[FFmpeg-devel] [PATCH] Playout to DeckLink will wait for all buffered frames before stopping.
Marvin Scholz
epirat07 at gmail.com
Tue Jul 8 18:19:14 EEST 2025
On 8 Jul 2025, at 16:54, Devin Heitmueller wrote:
> Hi Matt,
>
> Thanks for your contribution. Comments inline.
>
> On Mon, Jul 7, 2025 at 9:40 PM Matt via ffmpeg-devel
> <ffmpeg-devel at ffmpeg.org> wrote:
>> diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp
>> index cb8f91730e..5751f27de8 100644
>> --- a/libavdevice/decklink_enc.cpp
>> +++ b/libavdevice/decklink_enc.cpp
>> @@ -20,6 +20,7 @@
>> */
>>
>> #include <atomic>
>> +#include <unistd.h>
>
> Not needed (see below)
>
>> using std::atomic;
>>
>> /* Include internal.h first to avoid conflict between winsock.h (used by
>> @@ -369,11 +370,26 @@ av_cold int ff_decklink_write_trailer(AVFormatContext *avctx)
>> {
>> struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
>> struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
>> + uint32_t buffered;
Can be moved inside the while block to narrow the scope.
>>
>> if (ctx->playback_started) {
>> BMDTimeValue actual;
>> ctx->dlo->StopScheduledPlayback(ctx->last_pts * ctx->bmd_tb_num,
>> &actual, ctx->bmd_tb_den);
>> + av_log(avctx, AV_LOG_DEBUG, "Stopped at %ld, requested %ld\n", actual, ctx->last_pts * ctx->bmd_tb_num);
>> + while (1){
>> + ctx->dlo->GetBufferedVideoFrameCount(&buffered);
>> + if (buffered <= 0){
>> + break;
>> + }
>> + av_log(avctx, AV_LOG_DEBUG, "Waiting for %d buffered frames to finish\n", buffered);
>> + if (buffered < 5) {
>> + usleep(1);
>> + } else {
>> + usleep(300);
>> + }
>
> The sleep calls should use av_usleep(), which is portable and you
> don't need unistd.h. Also, there should be some limit so that it
> doesn't block forever if video frames are scheduled very far in the
> future (e.g. after 1 second, give up and log a warning).
>
I think even if a frame is schedule "far" in the future, if I want them
all played out then it should probably still wait, no? As what is considered
"far" is a matter of interpretation…
Also there should likely be an option to opt in to this new behavior?
> Devin
>
> --
> Devin Heitmueller, Senior Software Engineer
> LTN Global Communications
> o: +1 (301) 363-1001
> w: https://ltnglobal.com e: devin.heitmueller at ltnglobal.com
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list