[FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: Respect the -refs option

Cameron Gutman aicommander at gmail.com
Thu Oct 10 03:54:24 EEST 2024


VideoToolbox doesn't allow us to specify an exact number of ref frames,
but it does allow an upper limit to be specified which is better than
nothing.

Signed-off-by: Cameron Gutman <aicommander at gmail.com>
---
 libavcodec/videotoolboxenc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index da7b291b03..9605657712 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1588,11 +1588,12 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
                                     vtctx->power_efficient ? kCFBooleanTrue : kCFBooleanFalse);
     }
 
-    if (vtctx->max_ref_frames > 0) {
+    if (vtctx->max_ref_frames > 0 || avctx->refs > 0) {
+        int max_ref_frames = avctx->refs > 0 ? avctx->refs : vtctx->max_ref_frames;
         status = set_encoder_int_property_or_log(avctx,
                                                  compat_keys.kVTCompressionPropertyKey_ReferenceBufferCount,
                                                  "max_ref_frames",
-                                                 vtctx->max_ref_frames);
+                                                 max_ref_frames);
 
         if (status != 0) {
             return status;
@@ -2940,6 +2941,7 @@ static const FFCodecDefault vt_defaults[] = {
         {"b",    "0"},
         {"qmin", "-1"},
         {"qmax", "-1"},
+        {"refs", "0"},
         {NULL},
 };
 
-- 
2.43.0.windows.1



More information about the ffmpeg-devel mailing list