mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-08 06:09:50 +00:00
lavc/vaapi_encode: Enable block level bitrate control
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
This commit is contained in:
parent
74a8e080d0
commit
a8d9fab06b
3 changed files with 24 additions and 2 deletions
|
|
@ -4089,6 +4089,10 @@ Quality-defined variable-bitrate.
|
||||||
Average variable bitrate.
|
Average variable bitrate.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
@item blbrc
|
||||||
|
Enable block level rate control, which assigns different bitrate block by block.
|
||||||
|
Invalid for CQP mode.
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
Each encoder also has its own specific options:
|
Each encoder also has its own specific options:
|
||||||
|
|
|
||||||
|
|
@ -1805,6 +1805,11 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
|
||||||
int i, first = 1, res;
|
int i, first = 1, res;
|
||||||
|
|
||||||
supported_va_rc_modes = rc_attr.value;
|
supported_va_rc_modes = rc_attr.value;
|
||||||
|
if (ctx->blbrc && !(supported_va_rc_modes & VA_RC_MB)) {
|
||||||
|
ctx->blbrc = 0;
|
||||||
|
av_log(avctx, AV_LOG_WARNING, "Driver does not support BLBRC.\n");
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < FF_ARRAY_ELEMS(vaapi_encode_rc_modes); i++) {
|
for (i = 0; i < FF_ARRAY_ELEMS(vaapi_encode_rc_modes); i++) {
|
||||||
rc_mode = &vaapi_encode_rc_modes[i];
|
rc_mode = &vaapi_encode_rc_modes[i];
|
||||||
if (supported_va_rc_modes & rc_mode->va_mode) {
|
if (supported_va_rc_modes & rc_mode->va_mode) {
|
||||||
|
|
@ -2016,13 +2021,18 @@ rc_mode_found:
|
||||||
ctx->va_bit_rate = rc_bits_per_second;
|
ctx->va_bit_rate = rc_bits_per_second;
|
||||||
|
|
||||||
av_log(avctx, AV_LOG_VERBOSE, "RC mode: %s.\n", rc_mode->name);
|
av_log(avctx, AV_LOG_VERBOSE, "RC mode: %s.\n", rc_mode->name);
|
||||||
|
|
||||||
|
if (ctx->blbrc && ctx->va_rc_mode == VA_RC_CQP)
|
||||||
|
ctx->blbrc = 0;
|
||||||
|
av_log(avctx, AV_LOG_VERBOSE, "Block Level bitrate control: %s.\n", ctx->blbrc ? "ON" : "OFF");
|
||||||
|
|
||||||
if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
|
if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
|
||||||
// This driver does not want the RC mode attribute to be set.
|
// This driver does not want the RC mode attribute to be set.
|
||||||
} else {
|
} else {
|
||||||
ctx->config_attributes[ctx->nb_config_attributes++] =
|
ctx->config_attributes[ctx->nb_config_attributes++] =
|
||||||
(VAConfigAttrib) {
|
(VAConfigAttrib) {
|
||||||
.type = VAConfigAttribRateControl,
|
.type = VAConfigAttribRateControl,
|
||||||
.value = ctx->va_rc_mode,
|
.value = ctx->blbrc ? ctx->va_rc_mode | VA_RC_MB : ctx->va_rc_mode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2051,6 +2061,7 @@ rc_mode_found:
|
||||||
#if VA_CHECK_VERSION(1, 1, 0)
|
#if VA_CHECK_VERSION(1, 1, 0)
|
||||||
.ICQ_quality_factor = av_clip(rc_quality, 1, 51),
|
.ICQ_quality_factor = av_clip(rc_quality, 1, 51),
|
||||||
.max_qp = (avctx->qmax > 0 ? avctx->qmax : 0),
|
.max_qp = (avctx->qmax > 0 ? avctx->qmax : 0),
|
||||||
|
.rc_flags.bits.mb_rate_control = ctx->blbrc ? 1 : 2,
|
||||||
#endif
|
#endif
|
||||||
#if VA_CHECK_VERSION(1, 3, 0)
|
#if VA_CHECK_VERSION(1, 3, 0)
|
||||||
.quality_factor = rc_quality,
|
.quality_factor = rc_quality,
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,9 @@ typedef struct VAAPIEncodeContext {
|
||||||
// available modes).
|
// available modes).
|
||||||
int explicit_rc_mode;
|
int explicit_rc_mode;
|
||||||
|
|
||||||
|
// Block Level based bitrate control.
|
||||||
|
int blbrc;
|
||||||
|
|
||||||
// Explicitly-set QP, for use with the "qp" options.
|
// Explicitly-set QP, for use with the "qp" options.
|
||||||
// (Forces CQP mode when set, overriding everything else.)
|
// (Forces CQP mode when set, overriding everything else.)
|
||||||
int explicit_qp;
|
int explicit_qp;
|
||||||
|
|
@ -538,7 +541,11 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
|
||||||
VAAPI_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
|
VAAPI_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
|
||||||
VAAPI_ENCODE_RC_MODE(ICQ, "Intelligent constant-quality"), \
|
VAAPI_ENCODE_RC_MODE(ICQ, "Intelligent constant-quality"), \
|
||||||
VAAPI_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate"), \
|
VAAPI_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate"), \
|
||||||
VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate")
|
VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate"), \
|
||||||
|
{ "blbrc", \
|
||||||
|
"Block level based bitrate control",\
|
||||||
|
OFFSET(common.blbrc), AV_OPT_TYPE_BOOL, \
|
||||||
|
{ .i64 = 0 }, 0, 1, FLAGS }
|
||||||
|
|
||||||
|
|
||||||
#endif /* AVCODEC_VAAPI_ENCODE_H */
|
#endif /* AVCODEC_VAAPI_ENCODE_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue