From: cgutman via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: cgutman <code@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH] avcodec/amfenc: avoid unnecessary output delay in low delay mode (PR #20473) Date: Tue, 09 Sep 2025 05:09:19 -0000 Message-ID: <175739456014.25.2012851308462728431@463a07221176> (raw) PR #20473 opened by cgutman URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20473 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20473.patch 88a8ba5c991a0ffd00c8ce34d127b1b201b1ee19 introduced an output latency regression making it impossible to acheive lower than 1 frame of latency from AMF. I assume the new behavior was intentional to improve throughput, so I only avoid it if the user explicitly asks for low delay. >From f3083931ad8b432ecd87dee4bef6895e9e20f9d9 Mon Sep 17 00:00:00 2001 From: Cameron Gutman <aicommander@gmail.com> Date: Mon, 8 Sep 2025 23:41:43 -0500 Subject: [PATCH] avcodec/amfenc: avoid unnecessary output delay in low delay mode The code optimizes throughput by letting the encoder work on frame N until frame N+1 is ready for submission, but this hurts low-delay uses by delaying output by one frame. Don't delay output beyond what is necessary when AV_CODEC_FLAG_LOW_DELAY is used. Signed-off-by: Cameron Gutman <aicommander@gmail.com> --- libavcodec/amfenc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index b16b642e4c..f363192000 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -497,7 +497,7 @@ static int amf_submit_frame(AVCodecContext *avctx, AVFrame *frame, AMFSurface AMF_RESULT res; int ret; int hw_surface = 0; - int max_b_frames = ctx->max_b_frames < 0 ? 0 : ctx->max_b_frames; + int output_delay = FFMAX(ctx->max_b_frames, 0) + ((avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : 1); // prepare surface from frame switch (frame->format) { @@ -634,8 +634,8 @@ static int amf_submit_frame(AVCodecContext *avctx, AVFrame *frame, AMFSurface ret = av_fifo_write(ctx->timestamp_list, &frame->pts, 1); if (ret < 0) return ret; - if(ctx->submitted_frame <= ctx->encoded_frame + max_b_frames + 1) - return AVERROR(EAGAIN); // if frame just submiited - don't poll or wait + if(ctx->submitted_frame <= ctx->encoded_frame + output_delay) + return AVERROR(EAGAIN); // too soon to poll or wait } return 0; } @@ -681,7 +681,7 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) AVFrame *frame = av_frame_alloc(); int block_and_wait; int64_t pts = 0; - int max_b_frames = ctx->max_b_frames < 0 ? 0 : ctx->max_b_frames; + int output_delay = FFMAX(ctx->max_b_frames, 0) + ((avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : 1); if (!ctx->encoder){ av_frame_free(&frame); @@ -700,7 +700,7 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) if(ret != AVERROR_EOF){ av_frame_free(&frame); if(ret == AVERROR(EAGAIN)){ - if(ctx->submitted_frame <= ctx->encoded_frame + max_b_frames + 1) // too soon to poll + if(ctx->submitted_frame <= ctx->encoded_frame + output_delay) // too soon to poll return ret; } } -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-09-09 5:09 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=175739456014.25.2012851308462728431@463a07221176 \ --to=ffmpeg-devel@ffmpeg.org \ --cc=code@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git