mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-26 17:32:06 +00:00
libavcodec/qsvenc: Add bitrate reset support to qsvenc
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
This commit is contained in:
parent
17df61083d
commit
29a3ba8693
@ -3365,6 +3365,12 @@ Change this value to reset qsv codec's low_delay_brc configuration.
|
||||
|
||||
@item @var{framerate}
|
||||
Change this value to reset qsv codec's framerate configuration.
|
||||
|
||||
@item @var{bit_rate}
|
||||
@item @var{rc_buffer_size}
|
||||
@item @var{rc_initial_buffer_occupancy}
|
||||
@item @var{rc_max_rate}
|
||||
Change these value to reset qsv codec's bitrate control configuration.
|
||||
@end table
|
||||
|
||||
@subsection H264 options
|
||||
|
@ -718,6 +718,10 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
|
||||
max_bitrate_kbps = avctx->rc_max_rate / 1000;
|
||||
brc_param_multiplier = (FFMAX(FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
|
||||
initial_delay_in_kilobytes) + 0x10000) / 0x10000;
|
||||
q->old_rc_buffer_size = avctx->rc_buffer_size;
|
||||
q->old_rc_initial_buffer_occupancy = avctx->rc_initial_buffer_occupancy;
|
||||
q->old_bit_rate = avctx->bit_rate;
|
||||
q->old_rc_max_rate = avctx->rc_max_rate;
|
||||
|
||||
switch (q->param.mfx.RateControlMethod) {
|
||||
case MFX_RATECONTROL_CBR:
|
||||
@ -1863,6 +1867,39 @@ static int update_frame_rate(AVCodecContext *avctx, QSVEncContext *q)
|
||||
return updated;
|
||||
}
|
||||
|
||||
static int update_bitrate(AVCodecContext *avctx, QSVEncContext *q)
|
||||
{
|
||||
int updated = 0;
|
||||
int target_bitrate_kbps, max_bitrate_kbps, brc_param_multiplier;
|
||||
int buffer_size_in_kilobytes, initial_delay_in_kilobytes;
|
||||
|
||||
UPDATE_PARAM(q->old_rc_buffer_size, avctx->rc_buffer_size);
|
||||
UPDATE_PARAM(q->old_rc_initial_buffer_occupancy, avctx->rc_initial_buffer_occupancy);
|
||||
UPDATE_PARAM(q->old_bit_rate, avctx->bit_rate);
|
||||
UPDATE_PARAM(q->old_rc_max_rate, avctx->rc_max_rate);
|
||||
if (!updated)
|
||||
return 0;
|
||||
|
||||
buffer_size_in_kilobytes = avctx->rc_buffer_size / 8000;
|
||||
initial_delay_in_kilobytes = avctx->rc_initial_buffer_occupancy / 8000;
|
||||
target_bitrate_kbps = avctx->bit_rate / 1000;
|
||||
max_bitrate_kbps = avctx->rc_max_rate / 1000;
|
||||
brc_param_multiplier = (FFMAX(FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
|
||||
initial_delay_in_kilobytes) + 0x10000) / 0x10000;
|
||||
|
||||
q->param.mfx.BufferSizeInKB = buffer_size_in_kilobytes / brc_param_multiplier;
|
||||
q->param.mfx.InitialDelayInKB = initial_delay_in_kilobytes / brc_param_multiplier;
|
||||
q->param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
|
||||
q->param.mfx.MaxKbps = max_bitrate_kbps / brc_param_multiplier;
|
||||
q->param.mfx.BRCParamMultiplier = brc_param_multiplier;
|
||||
av_log(avctx, AV_LOG_VERBOSE,
|
||||
"Reset BufferSizeInKB: %d; InitialDelayInKB: %d; "
|
||||
"TargetKbps: %d; MaxKbps: %d; BRCParamMultiplier: %d\n",
|
||||
q->param.mfx.BufferSizeInKB, q->param.mfx.InitialDelayInKB,
|
||||
q->param.mfx.TargetKbps, q->param.mfx.MaxKbps, q->param.mfx.BRCParamMultiplier);
|
||||
return updated;
|
||||
}
|
||||
|
||||
static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
|
||||
const AVFrame *frame)
|
||||
{
|
||||
@ -1877,6 +1914,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q,
|
||||
needReset |= update_rir(avctx, q);
|
||||
needReset |= update_low_delay_brc(avctx, q);
|
||||
needReset |= update_frame_rate(avctx, q);
|
||||
needReset |= update_bitrate(avctx, q);
|
||||
ret = update_min_max_qp(avctx, q);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
@ -273,6 +273,11 @@ typedef struct QSVEncContext {
|
||||
int old_low_delay_brc;
|
||||
// This is used for framerate reset
|
||||
AVRational old_framerate;
|
||||
// These are used for bitrate control reset
|
||||
int old_bit_rate;
|
||||
int old_rc_buffer_size;
|
||||
int old_rc_initial_buffer_occupancy;
|
||||
int old_rc_max_rate;
|
||||
} QSVEncContext;
|
||||
|
||||
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);
|
||||
|
Loading…
Reference in New Issue
Block a user