remove bitrate variable
This commit is contained in:
@@ -130,12 +130,11 @@ static void check_profile_guid_supported(std::shared_ptr<video_encoder_nvenc_sha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NV_ENC_RC_PARAMS video_encoder_nvenc::get_rc_params()
|
NV_ENC_RC_PARAMS video_encoder_nvenc::get_rc_params(int bitrate)
|
||||||
{
|
{
|
||||||
NV_ENC_RC_PARAMS rc_params {
|
NV_ENC_RC_PARAMS rc_params {
|
||||||
.rateControlMode = NV_ENC_PARAMS_RC_CBR,
|
.rateControlMode = NV_ENC_PARAMS_RC_CBR,
|
||||||
.averageBitRate = bitrate,
|
.averageBitRate = bitrate,
|
||||||
.maxBitRate = bitrate,
|
|
||||||
.vbvBufferSize = bitrate / fps,
|
.vbvBufferSize = bitrate / fps,
|
||||||
.vbvInitialDelay = bitrate / fps,
|
.vbvInitialDelay = bitrate / fps,
|
||||||
.multiPass = NV_ENC_TWO_PASS_QUARTER_RESOLUTION
|
.multiPass = NV_ENC_TWO_PASS_QUARTER_RESOLUTION
|
||||||
@@ -152,8 +151,7 @@ video_encoder_nvenc::video_encoder_nvenc(
|
|||||||
video_encoder(stream_idx, settings.channels, settings.bitrate_multiplier, true),
|
video_encoder(stream_idx, settings.channels, settings.bitrate_multiplier, true),
|
||||||
vk(vk),
|
vk(vk),
|
||||||
shared_state(video_encoder_nvenc_shared_state::get()),
|
shared_state(video_encoder_nvenc_shared_state::get()),
|
||||||
fps(fps),
|
fps(fps)
|
||||||
bitrate(settings.bitrate)
|
|
||||||
{
|
{
|
||||||
if (settings.bit_depth != 8 && settings.bit_depth != 10)
|
if (settings.bit_depth != 8 && settings.bit_depth != 10)
|
||||||
throw std::runtime_error("nvenc encoder only supports 8-bit and 10-bit encoding");
|
throw std::runtime_error("nvenc encoder only supports 8-bit and 10-bit encoding");
|
||||||
@@ -199,7 +197,7 @@ video_encoder_nvenc::video_encoder_nvenc(
|
|||||||
config = preset_config.presetCfg;
|
config = preset_config.presetCfg;
|
||||||
|
|
||||||
// Bitrate control
|
// Bitrate control
|
||||||
config.rcParams = get_rc_params();
|
config.rcParams = get_rc_params(settings.bitrate);
|
||||||
|
|
||||||
config.gopLength = NVENC_INFINITE_GOPLENGTH;
|
config.gopLength = NVENC_INFINITE_GOPLENGTH;
|
||||||
config.frameIntervalP = 1;
|
config.frameIntervalP = 1;
|
||||||
@@ -421,13 +419,10 @@ std::optional<video_encoder::data> video_encoder_nvenc::encode(bool idr, std::ch
|
|||||||
{
|
{
|
||||||
CU_CHECK(shared_state->cuda_fn->cuCtxPushCurrent(shared_state->cuda));
|
CU_CHECK(shared_state->cuda_fn->cuCtxPushCurrent(shared_state->cuda));
|
||||||
|
|
||||||
if (auto bitrate2 = pending_bitrate.exchange(0))
|
if (auto bitrate = pending_bitrate.exchange(0))
|
||||||
{
|
{
|
||||||
U_LOG_W("reconfiguring bitrate, new value: %d", bitrate2);
|
NV_ENC_RC_PARAMS old_rc = config.rcParams;
|
||||||
|
config.rcParams = get_rc_params(bitrate);
|
||||||
std::swap(bitrate, bitrate2);
|
|
||||||
|
|
||||||
config.rcParams = get_rc_params();
|
|
||||||
|
|
||||||
NV_ENC_RECONFIGURE_PARAMS reconfig_params {
|
NV_ENC_RECONFIGURE_PARAMS reconfig_params {
|
||||||
.version = NV_ENC_RECONFIGURE_PARAMS_VER,
|
.version = NV_ENC_RECONFIGURE_PARAMS_VER,
|
||||||
@@ -438,12 +433,12 @@ std::optional<video_encoder::data> video_encoder_nvenc::encode(bool idr, std::ch
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
NVENC_CHECK(shared_state->fn.nvEncReconfigureEncoder(session_handle, &reconfig_params));
|
NVENC_CHECK(shared_state->fn.nvEncReconfigureEncoder(session_handle, &reconfig_params));
|
||||||
U_LOG_W("reconfiguring succeeded, new bitrate: %d", bitrate);
|
U_LOG_I("nvenc: reconfiguring bitrate succeeded, new value: %d", bitrate);
|
||||||
}
|
}
|
||||||
catch(const std::exception& e)
|
catch(const std::exception& e)
|
||||||
{
|
{
|
||||||
U_LOG_E("nvenc: failed to reconfigure bitrate - from %d to %d", bitrate2, bitrate);
|
U_LOG_E("nvenc: failed to reconfigure bitrate to %d", bitrate);
|
||||||
std::swap(bitrate, bitrate2);
|
config.rcParams = old_rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,10 +53,9 @@ private:
|
|||||||
std::array<in_t, num_slots> in;
|
std::array<in_t, num_slots> in;
|
||||||
|
|
||||||
float fps;
|
float fps;
|
||||||
int bitrate;
|
|
||||||
int bytesPerPixel = 1;
|
int bytesPerPixel = 1;
|
||||||
|
|
||||||
NV_ENC_RC_PARAMS get_rc_params();
|
NV_ENC_RC_PARAMS get_rc_params(int bitrate);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
video_encoder_nvenc(wivrn_vk_bundle & vk, encoder_settings & settings, float fps, uint8_t stream_idx);
|
video_encoder_nvenc(wivrn_vk_bundle & vk, encoder_settings & settings, float fps, uint8_t stream_idx);
|
||||||
|
|||||||
Reference in New Issue
Block a user