From c2c31d1d70e28a7db65bd3a6206fcc1fada274c3 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sat, 25 Apr 2020 08:32:34 +0200 Subject: [PATCH] ffmpeg-encoder/nvenc: Invert "no-scenecut" option for "Adaptive I-Frames" Our "Adaptive I-Frames" is the inverse of the expected parameter to "no-scenecut" in FFmpegs NVENC. Related #191 --- source/encoders/handlers/nvenc_shared.cpp | 5 +++-- source/ffmpeg/tools.cpp | 9 +++++---- source/ffmpeg/tools.hpp | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/source/encoders/handlers/nvenc_shared.cpp b/source/encoders/handlers/nvenc_shared.cpp index 7e735914..66dce2d6 100644 --- a/source/encoders/handlers/nvenc_shared.cpp +++ b/source/encoders/handlers/nvenc_shared.cpp @@ -587,7 +587,8 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c // 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); + // no-scenecut is inverted compared to our UI. + av_opt_set_int(context->priv_data, "no-scenecut", 1 - adapt_i, AV_OPT_SEARCH_CHILDREN); } // Adaptive B-Frames @@ -726,7 +727,7 @@ void nvenc::log_options(obs_data_t*, const AVCodec* codec, AVCodecContext* conte }); tools::print_av_option_bool(context, "2pass", " Two Pass"); tools::print_av_option_int(context, "rc-lookahead", " Look-Ahead", "Frames"); - tools::print_av_option_bool(context, "no-scenecut", " Adaptive I-Frames"); + tools::print_av_option_bool(context, "no-scenecut", " Adaptive I-Frames", true); if (strcmp(codec->name, "h264_nvenc") == 0) tools::print_av_option_bool(context, "b_adapt", " Adaptive B-Frames"); diff --git a/source/ffmpeg/tools.cpp b/source/ffmpeg/tools.cpp index 588eede3..5a9007cf 100644 --- a/source/ffmpeg/tools.cpp +++ b/source/ffmpeg/tools.cpp @@ -311,20 +311,21 @@ const char* tools::get_thread_type_name(int thread_type) } } -void tools::print_av_option_bool(AVCodecContext* ctx_codec, const char* option, std::string text) +void tools::print_av_option_bool(AVCodecContext* ctx_codec, const char* option, std::string text, bool inverse) { - print_av_option_bool(ctx_codec, ctx_codec, option, text); + print_av_option_bool(ctx_codec, ctx_codec, option, text, inverse); } void ffmpeg::tools::print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, const char* option, - std::string text) + std::string text, bool inverse) { int64_t v = 0; if (int err = av_opt_get_int(ctx_option, option, AV_OPT_SEARCH_CHILDREN, &v); err != 0) { LOG_INFO("[%s] %s: ", ctx_codec->codec->name, text.c_str(), ffmpeg::tools::get_error_description(err)); } else { - LOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text.c_str(), v == 0 ? "Disabled" : "Enabled", + LOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text.c_str(), + (inverse ? v != 0 : v == 0) ? "Disabled" : "Enabled", av_opt_is_set_to_default_by_name(ctx_option, option, AV_OPT_SEARCH_CHILDREN) > 0 ? " " : ""); } } diff --git a/source/ffmpeg/tools.hpp b/source/ffmpeg/tools.hpp index b9567ab1..ee4d9110 100644 --- a/source/ffmpeg/tools.hpp +++ b/source/ffmpeg/tools.hpp @@ -66,8 +66,9 @@ namespace ffmpeg::tools { const char* get_thread_type_name(int thread_type); - void print_av_option_bool(AVCodecContext* context, const char* option, std::string text); - void print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text); + void print_av_option_bool(AVCodecContext* context, const char* option, std::string text, bool inverse = false); + void print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text, + bool inverse = false); void print_av_option_int(AVCodecContext* context, const char* option, std::string text, std::string suffix); void print_av_option_int(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text,