Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg_patches: add amfenc delay/buffering fix #18

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-ffmpeg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ jobs:
run: |
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/01-idr-on-amf.patch
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/02-amf-color-fixes.patch
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/03-amfenc-disable-buffering.patch

- name: Setup cross compilation
id: cross
Expand Down
43 changes: 43 additions & 0 deletions ffmpeg_patches/ffmpeg/03-amfenc-disable-buffering.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 8b0966a3723a05d29810b116454a1eb94e15a0b1 Mon Sep 17 00:00:00 2001
From: Conn O'Griofa <[email protected]>
Date: Thu, 24 Nov 2022 06:34:48 +0000
Subject: [PATCH] amfenc: disable buffering & blocking delay in IPP mode

When realtime encoding is required, the HW queue and arbitrary
1ms sleep during blocking introduces unnecessary latency, especially
in low FPS situations such as streaming desktop content at a variable
framerate.

Resolve by disabling buffering and blocking delay if no B-frames are
requested, as is typical for zero latency streaming use cases.
---
libavcodec/amfenc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index fb23ed738c..c452a0fd5b 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -219,7 +219,7 @@ static int amf_init_context(AVCodecContext *avctx)
av_unused int ret;

ctx->hwsurfaces_in_queue = 0;
- ctx->hwsurfaces_in_queue_max = 16;
+ ctx->hwsurfaces_in_queue_max = avctx->max_b_frames > 0 ? 16 : 0; // avoid buffering frames if no B frames are in use

// configure AMF logger
// the return of these functions indicates old state and do not affect behaviour
@@ -769,7 +769,9 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
}
} else if (ctx->delayed_surface != NULL || ctx->delayed_drain || (ctx->eof && res_query != AMF_EOF) || (ctx->hwsurfaces_in_queue >= ctx->hwsurfaces_in_queue_max)) {
block_and_wait = 1;
- av_usleep(1000); // wait and poll again
+ if (avctx->max_b_frames > 0) {
+ av_usleep(1000); // wait and poll again
+ }
}
} while (block_and_wait);

--
2.37.2