From 8f74c3b48230055b64561c3e2ccdaca461ba822d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 14 Apr 2023 18:08:53 -0500 Subject: [PATCH] Leave reference frames unspecified if REF_FRAMES_RESTRICT is not supported FFmpeg codecs specify their own defaults that we shouldn't override. --- src/video.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index 86de57de..776dd50c 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -1106,12 +1106,14 @@ namespace video { ctx->keyint_min = std::numeric_limits::max(); - if (config.numRefFrames == 0) { - ctx->refs = video_format[encoder_t::REF_FRAMES_AUTOSELECT] ? 0 : 16; - } - else { - // Some client decoders have limits on the number of reference frames - ctx->refs = video_format[encoder_t::REF_FRAMES_RESTRICT] ? config.numRefFrames : 0; + // Some client decoders have limits on the number of reference frames + if (config.numRefFrames) { + if (video_format[encoder_t::REF_FRAMES_RESTRICT]) { + ctx->refs = config.numRefFrames; + } + else { + BOOST_LOG(warning) << "Client requested reference frame limit, but encoder doesn't support it!"sv; + } } ctx->flags |= (AV_CODEC_FLAG_CLOSED_GOP | AV_CODEC_FLAG_LOW_DELAY);