2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// Copyright (C) 2022 lainon <GermanAizek@yandex.ru>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2020-01-13 00:52:30 +00:00
|
|
|
|
|
|
|
#include "nvenc_shared.hpp"
|
2020-08-09 23:18:36 +00:00
|
|
|
#include "encoders/encoder-ffmpeg.hpp"
|
2020-01-13 00:52:30 +00:00
|
|
|
#include "ffmpeg/tools.hpp"
|
|
|
|
|
|
|
|
extern "C" {
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
2020-01-13 00:52:30 +00:00
|
|
|
#include <libavutil/opt.h>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-enable.hpp"
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_PRESET "Encoder.FFmpeg.NVENC.Preset"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_PRESET_(x) ST_I18N_PRESET "." D_VSTR(x)
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_PRESET "Preset"
|
2022-02-17 03:30:17 +00:00
|
|
|
#define ST_I18N_TUNE "Encoder.FFmpeg.NVENC.Tune"
|
|
|
|
#define ST_I18N_TUNE_(x) ST_I18N_TUNE "." D_VSTR(x)
|
|
|
|
#define ST_KEY_TUNE "Tune"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_RATECONTROL "Encoder.FFmpeg.NVENC.RateControl"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_MODE ST_I18N_RATECONTROL ".Mode"
|
|
|
|
#define ST_I18N_RATECONTROL_MODE_(x) ST_I18N_RATECONTROL_MODE "." D_VSTR(x)
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_MODE "RateControl.Mode"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_TWOPASS ST_I18N_RATECONTROL ".TwoPass"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_TWOPASS "RateControl.TwoPass"
|
2022-02-17 03:30:17 +00:00
|
|
|
#define ST_I18N_RATECONTROL_MULTIPASS ST_I18N_RATECONTROL ".MultiPass"
|
|
|
|
#define ST_KEY_RATECONTROL_MULTIPASS "RateControl.MultiPass"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_LOOKAHEAD ST_I18N_RATECONTROL ".LookAhead"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_LOOKAHEAD "RateControl.LookAhead"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_ADAPTIVEI ST_I18N_RATECONTROL ".AdaptiveI"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_ADAPTIVEI "RateControl.AdaptiveI"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_ADAPTIVEB ST_I18N_RATECONTROL ".AdaptiveB"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_ADAPTIVEB "RateControl.AdaptiveB"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_LIMITS ST_I18N_RATECONTROL ".Limits"
|
|
|
|
#define ST_I18N_RATECONTROL_LIMITS_BUFFERSIZE ST_I18N_RATECONTROL_LIMITS ".BufferSize"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_LIMITS_BUFFERSIZE "RateControl.Limits.BufferSize"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_LIMITS_QUALITY ST_I18N_RATECONTROL_LIMITS ".Quality"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_LIMITS_QUALITY "RateControl.Limits.Quality"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_LIMITS_BITRATE ST_I18N_RATECONTROL_LIMITS ".Bitrate"
|
|
|
|
#define ST_I18N_RATECONTROL_LIMITS_BITRATE_TARGET ST_I18N_RATECONTROL_LIMITS_BITRATE ".Target"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_LIMITS_BITRATE_TARGET "RateControl.Limits.Bitrate.Target"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_LIMITS_BITRATE_MAXIMUM ST_I18N_RATECONTROL_LIMITS_BITRATE ".Maximum"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_KEY_RATECONTROL_LIMITS_BITRATE_MAXIMUM "RateControl.Limits.Bitrate.Maximum"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_I18N_RATECONTROL_QP ST_I18N_RATECONTROL ".QP"
|
|
|
|
#define ST_I18N_RATECONTROL_QP_MINIMUM ST_I18N_RATECONTROL_QP ".Minimum"
|
|
|
|
#define ST_KEY_RATECONTROL_QP_MINIMUM "RateControl.Quality.Minimum"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_RATECONTROL_QP_MAXIMUM ST_I18N_RATECONTROL_QP ".Maximum"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_RATECONTROL_QP_MAXIMUM "RateControl.Quality.Maximum"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_RATECONTROL_QP_I ST_I18N_RATECONTROL_QP ".I"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_RATECONTROL_QP_I "RateControl.QP.I"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_RATECONTROL_QP_P ST_I18N_RATECONTROL_QP ".P"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_RATECONTROL_QP_P "RateControl.QP.P"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_RATECONTROL_QP_B ST_I18N_RATECONTROL_QP ".B"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_RATECONTROL_QP_B "RateControl.QP.B"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_AQ "Encoder.FFmpeg.NVENC.AQ"
|
|
|
|
#define ST_I18N_AQ_SPATIAL ST_I18N_AQ ".Spatial"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_AQ_SPATIAL "AQ.Spatial"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_AQ_TEMPORAL ST_I18N_AQ ".Temporal"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_AQ_TEMPORAL "AQ.Temporal"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_AQ_STRENGTH ST_I18N_AQ ".Strength"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_AQ_STRENGTH "AQ.Strength"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_OTHER "Encoder.FFmpeg.NVENC.Other"
|
|
|
|
#define ST_I18N_OTHER_BFRAMES ST_I18N_OTHER ".BFrames"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_OTHER_BFRAMES "Other.BFrames"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_OTHER_BFRAMEREFERENCEMODE ST_I18N_OTHER ".BFrameReferenceMode"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_OTHER_BFRAMEREFERENCEMODE "Other.BFrameReferenceMode"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_OTHER_ZEROLATENCY ST_I18N_OTHER ".ZeroLatency"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_OTHER_ZEROLATENCY "Other.ZeroLatency"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_OTHER_WEIGHTEDPREDICTION ST_I18N_OTHER ".WeightedPrediction"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_OTHER_WEIGHTEDPREDICTION "Other.WeightedPrediction"
|
2021-10-17 08:09:47 +00:00
|
|
|
#define ST_I18N_OTHER_NONREFERENCEPFRAMES ST_I18N_OTHER ".NonReferencePFrames"
|
2021-06-08 02:02:32 +00:00
|
|
|
#define ST_KEY_OTHER_NONREFERENCEPFRAMES "Other.NonReferencePFrames"
|
2021-10-17 08:16:04 +00:00
|
|
|
#define ST_I18N_OTHER_REFERENCEFRAMES ST_I18N_OTHER ".ReferenceFrames"
|
|
|
|
#define ST_KEY_OTHER_REFERENCEFRAMES "Other.ReferenceFrames"
|
2022-02-17 03:30:17 +00:00
|
|
|
#define ST_I18N_OTHER_LOWDELAYKEYFRAMESCALE ST_I18N_OTHER ".LowDelayKeyFrameScale"
|
|
|
|
#define ST_KEY_OTHER_LOWDELAYKEYFRAMESCALE "Other.LowDelayKeyFrameScale"
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
using namespace streamfx::encoder::ffmpeg::handler;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
inline bool is_cqp(std::string_view rc)
|
|
|
|
{
|
|
|
|
return std::string_view("constqp") == rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool is_cbr(std::string_view rc)
|
|
|
|
{
|
|
|
|
return std::string_view("cbr") == rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool is_vbr(std::string_view rc)
|
|
|
|
{
|
|
|
|
return std::string_view("vbr") == rc;
|
|
|
|
}
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2020-08-09 23:18:36 +00:00
|
|
|
bool streamfx::encoder::ffmpeg::handler::nvenc::is_available()
|
|
|
|
{
|
|
|
|
#if defined(D_PLATFORM_WINDOWS)
|
|
|
|
#if defined(D_PLATFORM_64BIT)
|
|
|
|
std::filesystem::path lib_name = "nvEncodeAPI64.dll";
|
|
|
|
#else
|
|
|
|
std::filesystem::path lib_name = "nvEncodeAPI.dll";
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
std::filesystem::path lib_name = "libnvidia-encode.so.1";
|
|
|
|
#endif
|
|
|
|
try {
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::library::load(lib_name);
|
2020-08-09 23:18:36 +00:00
|
|
|
return true;
|
|
|
|
} catch (...) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
void nvenc::override_update(ffmpeg_instance* instance, obs_data_t*)
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
|
|
|
AVCodecContext* context = const_cast<AVCodecContext*>(instance->get_avcodeccontext());
|
|
|
|
|
|
|
|
int64_t rclookahead = 0;
|
|
|
|
int64_t surfaces = 0;
|
|
|
|
int64_t async_depth = 0;
|
|
|
|
|
|
|
|
av_opt_get_int(context, "rc-lookahead", AV_OPT_SEARCH_CHILDREN, &rclookahead);
|
|
|
|
av_opt_get_int(context, "surfaces", AV_OPT_SEARCH_CHILDREN, &surfaces);
|
|
|
|
av_opt_get_int(context, "async_depth", AV_OPT_SEARCH_CHILDREN, &async_depth);
|
|
|
|
|
|
|
|
// Calculate and set the number of surfaces to allocate (if not user overridden).
|
|
|
|
if (surfaces == 0) {
|
2020-08-10 14:44:00 +00:00
|
|
|
surfaces = std::max<int64_t>(4ll, (context->max_b_frames + 1ll) * 4ll);
|
2020-01-13 00:52:30 +00:00
|
|
|
if (rclookahead > 0) {
|
2020-08-10 14:44:00 +00:00
|
|
|
surfaces = std::max<int64_t>(1ll, std::max<int64_t>(surfaces, rclookahead + (context->max_b_frames + 5ll)));
|
2020-01-13 00:52:30 +00:00
|
|
|
} else if (context->max_b_frames > 0) {
|
2020-08-10 14:44:00 +00:00
|
|
|
surfaces = std::max<int64_t>(4ll, (context->max_b_frames + 1ll) * 4ll);
|
2020-01-13 00:52:30 +00:00
|
|
|
} else {
|
|
|
|
surfaces = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_opt_set_int(context, "surfaces", surfaces, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set delay
|
2021-09-07 03:11:04 +00:00
|
|
|
context->delay = std::min<int>(std::max<int>(static_cast<int>(async_depth), 3), static_cast<int>(surfaces - 1));
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
void nvenc::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*)
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_data_set_default_string(settings, ST_KEY_PRESET, "default");
|
|
|
|
obs_data_set_default_string(settings, ST_I18N_TUNE, "hq");
|
2021-06-08 02:02:32 +00:00
|
|
|
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_data_set_default_string(settings, ST_KEY_RATECONTROL_MODE, "cbr");
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_TWOPASS, -1);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_MULTIPASS, -1);
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_LOOKAHEAD, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_ADAPTIVEI, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_ADAPTIVEB, -1);
|
|
|
|
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_LIMITS_BITRATE_TARGET, 6000);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_LIMITS_BITRATE_MAXIMUM, 0);
|
2021-10-17 08:16:04 +00:00
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_LIMITS_BUFFERSIZE, 0);
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_data_set_default_double(settings, ST_KEY_RATECONTROL_LIMITS_QUALITY, 0);
|
|
|
|
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_QP_MINIMUM, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_QP_MAXIMUM, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_QP_I, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_QP_P, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_RATECONTROL_QP_B, -1);
|
|
|
|
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_AQ_SPATIAL, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_AQ_STRENGTH, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_AQ_TEMPORAL, -1);
|
|
|
|
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_OTHER_BFRAMES, -1);
|
2022-02-17 03:30:17 +00:00
|
|
|
obs_data_set_default_int(settings, ST_KEY_OTHER_BFRAMEREFERENCEMODE, -1);
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_data_set_default_int(settings, ST_KEY_OTHER_ZEROLATENCY, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_OTHER_WEIGHTEDPREDICTION, -1);
|
|
|
|
obs_data_set_default_int(settings, ST_KEY_OTHER_NONREFERENCEPFRAMES, -1);
|
2021-10-17 08:16:04 +00:00
|
|
|
obs_data_set_default_int(settings, ST_KEY_OTHER_REFERENCEFRAMES, -1);
|
2022-02-17 03:30:17 +00:00
|
|
|
obs_data_set_default_int(settings, ST_KEY_OTHER_LOWDELAYKEYFRAMESCALE, -1);
|
2020-01-13 00:52:30 +00:00
|
|
|
|
|
|
|
// Replay Buffer
|
|
|
|
obs_data_set_default_int(settings, "bitrate", 0);
|
|
|
|
}
|
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
static bool modified_ratecontrol(obs_properties_t* props, obs_property_t*, obs_data_t* settings) noexcept
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2022-02-17 03:30:17 +00:00
|
|
|
// Decode the name into useful flags.
|
2022-07-21 11:09:10 +00:00
|
|
|
const char* value = obs_data_get_string(settings, ST_KEY_RATECONTROL_MODE);
|
|
|
|
bool have_bitrate = false;
|
|
|
|
bool have_bitrate_range = false;
|
|
|
|
bool have_quality = false;
|
|
|
|
bool have_qp_limits = false;
|
|
|
|
bool have_qp = false;
|
2022-02-20 18:45:41 +00:00
|
|
|
if (value == std::string_view("cbr")) {
|
2022-02-17 03:30:17 +00:00
|
|
|
have_bitrate = true;
|
2022-02-20 18:45:41 +00:00
|
|
|
} else if (value == std::string_view("vbr")) {
|
2022-02-17 03:30:17 +00:00
|
|
|
have_bitrate = true;
|
|
|
|
have_bitrate_range = true;
|
|
|
|
have_quality = true;
|
|
|
|
have_qp_limits = true;
|
|
|
|
have_qp = true;
|
2022-02-20 18:45:41 +00:00
|
|
|
} else if (value == std::string_view("constqp")) {
|
2020-01-13 00:52:30 +00:00
|
|
|
have_qp = true;
|
2022-02-17 03:30:17 +00:00
|
|
|
} else {
|
2020-02-13 10:19:30 +00:00
|
|
|
have_bitrate = true;
|
|
|
|
have_bitrate_range = true;
|
|
|
|
have_quality = true;
|
2021-10-17 08:05:37 +00:00
|
|
|
have_qp_limits = true;
|
2020-02-13 10:19:30 +00:00
|
|
|
have_qp = true;
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_I18N_RATECONTROL_LIMITS), have_bitrate || have_quality);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_LIMITS_BUFFERSIZE), have_bitrate);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_LIMITS_QUALITY), have_quality);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_LIMITS_BITRATE_TARGET), have_bitrate);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_LIMITS_BITRATE_MAXIMUM), have_bitrate_range);
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2021-10-17 08:05:37 +00:00
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_I18N_RATECONTROL_QP), have_qp || have_qp_limits);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_QP_MINIMUM), have_qp_limits);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_QP_MAXIMUM), have_qp_limits);
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_QP_I), have_qp);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_QP_P), have_qp);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_RATECONTROL_QP_B), have_qp);
|
2020-01-13 00:52:30 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
static bool modified_aq(obs_properties_t* props, obs_property_t*, obs_data_t* settings) noexcept
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
bool spatial_aq = streamfx::util::is_tristate_enabled(obs_data_get_int(settings, ST_KEY_AQ_SPATIAL));
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_KEY_AQ_STRENGTH), spatial_aq);
|
2020-01-13 00:52:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
void nvenc::get_properties_pre(obs_properties_t* props, const AVCodec*, const AVCodecContext* context)
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2022-02-17 03:30:17 +00:00
|
|
|
{
|
|
|
|
auto p = obs_properties_add_list(props, ST_KEY_PRESET, D_TRANSLATE(ST_I18N_PRESET), OBS_COMBO_TYPE_LIST,
|
2022-02-20 18:45:41 +00:00
|
|
|
OBS_COMBO_FORMAT_STRING);
|
|
|
|
streamfx::ffmpeg::tools::avoption_list_add_entries(context->priv_data, "preset", [&p](const AVOption* opt) {
|
|
|
|
char buffer[1024];
|
2022-08-28 13:53:01 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s.%s", ST_I18N_PRESET, opt->name);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(buffer), opt->name);
|
|
|
|
});
|
2022-02-17 03:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (streamfx::ffmpeg::tools::avoption_exists(context->priv_data, "tune")) {
|
|
|
|
auto p = obs_properties_add_list(props, ST_KEY_TUNE, D_TRANSLATE(ST_I18N_TUNE), OBS_COMBO_TYPE_LIST,
|
2022-02-20 18:45:41 +00:00
|
|
|
OBS_COMBO_FORMAT_STRING);
|
|
|
|
streamfx::ffmpeg::tools::avoption_list_add_entries(context->priv_data, "tune", [&p](const AVOption* opt) {
|
|
|
|
char buffer[1024];
|
2022-08-28 13:53:01 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s.%s", ST_I18N_TUNE, opt->name);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(buffer), opt->name);
|
|
|
|
});
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec, const AVCodecContext* context)
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
|
|
|
{ // Rate Control
|
|
|
|
obs_properties_t* grp = props;
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::are_property_groups_broken()) {
|
2020-01-13 00:52:30 +00:00
|
|
|
grp = obs_properties_create();
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_properties_add_group(props, ST_I18N_RATECONTROL, D_TRANSLATE(ST_I18N_RATECONTROL), OBS_GROUP_NORMAL,
|
|
|
|
grp);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_list(grp, ST_KEY_RATECONTROL_MODE, D_TRANSLATE(ST_I18N_RATECONTROL_MODE),
|
2022-02-20 18:45:41 +00:00
|
|
|
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
|
2020-01-13 00:52:30 +00:00
|
|
|
obs_property_set_modified_callback(p, modified_ratecontrol);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_STATE_DEFAULT), "");
|
|
|
|
streamfx::ffmpeg::tools::avoption_list_add_entries(context->priv_data, "rc", [&p](const AVOption* opt) {
|
|
|
|
// Ignore options that are "deprecated" but not flagged as such.
|
2022-02-17 03:30:17 +00:00
|
|
|
if (opt->default_val.i64 & (1 << 23))
|
2022-02-20 18:45:41 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
char buffer[1024];
|
2022-08-28 13:53:01 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s.%s", ST_I18N_RATECONTROL_MODE, opt->name);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(buffer), opt->name);
|
|
|
|
});
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
if (streamfx::ffmpeg::tools::avoption_exists(context->priv_data, "multipass")) {
|
|
|
|
auto p =
|
|
|
|
obs_properties_add_list(grp, ST_KEY_RATECONTROL_MULTIPASS, D_TRANSLATE(ST_I18N_RATECONTROL_MULTIPASS),
|
2022-02-20 18:45:41 +00:00
|
|
|
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_STATE_DEFAULT), "");
|
|
|
|
streamfx::ffmpeg::tools::avoption_list_add_entries(
|
|
|
|
context->priv_data, "multipass", [&p](const AVOption* opt) {
|
|
|
|
char buffer[1024];
|
2022-08-28 13:53:01 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s.%s", ST_I18N_RATECONTROL_MULTIPASS, opt->name);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(buffer), opt->name);
|
|
|
|
});
|
2022-02-17 03:30:17 +00:00
|
|
|
} else {
|
2021-06-08 02:18:02 +00:00
|
|
|
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_TWOPASS,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_TWOPASS));
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int_slider(grp, ST_KEY_RATECONTROL_LOOKAHEAD,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_LOOKAHEAD), -1, 32, 1);
|
2020-01-13 00:52:30 +00:00
|
|
|
obs_property_int_set_suffix(p, " frames");
|
2020-02-13 10:19:30 +00:00
|
|
|
//obs_property_set_modified_callback(p, modified_lookahead);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
2020-01-15 04:50:31 +00:00
|
|
|
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEI,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEI));
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
2020-01-15 04:50:31 +00:00
|
|
|
|
2020-01-13 00:52:30 +00:00
|
|
|
if (strcmp(codec->name, "h264_nvenc") == 0) {
|
2021-06-08 02:18:02 +00:00
|
|
|
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEB,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEB));
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
obs_properties_t* grp = props;
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::are_property_groups_broken()) {
|
2020-01-13 00:52:30 +00:00
|
|
|
grp = obs_properties_create();
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_properties_add_group(props, ST_I18N_RATECONTROL_LIMITS, D_TRANSLATE(ST_I18N_RATECONTROL_LIMITS),
|
|
|
|
OBS_GROUP_NORMAL, grp);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_float_slider(grp, ST_KEY_RATECONTROL_LIMITS_QUALITY,
|
2022-02-17 03:30:17 +00:00
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_LIMITS_QUALITY), 0, 51, 0.01);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
2020-07-05 22:10:04 +00:00
|
|
|
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int(grp, ST_KEY_RATECONTROL_LIMITS_BITRATE_TARGET,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_LIMITS_BITRATE_TARGET), -1,
|
2020-08-10 01:29:05 +00:00
|
|
|
std::numeric_limits<int32_t>::max(), 1);
|
2020-01-15 04:50:31 +00:00
|
|
|
obs_property_int_set_suffix(p, " kbit/s");
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 04:50:31 +00:00
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int(grp, ST_KEY_RATECONTROL_LIMITS_BITRATE_MAXIMUM,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_LIMITS_BITRATE_MAXIMUM), -1,
|
2020-08-10 01:29:05 +00:00
|
|
|
std::numeric_limits<int32_t>::max(), 1);
|
2020-07-05 22:10:04 +00:00
|
|
|
obs_property_int_set_suffix(p, " kbit/s");
|
2020-01-15 04:50:31 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int(grp, ST_KEY_RATECONTROL_LIMITS_BUFFERSIZE,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_LIMITS_BUFFERSIZE), 0,
|
2020-08-10 01:29:05 +00:00
|
|
|
std::numeric_limits<int32_t>::max(), 1);
|
2020-07-05 22:10:04 +00:00
|
|
|
obs_property_int_set_suffix(p, " kbit");
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
obs_properties_t* grp = props;
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::are_property_groups_broken()) {
|
2020-03-27 19:06:27 +00:00
|
|
|
grp = obs_properties_create();
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_properties_add_group(props, ST_I18N_RATECONTROL_QP, D_TRANSLATE(ST_I18N_RATECONTROL_QP),
|
|
|
|
OBS_GROUP_NORMAL, grp);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 22:10:04 +00:00
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int_slider(grp, ST_KEY_RATECONTROL_QP_MINIMUM,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_QP_MINIMUM), -1, 51, 1);
|
2020-07-05 22:10:04 +00:00
|
|
|
}
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int_slider(grp, ST_KEY_RATECONTROL_QP_MAXIMUM,
|
|
|
|
D_TRANSLATE(ST_I18N_RATECONTROL_QP_MAXIMUM), -1, 51, 1);
|
2020-07-05 22:10:04 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int_slider(grp, ST_KEY_RATECONTROL_QP_I, D_TRANSLATE(ST_I18N_RATECONTROL_QP_I),
|
|
|
|
-1, 51, 1);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int_slider(grp, ST_KEY_RATECONTROL_QP_P, D_TRANSLATE(ST_I18N_RATECONTROL_QP_P),
|
|
|
|
-1, 51, 1);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_int_slider(grp, ST_KEY_RATECONTROL_QP_B, D_TRANSLATE(ST_I18N_RATECONTROL_QP_B),
|
|
|
|
-1, 51, 1);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
obs_properties_t* grp = props;
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::are_property_groups_broken()) {
|
2020-01-13 00:52:30 +00:00
|
|
|
grp = obs_properties_create();
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_properties_add_group(props, ST_I18N_AQ, D_TRANSLATE(ST_I18N_AQ), OBS_GROUP_NORMAL, grp);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
auto p =
|
|
|
|
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_AQ_SPATIAL, D_TRANSLATE(ST_I18N_AQ_SPATIAL));
|
2020-01-13 00:52:30 +00:00
|
|
|
obs_property_set_modified_callback(p, modified_aq);
|
|
|
|
}
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p =
|
|
|
|
obs_properties_add_int_slider(grp, ST_KEY_AQ_STRENGTH, D_TRANSLATE(ST_I18N_AQ_STRENGTH), -1, 15, 1);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
auto p =
|
|
|
|
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_AQ_TEMPORAL, D_TRANSLATE(ST_I18N_AQ_TEMPORAL));
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
obs_properties_t* grp = props;
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::are_property_groups_broken()) {
|
2020-01-13 00:52:30 +00:00
|
|
|
grp = obs_properties_create();
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_properties_add_group(props, ST_I18N_OTHER, D_TRANSLATE(ST_I18N_OTHER), OBS_GROUP_NORMAL, grp);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p =
|
|
|
|
obs_properties_add_int_slider(grp, ST_KEY_OTHER_BFRAMES, D_TRANSLATE(ST_I18N_OTHER_BFRAMES), -1, 4, 1);
|
2020-01-13 00:52:30 +00:00
|
|
|
obs_property_int_set_suffix(p, " frames");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
auto p = obs_properties_add_list(grp, ST_KEY_OTHER_BFRAMEREFERENCEMODE,
|
|
|
|
D_TRANSLATE(ST_I18N_OTHER_BFRAMEREFERENCEMODE), OBS_COMBO_TYPE_LIST,
|
2022-02-20 18:45:41 +00:00
|
|
|
OBS_COMBO_FORMAT_STRING);
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_STATE_DEFAULT), "");
|
|
|
|
streamfx::ffmpeg::tools::avoption_list_add_entries(
|
|
|
|
context->priv_data, "b_ref_mode", [&p](const AVOption* opt) {
|
|
|
|
char buffer[1024];
|
2022-08-28 13:53:01 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s.%s", ST_I18N_OTHER_BFRAMEREFERENCEMODE, opt->name);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(buffer), opt->name);
|
|
|
|
});
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ZEROLATENCY,
|
|
|
|
D_TRANSLATE(ST_I18N_OTHER_ZEROLATENCY));
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_WEIGHTEDPREDICTION,
|
|
|
|
D_TRANSLATE(ST_I18N_OTHER_WEIGHTEDPREDICTION));
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_NONREFERENCEPFRAMES,
|
|
|
|
D_TRANSLATE(ST_I18N_OTHER_NONREFERENCEPFRAMES));
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
2020-01-15 12:43:33 +00:00
|
|
|
|
|
|
|
{
|
2021-10-17 08:16:04 +00:00
|
|
|
auto p = obs_properties_add_int_slider(grp, ST_KEY_OTHER_REFERENCEFRAMES,
|
|
|
|
D_TRANSLATE(ST_I18N_OTHER_REFERENCEFRAMES), -1,
|
|
|
|
(strcmp(codec->name, "h264_nvenc") == 0) ? 16 : 4, 1);
|
2020-01-15 12:43:33 +00:00
|
|
|
obs_property_int_set_suffix(p, " frames");
|
|
|
|
}
|
2022-02-17 03:30:17 +00:00
|
|
|
|
|
|
|
if (streamfx::ffmpeg::tools::avoption_exists(context->priv_data, "ldkfs")) {
|
|
|
|
auto p = obs_properties_add_int_slider(grp, ST_KEY_OTHER_LOWDELAYKEYFRAMESCALE,
|
|
|
|
D_TRANSLATE(ST_I18N_OTHER_LOWDELAYKEYFRAMESCALE), -1, 255, 1);
|
|
|
|
}
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
void nvenc::get_runtime_properties(obs_properties_t* props, const AVCodec*, AVCodecContext*)
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_PRESET), false);
|
2022-02-17 03:30:17 +00:00
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_TUNE), false);
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_I18N_RATECONTROL), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_MODE), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_TWOPASS), false);
|
2022-02-17 03:30:17 +00:00
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_MULTIPASS), false);
|
2021-06-08 02:02:32 +00:00
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_LOOKAHEAD), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_ADAPTIVEI), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_ADAPTIVEB), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_I18N_RATECONTROL_LIMITS), true);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_LIMITS_BUFFERSIZE), true);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_LIMITS_BITRATE_TARGET), true);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_LIMITS_BITRATE_MAXIMUM), true);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_I18N_RATECONTROL_LIMITS_QUALITY), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_I18N_RATECONTROL_QP), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_QP_MINIMUM), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_QP_MAXIMUM), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_QP_I), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_QP_P), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_RATECONTROL_QP_B), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_I18N_AQ), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_AQ_SPATIAL), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_AQ_STRENGTH), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_AQ_TEMPORAL), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_I18N_OTHER), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_OTHER_BFRAMES), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_OTHER_BFRAMEREFERENCEMODE), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_OTHER_ZEROLATENCY), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_OTHER_WEIGHTEDPREDICTION), false);
|
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_OTHER_NONREFERENCEPFRAMES), false);
|
2021-10-17 08:16:04 +00:00
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_OTHER_REFERENCEFRAMES), false);
|
2022-02-17 03:30:17 +00:00
|
|
|
obs_property_set_enabled(obs_properties_get(props, ST_KEY_OTHER_LOWDELAYKEYFRAMESCALE), false);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2022-07-21 11:09:10 +00:00
|
|
|
if (const char* v = obs_data_get_string(settings, ST_KEY_PRESET);
|
|
|
|
!context->internal && (v != nullptr) && (v[0] != '\0')) {
|
2022-02-20 18:45:41 +00:00
|
|
|
av_opt_set(context->priv_data, "preset", v, AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // Rate Control
|
2022-07-21 11:09:10 +00:00
|
|
|
const char* v = obs_data_get_string(settings, ST_KEY_RATECONTROL_MODE);
|
|
|
|
if (!context->internal && (v != nullptr) && (v[0] != '\0')) {
|
2022-02-20 18:45:41 +00:00
|
|
|
av_opt_set(context->priv_data, "rc", v, AV_OPT_SEARCH_CHILDREN);
|
2022-02-17 03:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the name into useful flags.
|
2020-02-13 10:19:30 +00:00
|
|
|
bool have_bitrate = false;
|
|
|
|
bool have_bitrate_range = false;
|
|
|
|
bool have_quality = false;
|
2021-10-17 08:05:37 +00:00
|
|
|
bool have_qp_limits = false;
|
2020-02-13 10:19:30 +00:00
|
|
|
bool have_qp = false;
|
2022-02-20 18:45:41 +00:00
|
|
|
if (v && is_cbr(v)) {
|
2022-02-17 03:30:17 +00:00
|
|
|
have_bitrate = true;
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
if (!context->internal)
|
|
|
|
av_opt_set_int(context->priv_data, "cbr", 1, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
|
|
|
|
// Support for OBS Studio
|
|
|
|
obs_data_set_string(settings, "rate_control", "CBR");
|
2022-02-20 18:45:41 +00:00
|
|
|
} else if (v && is_vbr(v)) {
|
2020-02-13 10:19:30 +00:00
|
|
|
have_bitrate = true;
|
|
|
|
have_bitrate_range = true;
|
|
|
|
have_quality = true;
|
2021-10-17 08:05:37 +00:00
|
|
|
have_qp_limits = true;
|
2020-02-13 10:19:30 +00:00
|
|
|
have_qp = true;
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
if (!context->internal)
|
|
|
|
av_opt_set_int(context->priv_data, "cbr", 0, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
|
|
|
|
// Support for OBS Studio
|
|
|
|
obs_data_set_string(settings, "rate_control", "VBR");
|
2022-02-20 18:45:41 +00:00
|
|
|
} else if (v && is_cqp(v)) {
|
2020-01-13 00:52:30 +00:00
|
|
|
have_qp = true;
|
2021-12-03 07:22:08 +00:00
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
if (!context->internal)
|
|
|
|
av_opt_set_int(context->priv_data, "cbr", 0, AV_OPT_SEARCH_CHILDREN);
|
2021-12-03 07:22:08 +00:00
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
// Support for OBS Studio
|
|
|
|
obs_data_set_string(settings, "rate_control", "CQP");
|
|
|
|
} else {
|
2020-02-13 10:19:30 +00:00
|
|
|
have_bitrate = true;
|
2022-02-17 03:30:17 +00:00
|
|
|
have_bitrate_range = true;
|
2020-02-13 10:19:30 +00:00
|
|
|
have_quality = true;
|
2021-10-17 08:05:37 +00:00
|
|
|
have_qp_limits = true;
|
2022-02-17 03:30:17 +00:00
|
|
|
have_qp = true;
|
2021-12-03 07:22:08 +00:00
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
if (!context->internal)
|
|
|
|
av_opt_set_int(context->priv_data, "cbr", 0, AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
if (!context->internal) {
|
2022-02-17 03:30:17 +00:00
|
|
|
if (streamfx::ffmpeg::tools::avoption_exists(context->priv_data, "multipass")) {
|
|
|
|
// Multi-Pass
|
2022-07-21 11:09:10 +00:00
|
|
|
if (const char* v = obs_data_get_string(settings, ST_KEY_RATECONTROL_MULTIPASS);
|
|
|
|
(v != nullptr) && (v[0] != '\0')) {
|
2022-02-20 18:45:41 +00:00
|
|
|
av_opt_set(context->priv_data, "multipass", v, AV_OPT_SEARCH_CHILDREN);
|
2022-02-17 03:30:17 +00:00
|
|
|
av_opt_set_int(context->priv_data, "2pass", 0, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Two-Pass
|
|
|
|
if (int tp = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_TWOPASS)); tp > -1) {
|
|
|
|
av_opt_set_int(context->priv_data, "2pass", tp ? 1 : 0, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
}
|
2021-12-03 06:20:31 +00:00
|
|
|
}
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
// Look Ahead # of Frames
|
|
|
|
int la = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_LOOKAHEAD));
|
|
|
|
if (!streamfx::util::is_tristate_default(la)) {
|
|
|
|
av_opt_set_int(context->priv_data, "rc-lookahead", la, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
}
|
2020-04-17 08:24:13 +00:00
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
// Adaptive I-Frames
|
|
|
|
if (int64_t adapt_i = obs_data_get_int(settings, ST_KEY_RATECONTROL_ADAPTIVEI);
|
|
|
|
!streamfx::util::is_tristate_default(adapt_i) && (la != 0)) {
|
|
|
|
// no-scenecut is inverted compared to our UI.
|
|
|
|
av_opt_set_int(context->priv_data, "no-scenecut", 1 - adapt_i, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
}
|
2020-04-24 22:59:27 +00:00
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
// Adaptive B-Frames
|
2022-02-17 03:30:17 +00:00
|
|
|
if (std::string_view("h264_nvenc") == codec->name) {
|
2021-12-03 06:20:31 +00:00
|
|
|
if (int64_t adapt_b = obs_data_get_int(settings, ST_KEY_RATECONTROL_ADAPTIVEB);
|
|
|
|
!streamfx::util::is_tristate_default(adapt_b) && (la != 0)) {
|
|
|
|
av_opt_set_int(context->priv_data, "b_adapt", adapt_b, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
}
|
2020-04-17 07:41:58 +00:00
|
|
|
}
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (have_bitrate) {
|
2021-06-08 02:02:32 +00:00
|
|
|
int64_t v = obs_data_get_int(settings, ST_KEY_RATECONTROL_LIMITS_BITRATE_TARGET);
|
2020-01-15 04:50:31 +00:00
|
|
|
|
2021-12-03 07:22:08 +00:00
|
|
|
// Allow OBS to specify a maximum allowed bitrate.
|
|
|
|
if (obs_data_get_int(settings, "bitrate") != obs_data_get_default_int(settings, "bitrate")) {
|
|
|
|
// obs_data_has_user_value(X, Y) is also true if obs_data_set_Z(X, Y, obs_data_get_Z(X, Y))
|
|
|
|
v = std::clamp<int64_t>(v, -1, obs_data_get_int(settings, "bitrate"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v > -1) {
|
|
|
|
context->bit_rate = static_cast<int>(v * 1000);
|
|
|
|
}
|
2020-03-07 00:52:04 +00:00
|
|
|
} else {
|
|
|
|
context->bit_rate = 0;
|
2020-01-15 04:50:31 +00:00
|
|
|
}
|
2020-02-13 10:19:30 +00:00
|
|
|
if (have_bitrate_range) {
|
2021-12-03 07:22:08 +00:00
|
|
|
if (int64_t max = obs_data_get_int(settings, ST_KEY_RATECONTROL_LIMITS_BITRATE_MAXIMUM); max > -1) {
|
2020-01-15 04:50:31 +00:00
|
|
|
context->rc_max_rate = static_cast<int>(max * 1000);
|
2021-12-03 07:22:08 +00:00
|
|
|
} else {
|
|
|
|
context->rc_max_rate = context->bit_rate;
|
|
|
|
}
|
2021-12-02 17:27:43 +00:00
|
|
|
context->rc_min_rate = context->bit_rate;
|
2020-03-07 00:52:04 +00:00
|
|
|
} else {
|
2021-12-02 17:27:43 +00:00
|
|
|
context->rc_min_rate = context->bit_rate;
|
|
|
|
context->rc_max_rate = context->bit_rate;
|
2020-01-15 04:50:31 +00:00
|
|
|
}
|
2021-12-03 07:22:08 +00:00
|
|
|
{ // Support for OBS Studio
|
|
|
|
obs_data_set_int(settings, "bitrate", context->rc_max_rate);
|
|
|
|
}
|
2020-04-17 08:24:13 +00:00
|
|
|
|
|
|
|
// Buffer Size
|
2020-02-13 10:19:30 +00:00
|
|
|
if (have_bitrate || have_bitrate_range) {
|
2021-06-08 02:02:32 +00:00
|
|
|
if (int64_t v = obs_data_get_int(settings, ST_KEY_RATECONTROL_LIMITS_BUFFERSIZE); v > -1)
|
2020-01-15 04:50:31 +00:00
|
|
|
context->rc_buffer_size = static_cast<int>(v * 1000);
|
2020-03-07 00:52:04 +00:00
|
|
|
} else {
|
|
|
|
context->rc_buffer_size = 0;
|
2020-01-15 04:50:31 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
if (!context->internal) {
|
|
|
|
// Quality Limits
|
|
|
|
if (have_qp_limits) {
|
|
|
|
if (int qmin = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_QP_MINIMUM)); qmin > -1)
|
|
|
|
context->qmin = qmin;
|
|
|
|
if (int qmax = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_QP_MAXIMUM)); qmax > -1)
|
|
|
|
context->qmax = qmax;
|
|
|
|
} else {
|
|
|
|
context->qmin = -1;
|
|
|
|
context->qmax = -1;
|
|
|
|
}
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
// Quality Target
|
|
|
|
if (have_quality) {
|
2022-02-17 03:30:17 +00:00
|
|
|
if (double_t v = obs_data_get_double(settings, ST_KEY_RATECONTROL_LIMITS_QUALITY); v > 0) {
|
2021-12-03 06:20:31 +00:00
|
|
|
av_opt_set_double(context->priv_data, "cq", v, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
av_opt_set_double(context->priv_data, "cq", 0, AV_OPT_SEARCH_CHILDREN);
|
2021-10-17 08:05:37 +00:00
|
|
|
}
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
// QP Settings
|
|
|
|
if (have_qp) {
|
|
|
|
if (int64_t qp = obs_data_get_int(settings, ST_KEY_RATECONTROL_QP_I); qp > -1)
|
|
|
|
av_opt_set_int(context->priv_data, "init_qpI", static_cast<int>(qp), AV_OPT_SEARCH_CHILDREN);
|
|
|
|
if (int64_t qp = obs_data_get_int(settings, ST_KEY_RATECONTROL_QP_P); qp > -1)
|
|
|
|
av_opt_set_int(context->priv_data, "init_qpP", static_cast<int>(qp), AV_OPT_SEARCH_CHILDREN);
|
|
|
|
if (int64_t qp = obs_data_get_int(settings, ST_KEY_RATECONTROL_QP_B); qp > -1)
|
|
|
|
av_opt_set_int(context->priv_data, "init_qpB", static_cast<int>(qp), AV_OPT_SEARCH_CHILDREN);
|
|
|
|
}
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
if (!context->internal) { // AQ
|
2021-06-08 02:02:32 +00:00
|
|
|
int64_t saq = obs_data_get_int(settings, ST_KEY_AQ_SPATIAL);
|
|
|
|
int64_t taq = obs_data_get_int(settings, ST_KEY_AQ_TEMPORAL);
|
2020-01-13 00:52:30 +00:00
|
|
|
|
|
|
|
if (strcmp(codec->name, "h264_nvenc") == 0) {
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::is_tristate_default(saq))
|
2020-01-15 04:50:31 +00:00
|
|
|
av_opt_set_int(context->priv_data, "spatial-aq", saq, AV_OPT_SEARCH_CHILDREN);
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::is_tristate_default(taq))
|
2020-01-15 04:50:31 +00:00
|
|
|
av_opt_set_int(context->priv_data, "temporal-aq", taq, AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
} else {
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::is_tristate_default(saq))
|
2020-01-15 04:50:31 +00:00
|
|
|
av_opt_set_int(context->priv_data, "spatial_aq", saq, AV_OPT_SEARCH_CHILDREN);
|
2021-06-08 02:18:02 +00:00
|
|
|
if (!streamfx::util::is_tristate_default(taq))
|
2020-01-15 04:50:31 +00:00
|
|
|
av_opt_set_int(context->priv_data, "temporal_aq", taq, AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
2021-06-08 02:18:02 +00:00
|
|
|
if (streamfx::util::is_tristate_enabled(saq))
|
2021-06-08 02:02:32 +00:00
|
|
|
if (int64_t aqs = obs_data_get_int(settings, ST_KEY_AQ_STRENGTH); aqs > -1)
|
2020-02-13 10:19:30 +00:00
|
|
|
av_opt_set_int(context->priv_data, "aq-strength", static_cast<int>(aqs), AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 06:20:31 +00:00
|
|
|
if (!context->internal) { // Other
|
2021-06-08 02:02:32 +00:00
|
|
|
if (int64_t bf = obs_data_get_int(settings, ST_KEY_OTHER_BFRAMES); bf > -1)
|
2022-02-17 03:30:17 +00:00
|
|
|
av_opt_set_int(context, "bf", bf, AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
if (int64_t zl = obs_data_get_int(settings, ST_KEY_OTHER_ZEROLATENCY); !streamfx::util::is_tristate_default(zl))
|
2020-01-15 04:50:31 +00:00
|
|
|
av_opt_set_int(context->priv_data, "zerolatency", zl, AV_OPT_SEARCH_CHILDREN);
|
2021-06-08 02:18:02 +00:00
|
|
|
if (int64_t nrp = obs_data_get_int(settings, ST_KEY_OTHER_NONREFERENCEPFRAMES);
|
|
|
|
!streamfx::util::is_tristate_default(nrp))
|
2020-01-15 04:50:31 +00:00
|
|
|
av_opt_set_int(context->priv_data, "nonref_p", nrp, AV_OPT_SEARCH_CHILDREN);
|
2021-10-17 08:16:04 +00:00
|
|
|
if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_REFERENCEFRAMES); v > -1)
|
2022-02-17 03:30:17 +00:00
|
|
|
av_opt_set_int(context, "refs", v, AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2021-06-08 02:02:32 +00:00
|
|
|
int64_t wp = obs_data_get_int(settings, ST_KEY_OTHER_WEIGHTEDPREDICTION);
|
2021-06-08 02:18:02 +00:00
|
|
|
if ((context->max_b_frames > 0) && streamfx::util::is_tristate_enabled(wp)) {
|
2020-07-25 14:51:22 +00:00
|
|
|
DLOG_WARNING("[%s] Weighted Prediction disabled because of B-Frames being used.", codec->name);
|
2020-01-15 04:50:31 +00:00
|
|
|
av_opt_set_int(context->priv_data, "weighted_pred", 0, AV_OPT_SEARCH_CHILDREN);
|
2021-06-08 02:18:02 +00:00
|
|
|
} else if (!streamfx::util::is_tristate_default(wp)) {
|
2020-01-15 04:50:31 +00:00
|
|
|
av_opt_set_int(context->priv_data, "weighted_pred", wp, AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-21 11:09:10 +00:00
|
|
|
if (const char* v = obs_data_get_string(settings, ST_KEY_OTHER_BFRAMEREFERENCEMODE);
|
|
|
|
(v != nullptr) && (v[0] != '\0')) {
|
2022-02-20 18:45:41 +00:00
|
|
|
av_opt_set(context->priv_data, "b_ref_mode", v, AV_OPT_SEARCH_CHILDREN);
|
2022-02-17 03:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (auto v = obs_data_get_int(settings, ST_KEY_OTHER_LOWDELAYKEYFRAMESCALE); v > -1) {
|
|
|
|
av_opt_set_int(context->priv_data, "ldkfs", v, AV_OPT_SEARCH_CHILDREN);
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
void nvenc::log_options(obs_data_t*, const AVCodec* codec, AVCodecContext* context)
|
2020-01-13 00:52:30 +00:00
|
|
|
{
|
2021-06-08 02:12:55 +00:00
|
|
|
using namespace ::streamfx::ffmpeg;
|
2020-04-05 16:52:06 +00:00
|
|
|
|
2021-06-04 03:00:32 +00:00
|
|
|
DLOG_INFO("[%s] NVIDIA NVENC:", codec->name);
|
2020-07-28 23:00:45 +00:00
|
|
|
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); });
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_bool(context, "2pass", " Two Pass");
|
2022-02-17 03:30:17 +00:00
|
|
|
tools::print_av_option_string2(context, "multipass", " Multi-Pass",
|
|
|
|
[](int64_t v, std::string_view o) { return std::string(o); });
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_int(context, "rc-lookahead", " Look-Ahead", "Frames");
|
2020-04-25 06:32:34 +00:00
|
|
|
tools::print_av_option_bool(context, "no-scenecut", " Adaptive I-Frames", true);
|
2020-01-13 00:52:30 +00:00
|
|
|
if (strcmp(codec->name, "h264_nvenc") == 0)
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_bool(context, "b_adapt", " Adaptive B-Frames");
|
|
|
|
|
2020-07-25 14:51:22 +00:00
|
|
|
DLOG_INFO("[%s] Bitrate:", codec->name);
|
2020-03-07 00:52:04 +00:00
|
|
|
tools::print_av_option_int(context, "b", " Target", "bits/sec");
|
|
|
|
tools::print_av_option_int(context, "minrate", " Minimum", "bits/sec");
|
|
|
|
tools::print_av_option_int(context, "maxrate", " Maximum", "bits/sec");
|
|
|
|
tools::print_av_option_int(context, "bufsize", " Buffer", "bits");
|
2020-07-25 14:51:22 +00:00
|
|
|
DLOG_INFO("[%s] Quality:", codec->name);
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_int(context, "cq", " Target", "");
|
2020-01-15 02:59:03 +00:00
|
|
|
tools::print_av_option_int(context, "qmin", " Minimum", "");
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_int(context, "qmax", " Maximum", "");
|
2020-07-25 14:51:22 +00:00
|
|
|
DLOG_INFO("[%s] Quantization Parameters:", codec->name);
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_int(context, "init_qpI", " I-Frame", "");
|
|
|
|
tools::print_av_option_int(context, "init_qpP", " P-Frame", "");
|
|
|
|
tools::print_av_option_int(context, "init_qpB", " B-Frame", "");
|
2022-02-17 03:30:17 +00:00
|
|
|
tools::print_av_option_int(context, "qp_cb_offset", " CB Offset", "");
|
|
|
|
tools::print_av_option_int(context, "qp_cr_offset", " CR Offset", "");
|
2020-01-13 21:40:15 +00:00
|
|
|
|
2020-03-07 00:52:04 +00:00
|
|
|
tools::print_av_option_int(context, "bf", " B-Frames", "Frames");
|
2020-07-28 23:00:45 +00:00
|
|
|
tools::print_av_option_string2(context, "b_ref_mode", " Reference Mode",
|
|
|
|
[](int64_t v, std::string_view o) { return std::string(o); });
|
2020-01-13 00:52:30 +00:00
|
|
|
|
2020-07-25 14:51:22 +00:00
|
|
|
DLOG_INFO("[%s] Adaptive Quantization:", codec->name);
|
2020-01-13 00:52:30 +00:00
|
|
|
if (strcmp(codec->name, "h264_nvenc") == 0) {
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_bool(context, "spatial-aq", " Spatial AQ");
|
|
|
|
tools::print_av_option_int(context, "aq-strength", " Strength", "");
|
|
|
|
tools::print_av_option_bool(context, "temporal-aq", " Temporal AQ");
|
2020-01-13 00:52:30 +00:00
|
|
|
} else {
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_bool(context, "spatial_aq", " Spatial AQ");
|
|
|
|
tools::print_av_option_int(context, "aq-strength", " Strength", "");
|
|
|
|
tools::print_av_option_bool(context, "temporal_aq", " Temporal AQ");
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 14:51:22 +00:00
|
|
|
DLOG_INFO("[%s] Other:", codec->name);
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_bool(context, "zerolatency", " Zero Latency");
|
|
|
|
tools::print_av_option_bool(context, "weighted_pred", " Weighted Prediction");
|
|
|
|
tools::print_av_option_bool(context, "nonref_p", " Non-reference P-Frames");
|
2021-12-03 07:47:19 +00:00
|
|
|
tools::print_av_option_int(context, "refs", " Reference Frames", "Frames");
|
2020-01-13 21:40:15 +00:00
|
|
|
tools::print_av_option_bool(context, "strict_gop", " Strict GOP");
|
|
|
|
tools::print_av_option_bool(context, "aud", " Access Unit Delimiters");
|
|
|
|
tools::print_av_option_bool(context, "bluray-compat", " Bluray Compatibility");
|
2022-02-17 03:30:17 +00:00
|
|
|
tools::print_av_option_bool(context, "a53cc", " A53 Closed Captions");
|
2020-02-13 10:19:30 +00:00
|
|
|
tools::print_av_option_int(context, "dpb_size", " DPB Size", "Frames");
|
2022-02-17 03:30:17 +00:00
|
|
|
tools::print_av_option_int(context, "ldkfs", " DPB Size", "Frames");
|
|
|
|
tools::print_av_option_bool(context, "extra_sei", " Extra SEI Data");
|
|
|
|
tools::print_av_option_bool(context, "udu_sei", " User SEI Data");
|
|
|
|
tools::print_av_option_bool(context, "intra-refresh", " Intra-Refresh");
|
|
|
|
tools::print_av_option_bool(context, "single-slice-intra-refresh", " Single Slice Intra-Refresh");
|
|
|
|
tools::print_av_option_bool(context, "constrained-encoding", " Constrained Encoding");
|
2020-01-13 00:52:30 +00:00
|
|
|
}
|
2020-07-05 22:10:04 +00:00
|
|
|
|
|
|
|
void streamfx::encoder::ffmpeg::handler::nvenc::migrate(obs_data_t* settings, uint64_t version, const AVCodec* codec,
|
|
|
|
AVCodecContext* context)
|
|
|
|
{
|
2021-10-17 08:28:56 +00:00
|
|
|
// Only test for A.B.C in A.B.C.D
|
|
|
|
version = version & STREAMFX_MASK_UPDATE;
|
2020-07-05 22:10:04 +00:00
|
|
|
|
2021-12-01 12:57:24 +00:00
|
|
|
#define COPY_UNSET(TYPE, FROM, TO) \
|
|
|
|
if (obs_data_has_user_value(settings, FROM)) { \
|
|
|
|
obs_data_set_##TYPE(settings, TO, obs_data_get_##TYPE(settings, FROM)); \
|
|
|
|
obs_data_unset_user_value(settings, FROM); \
|
2021-10-17 08:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (version <= STREAMFX_MAKE_VERSION(0, 8, 0, 0)) {
|
|
|
|
COPY_UNSET(int, "RateControl.Bitrate.Target", ST_KEY_RATECONTROL_LIMITS_BITRATE_TARGET);
|
|
|
|
COPY_UNSET(int, "RateControl.Bitrate.Maximum", ST_KEY_RATECONTROL_LIMITS_BITRATE_TARGET);
|
|
|
|
COPY_UNSET(int, "RateControl.BufferSize", ST_KEY_RATECONTROL_LIMITS_BUFFERSIZE);
|
|
|
|
COPY_UNSET(int, "RateControl.Quality.Minimum", ST_KEY_RATECONTROL_QP_MINIMUM);
|
|
|
|
COPY_UNSET(int, "RateControl.Quality.Maximum", ST_KEY_RATECONTROL_QP_MAXIMUM);
|
|
|
|
COPY_UNSET(double, "RateControl.Quality.Target", ST_KEY_RATECONTROL_LIMITS_QUALITY);
|
2020-07-05 22:10:04 +00:00
|
|
|
}
|
2021-10-17 08:28:56 +00:00
|
|
|
|
2021-12-01 12:57:24 +00:00
|
|
|
if (version < STREAMFX_MAKE_VERSION(0, 11, 0, 0)) {
|
2021-10-17 08:28:56 +00:00
|
|
|
obs_data_unset_user_value(settings, "Other.AccessUnitDelimiter");
|
|
|
|
obs_data_unset_user_value(settings, "Other.DecodedPictureBufferSize");
|
|
|
|
}
|
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
if (version < STREAMFX_MAKE_VERSION(0, 11, 1, 0)) {
|
2022-02-20 18:45:41 +00:00
|
|
|
// Preset
|
|
|
|
if (auto v = obs_data_get_int(settings, ST_KEY_PRESET); v != -1) {
|
|
|
|
std::map<int64_t, std::string> preset{
|
|
|
|
{0, "default"}, {1, "slow"}, {2, "medium"}, {3, "fast"}, {4, "hp"}, {5, "hq"},
|
|
|
|
{6, "bd"}, {7, "ll"}, {8, "llhq"}, {9, "llhp"}, {10, "lossless"}, {11, "losslesshp"},
|
|
|
|
};
|
|
|
|
if (auto k = preset.find(v); k != preset.end()) {
|
|
|
|
obs_data_set_string(settings, ST_KEY_PRESET, k->second.data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rate Control Mode
|
2022-02-17 03:30:17 +00:00
|
|
|
if (auto v = obs_data_get_int(settings, ST_KEY_RATECONTROL_MODE); v != -1) {
|
2022-02-20 18:45:41 +00:00
|
|
|
if (!obs_data_has_user_value(settings, ST_KEY_RATECONTROL_MODE))
|
|
|
|
v = 4;
|
|
|
|
|
2022-02-17 03:30:17 +00:00
|
|
|
switch (v) {
|
|
|
|
case 0: // CQP
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_data_set_string(settings, ST_KEY_RATECONTROL_MODE, "constqp");
|
2022-02-17 03:30:17 +00:00
|
|
|
break;
|
|
|
|
case 2: // VBR_HQ
|
|
|
|
obs_data_set_int(settings, ST_KEY_RATECONTROL_TWOPASS, 1);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_data_set_string(settings, ST_KEY_RATECONTROL_MULTIPASS, "qres");
|
2022-02-17 03:30:17 +00:00
|
|
|
case 1: // VBR
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_data_set_string(settings, ST_KEY_RATECONTROL_MODE, "vbr");
|
2022-02-17 03:30:17 +00:00
|
|
|
break;
|
|
|
|
case 5: // CBR_LD_HQ
|
|
|
|
obs_data_set_int(settings, ST_KEY_OTHER_LOWDELAYKEYFRAMESCALE, 1);
|
|
|
|
case 4: // CBR_HQ
|
|
|
|
obs_data_set_int(settings, ST_KEY_RATECONTROL_TWOPASS, 1);
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_data_set_string(settings, ST_KEY_RATECONTROL_MULTIPASS, "qres");
|
2022-02-17 03:30:17 +00:00
|
|
|
case 3: // CBR
|
2022-02-20 18:45:41 +00:00
|
|
|
obs_data_set_string(settings, ST_KEY_RATECONTROL_MODE, "cbr");
|
2022-02-17 03:30:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-02-20 18:45:41 +00:00
|
|
|
|
|
|
|
// Target Quality
|
2022-02-17 03:30:17 +00:00
|
|
|
if (auto v = obs_data_get_double(settings, ST_KEY_RATECONTROL_LIMITS_QUALITY); v > 0) {
|
|
|
|
obs_data_set_double(settings, ST_KEY_RATECONTROL_LIMITS_QUALITY, (v / 100.) * 51.);
|
|
|
|
}
|
2022-02-20 18:45:41 +00:00
|
|
|
|
|
|
|
// B-Frame Reference Modes
|
|
|
|
if (auto v = obs_data_get_int(settings, ST_KEY_OTHER_BFRAMEREFERENCEMODE); v != -1) {
|
|
|
|
std::map<int64_t, std::string> preset{
|
|
|
|
{0, "default"},
|
|
|
|
{1, "each"},
|
|
|
|
{2, "middle"},
|
|
|
|
};
|
|
|
|
if (auto k = preset.find(v); k != preset.end()) {
|
|
|
|
obs_data_set_string(settings, ST_KEY_OTHER_BFRAMEREFERENCEMODE, k->second.data());
|
|
|
|
}
|
|
|
|
}
|
2022-02-17 03:30:17 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 08:28:56 +00:00
|
|
|
#undef COPY_UNSET
|
2020-07-05 22:10:04 +00:00
|
|
|
}
|