vaapi_encode_h265: Enable support for more RC modes
Also fixes QP going out of range when modified by the quant factor/offset values, and clarifies the QP behaviour for >8-bit modes.
This commit is contained in:
parent
f5eb08937e
commit
d237b6b549
@ -1073,15 +1073,21 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (ctx->va_rc_mode == VA_RC_CQP) {
|
if (ctx->va_rc_mode == VA_RC_CQP) {
|
||||||
priv->fixed_qp_p = priv->qp;
|
// Note that VAAPI only supports positive QP values - the range is
|
||||||
|
// therefore always bounded below by 1, even in 10-bit mode where
|
||||||
|
// it should go down to -12.
|
||||||
|
|
||||||
|
priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
|
||||||
if (avctx->i_quant_factor > 0.0)
|
if (avctx->i_quant_factor > 0.0)
|
||||||
priv->fixed_qp_idr = (int)((priv->fixed_qp_p * avctx->i_quant_factor +
|
priv->fixed_qp_idr =
|
||||||
avctx->i_quant_offset) + 0.5);
|
av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
|
||||||
|
avctx->i_quant_offset) + 0.5, 1, 51);
|
||||||
else
|
else
|
||||||
priv->fixed_qp_idr = priv->fixed_qp_p;
|
priv->fixed_qp_idr = priv->fixed_qp_p;
|
||||||
if (avctx->b_quant_factor > 0.0)
|
if (avctx->b_quant_factor > 0.0)
|
||||||
priv->fixed_qp_b = (int)((priv->fixed_qp_p * avctx->b_quant_factor +
|
priv->fixed_qp_b =
|
||||||
avctx->b_quant_offset) + 0.5);
|
av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
|
||||||
|
avctx->b_quant_offset) + 0.5, 1, 51);
|
||||||
else
|
else
|
||||||
priv->fixed_qp_b = priv->fixed_qp_p;
|
priv->fixed_qp_b = priv->fixed_qp_p;
|
||||||
|
|
||||||
@ -1089,15 +1095,11 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
|
|||||||
"%d / %d / %d for IDR- / P- / B-frames.\n",
|
"%d / %d / %d for IDR- / P- / B-frames.\n",
|
||||||
priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
|
priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
|
||||||
|
|
||||||
} else if (ctx->va_rc_mode == VA_RC_CBR ||
|
} else {
|
||||||
ctx->va_rc_mode == VA_RC_VBR) {
|
// These still need to be set for init_qp/slice_qp_delta.
|
||||||
// These still need to be set for pic_init_qp/slice_qp_delta.
|
|
||||||
priv->fixed_qp_idr = 30;
|
priv->fixed_qp_idr = 30;
|
||||||
priv->fixed_qp_p = 30;
|
priv->fixed_qp_p = 30;
|
||||||
priv->fixed_qp_b = 30;
|
priv->fixed_qp_b = 30;
|
||||||
|
|
||||||
} else {
|
|
||||||
av_assert0(0 && "Invalid RC mode.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1121,6 +1123,8 @@ static const VAAPIEncodeType vaapi_encode_type_h265 = {
|
|||||||
FLAG_B_PICTURE_REFERENCES |
|
FLAG_B_PICTURE_REFERENCES |
|
||||||
FLAG_NON_IDR_KEY_PICTURES,
|
FLAG_NON_IDR_KEY_PICTURES,
|
||||||
|
|
||||||
|
.default_quality = 25,
|
||||||
|
|
||||||
.configure = &vaapi_encode_h265_configure,
|
.configure = &vaapi_encode_h265_configure,
|
||||||
|
|
||||||
.picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
|
.picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
|
||||||
@ -1172,6 +1176,9 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
|
|||||||
// CTU size is currently hard-coded to 32.
|
// CTU size is currently hard-coded to 32.
|
||||||
ctx->slice_block_width = ctx->slice_block_height = 32;
|
ctx->slice_block_width = ctx->slice_block_height = 32;
|
||||||
|
|
||||||
|
if (priv->qp > 0)
|
||||||
|
ctx->explicit_qp = priv->qp;
|
||||||
|
|
||||||
return ff_vaapi_encode_init(avctx);
|
return ff_vaapi_encode_init(avctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1189,9 +1196,10 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
|
|||||||
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
|
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
|
||||||
static const AVOption vaapi_encode_h265_options[] = {
|
static const AVOption vaapi_encode_h265_options[] = {
|
||||||
VAAPI_ENCODE_COMMON_OPTIONS,
|
VAAPI_ENCODE_COMMON_OPTIONS,
|
||||||
|
VAAPI_ENCODE_RC_OPTIONS,
|
||||||
|
|
||||||
{ "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
|
{ "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
|
||||||
OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
|
OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
|
||||||
|
|
||||||
{ "aud", "Include AUD",
|
{ "aud", "Include AUD",
|
||||||
OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
|
OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user