From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0BFA4459B7 for ; Tue, 28 Feb 2023 20:46:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 70E3268A861; Tue, 28 Feb 2023 22:46:05 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 07E54680D1D for ; Tue, 28 Feb 2023 22:45:59 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id DEBF8E7FA8 for ; Tue, 28 Feb 2023 21:45:58 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KM1OE9rRrCq7 for ; Tue, 28 Feb 2023 21:45:57 +0100 (CET) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 214BFE7F95 for ; Tue, 28 Feb 2023 21:45:57 +0100 (CET) Date: Tue, 28 Feb 2023 21:45:57 +0100 (CET) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20230223222513.3759-2-dheitmueller@ltnglobal.com> Message-ID: <106ca8ce-ea36-75f3-d6ce-fbaf65fa1bfe@passwd.hu> References: <20230223222513.3759-1-dheitmueller@ltnglobal.com> <20230223222513.3759-2-dheitmueller@ltnglobal.com> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 1/3] decklink: Don't take for granted that first frame to decklink output will be PTS 0 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Thu, 23 Feb 2023, Devin Heitmueller wrote: > The existing code assumed that the first frame received by the decklink > output would always be PTS zero. However if running in other timing > modes than the default of CBR, items such as frame dropping at the > beginning may result in starting at a non-zero PTS. > > For example, in our setup because we discard probing data and run > with "-vsync 2" the first video frame scheduled to the decklink > output will have a PTS around 170. Scheduling frames too far into > the future will either fail or cause a backlog of frames scheduled > far enough into the future that the entire pipeline will stall. > > Issue can be reproduced with the following command-line: > > ./ffmpeg -copyts -i foo.ts -f decklink -vcodec v210 -ac 2 'DeckLink Duo (4)' > > Keep track of the PTS of the first frame received, so that when > we enable start playback we can provide that value to the decklink > driver. > > Signed-off-by: Devin Heitmueller > --- > libavdevice/decklink_common.h | 1 + > libavdevice/decklink_enc.cpp | 7 +++++-- > 2 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h > index 79d6ac5b38..088e165ee7 100644 > --- a/libavdevice/decklink_common.h > +++ b/libavdevice/decklink_common.h > @@ -118,6 +118,7 @@ struct decklink_ctx { > > /* Status */ > int playback_started; > + int64_t first_pts; > int64_t last_pts; > unsigned long frameCount; > unsigned int dropped; > diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp > index fb686b9032..c3dc2c0cac 100644 > --- a/libavdevice/decklink_enc.cpp > +++ b/libavdevice/decklink_enc.cpp > @@ -486,6 +486,9 @@ static int decklink_write_video_packet(AVFormatContext *avctx, AVPacket *pkt) > ctx->frames_buffer_available_spots--; > pthread_mutex_unlock(&ctx->mutex); > > + if (ctx->first_pts == 0) > + ctx->first_pts = pkt->pts; And what if first packet pts is 0? Then the second packet pts will be assigned to first pts? Maybe you should use AV_NOPTS_VALUE for the default first_pts value and check for that instead. Regards, Marton > + > /* Schedule frame for playback. */ > hr = ctx->dlo->ScheduleVideoFrame((class IDeckLinkVideoFrame *) frame, > pkt->pts * ctx->bmd_tb_num, > @@ -505,14 +508,14 @@ static int decklink_write_video_packet(AVFormatContext *avctx, AVPacket *pkt) > " Video may misbehave!\n"); > > /* Preroll video frames. */ > - if (!ctx->playback_started && pkt->pts > ctx->frames_preroll) { > + if (!ctx->playback_started && pkt->pts > (ctx->first_pts + ctx->frames_preroll)) { > av_log(avctx, AV_LOG_DEBUG, "Ending audio preroll.\n"); > if (ctx->audio && ctx->dlo->EndAudioPreroll() != S_OK) { > av_log(avctx, AV_LOG_ERROR, "Could not end audio preroll!\n"); > return AVERROR(EIO); > } > av_log(avctx, AV_LOG_DEBUG, "Starting scheduled playback.\n"); > - if (ctx->dlo->StartScheduledPlayback(0, ctx->bmd_tb_den, 1.0) != S_OK) { > + if (ctx->dlo->StartScheduledPlayback(ctx->first_pts * ctx->bmd_tb_num, ctx->bmd_tb_den, 1.0) != S_OK) { > av_log(avctx, AV_LOG_ERROR, "Could not start scheduled playback!\n"); > return AVERROR(EIO); > } > -- > 2.35.1.655.ga68dfadae5 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".