From eff661c5b25bc80f6ad16590dc2129e9ebf77e86 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Wed, 29 Jul 2020 01:00:45 +0200 Subject: [PATCH] encoders/handlers/nvenc: Fix incorrect values being logged Fixes the issue where "high444p" shows as "high", and "high" shows as "main", caused by the internal option mapping never being correct across version changes. Instead of keeping our own copy of things that has to be adjusted for each FFmpeg version, it's easier to just use the FFmpeg values and names. --- .../encoders/handlers/nvenc_h264_handler.cpp | 18 +++-------- .../encoders/handlers/nvenc_hevc_handler.cpp | 27 ++++------------- source/encoders/handlers/nvenc_shared.cpp | 30 ++++--------------- 3 files changed, 16 insertions(+), 59 deletions(-) diff --git a/source/encoders/handlers/nvenc_h264_handler.cpp b/source/encoders/handlers/nvenc_h264_handler.cpp index f662d74a..6876fdea 100644 --- a/source/encoders/handlers/nvenc_h264_handler.cpp +++ b/source/encoders/handlers/nvenc_h264_handler.cpp @@ -133,20 +133,10 @@ void nvenc_h264_handler::log_options(obs_data_t* settings, const AVCodec* codec, nvenc::log_options(settings, codec, context); DLOG_INFO("[%s] H.264/AVC:", codec->name); - ::ffmpeg::tools::print_av_option_string(context, "profile", " Profile", [](int64_t v) { - profile val = static_cast(v); - auto index = profiles.find(val); - if (index != profiles.end()) - return index->second; - return std::string(""); - }); - ::ffmpeg::tools::print_av_option_string(context, "level", " Level", [](int64_t v) { - level val = static_cast(v); - auto index = levels.find(val); - if (index != levels.end()) - return index->second; - return std::string(""); - }); + ::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "profile", " Profile", + [](int64_t v, std::string_view o) { return std::string(o); }); + ::ffmpeg::tools::print_av_option_string2(context, context->priv_data, "level", " Level", + [](int64_t v, std::string_view o) { return std::string(o); }); } void nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec) diff --git a/source/encoders/handlers/nvenc_hevc_handler.cpp b/source/encoders/handlers/nvenc_hevc_handler.cpp index d5ca06d1..ea6c7b56 100644 --- a/source/encoders/handlers/nvenc_hevc_handler.cpp +++ b/source/encoders/handlers/nvenc_hevc_handler.cpp @@ -139,27 +139,12 @@ void nvenc_hevc_handler::log_options(obs_data_t* settings, const AVCodec* codec, nvenc::log_options(settings, codec, context); DLOG_INFO("[%s] H.265/HEVC:", codec->name); - ::ffmpeg::tools::print_av_option_string(context, "profile", " Profile", [](int64_t v) { - profile val = static_cast(v); - auto index = profiles.find(val); - if (index != profiles.end()) - return index->second; - return std::string(""); - }); - ::ffmpeg::tools::print_av_option_string(context, "level", " Level", [](int64_t v) { - level val = static_cast(v); - auto index = levels.find(val); - if (index != levels.end()) - return index->second; - return std::string(""); - }); - ::ffmpeg::tools::print_av_option_string(context, "tier", " Tier", [](int64_t v) { - tier val = static_cast(v); - auto index = tiers.find(val); - if (index != tiers.end()) - return index->second; - return std::string(""); - }); + ::ffmpeg::tools::print_av_option_string2(context, "profile", " Profile", + [](int64_t v, std::string_view o) { return std::string(o); }); + ::ffmpeg::tools::print_av_option_string2(context, "level", " Level", + [](int64_t v, std::string_view o) { return std::string(o); }); + ::ffmpeg::tools::print_av_option_string2(context, "tier", " Tier", + [](int64_t v, std::string_view o) { return std::string(o); }); } void nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec) diff --git a/source/encoders/handlers/nvenc_shared.cpp b/source/encoders/handlers/nvenc_shared.cpp index ce68350b..6fa8a69d 100644 --- a/source/encoders/handlers/nvenc_shared.cpp +++ b/source/encoders/handlers/nvenc_shared.cpp @@ -701,22 +701,10 @@ void nvenc::log_options(obs_data_t*, const AVCodec* codec, AVCodecContext* conte using namespace ::ffmpeg; DLOG_INFO("[%s] Nvidia NVENC:", codec->name); - tools::print_av_option_string(context, "preset", " Preset", [](int64_t v) { - preset val = static_cast(v); - std::string name = ""; - auto index = preset_to_opt.find(val); - if (index != preset_to_opt.end()) - name = index->second; - return name; - }); - tools::print_av_option_string(context, "rc", " Rate Control", [](int64_t v) { - ratecontrolmode val = static_cast(v); - std::string name = ""; - auto index = ratecontrolmode_to_opt.find(val); - if (index != ratecontrolmode_to_opt.end()) - name = index->second; - return name; - }); + tools::print_av_option_string2(context, "preset", " Preset", + [](int64_t v, std::string_view o) { return std::string(o); }); + tools::print_av_option_string2(context, "rc", " Rate Control", + [](int64_t v, std::string_view o) { return std::string(o); }); 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", true); @@ -738,14 +726,8 @@ void nvenc::log_options(obs_data_t*, const AVCodec* codec, AVCodecContext* conte tools::print_av_option_int(context, "init_qpB", " B-Frame", ""); tools::print_av_option_int(context, "bf", " B-Frames", "Frames"); - tools::print_av_option_string(context, "b_ref_mode", " Reference Mode", [](int64_t v) { - b_ref_mode val = static_cast(v); - std::string name = ""; - auto index = b_ref_mode_to_opt.find(val); - if (index != b_ref_mode_to_opt.end()) - name = index->second; - return name; - }); + tools::print_av_option_string2(context, "b_ref_mode", " Reference Mode", + [](int64_t v, std::string_view o) { return std::string(o); }); DLOG_INFO("[%s] Adaptive Quantization:", codec->name); if (strcmp(codec->name, "h264_nvenc") == 0) {