From 0966b61f7649f836fabe3ab8006cae1e05dc280d Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sat, 25 Apr 2020 00:59:27 +0200 Subject: [PATCH] ffmpeg-encoder/nvenc: Test for "h264_nvenc" in for "Adaptive B-Frames" Fixes the bug where "Adaptive B-Frames" would not be applied in the way it was expected to be applied. Related: #191 --- source/encoders/handlers/nvenc_shared.cpp | 29 +++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/source/encoders/handlers/nvenc_shared.cpp b/source/encoders/handlers/nvenc_shared.cpp index 0fdce965..7e735914 100644 --- a/source/encoders/handlers/nvenc_shared.cpp +++ b/source/encoders/handlers/nvenc_shared.cpp @@ -584,25 +584,18 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c av_opt_set_int(context->priv_data, "rc-lookahead", la, AV_OPT_SEARCH_CHILDREN); } - if (la > 0) { - // Adaptive I-Frames - if (int64_t adapt_i = obs_data_get_int(settings, KEY_RATECONTROL_ADAPTIVEI); - !util::is_tristate_default(adapt_i)) { - av_opt_set_int(context->priv_data, "no-scenecut", adapt_i, AV_OPT_SEARCH_CHILDREN); - } + // Adaptive I-Frames + if (int64_t adapt_i = obs_data_get_int(settings, KEY_RATECONTROL_ADAPTIVEI); + !util::is_tristate_default(adapt_i) && (la != 0)) { + av_opt_set_int(context->priv_data, "no-scenecut", adapt_i, AV_OPT_SEARCH_CHILDREN); + } - // Adaptive B-Frames - if (strcmp(codec->name, "h264_nvenc")) { - if (int64_t adapt_b = obs_data_get_int(settings, KEY_RATECONTROL_ADAPTIVEB); - !util::is_tristate_default(adapt_b)) { - av_opt_set_int(context->priv_data, "b_adapt", adapt_b, AV_OPT_SEARCH_CHILDREN); - } - } - } else { - // These two do not work if lookahead is set to 0 frames (disabled). - av_opt_set_int(context->priv_data, "no-scenecut", 0, AV_OPT_SEARCH_CHILDREN); - if (strcmp(codec->name, "h264_nvenc")) { - av_opt_set_int(context->priv_data, "b_adapt", 0, AV_OPT_SEARCH_CHILDREN); + // Adaptive B-Frames + constexpr std::string_view h264_encoder_name = "h264_nvenc"; + if (h264_encoder_name == codec->name) { + if (int64_t adapt_b = obs_data_get_int(settings, KEY_RATECONTROL_ADAPTIVEB); + !util::is_tristate_default(adapt_b) && (la != 0)) { + av_opt_set_int(context->priv_data, "b_adapt", adapt_b, AV_OPT_SEARCH_CHILDREN); } }