[FFmpeg-devel] [PATCH] lavc/vaapi_encode: add "quality" option to all encoders
Xiang, Haihao
haihao.xiang at intel.com
Mon Jun 12 09:08:43 EEST 2023
> Move "quality" option from h264_vaapi to common options.
User may directly use compression_level option in vaapi path, the h.264 specific
quality option stays for compatibility only. (If I remember correctly, there
was a proposal to deprecate the h.264 specific option).
Thanks
Haihao
> ---
> libavcodec/vaapi_encode.c | 3 +++
> libavcodec/vaapi_encode.h | 8 +++++++-
> libavcodec/vaapi_encode_h264.c | 5 -----
> 3 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index bfca315a7a..974b805df1 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -2635,6 +2635,9 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
> if (err < 0)
> goto fail;
>
> + if (avctx->compression_level == FF_COMPRESSION_DEFAULT)
> + avctx->compression_level = ctx->quality;
> +
> if (avctx->compression_level >= 0) {
> err = vaapi_encode_init_quality(avctx);
> if (err < 0)
> diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
> index a1e639f56b..3e4a8c24d3 100644
> --- a/libavcodec/vaapi_encode.h
> +++ b/libavcodec/vaapi_encode.h
> @@ -364,6 +364,8 @@ typedef struct VAAPIEncodeContext {
> AVFifo *encode_fifo;
> // Max number of frame buffered in encoder.
> int async_depth;
> + // Encode quality (trades off against speed, higher is faster)
> + int quality;
> } VAAPIEncodeContext;
>
> enum {
> @@ -490,7 +492,11 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
> { "max_frame_size", \
> "Maximum frame size (in bytes)",\
> OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
> - { .i64 = 0 }, 0, INT_MAX, FLAGS }
> + { .i64 = 0 }, 0, INT_MAX, FLAGS }, \
> + { "quality", \
> + "Set encode quality (trades off against speed, higher is faster)", \
> + OFFSET(common.quality), AV_OPT_TYPE_INT, \
> + { .i64 = -1 }, -1, INT_MAX, FLAGS }
>
> #define VAAPI_ENCODE_RC_MODE(name, desc) \
> { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
> diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
> index 9ad017d540..c9629c1fea 100644
> --- a/libavcodec/vaapi_encode_h264.c
> +++ b/libavcodec/vaapi_encode_h264.c
> @@ -71,7 +71,6 @@ typedef struct VAAPIEncodeH264Context {
>
> // User options.
> int qp;
> - int quality;
> int coder;
> int aud;
> int sei;
> @@ -1211,8 +1210,6 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext
> *avctx)
> avctx->profile = priv->profile;
> if (avctx->level == FF_LEVEL_UNKNOWN)
> avctx->level = priv->level;
> - if (avctx->compression_level == FF_COMPRESSION_DEFAULT)
> - avctx->compression_level = priv->quality;
>
> // Reject unsupported profiles.
> switch (avctx->profile) {
> @@ -1282,8 +1279,6 @@ static const AVOption vaapi_encode_h264_options[] = {
>
> { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
> OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
> - { "quality", "Set encode quality (trades off against speed, higher is
> faster)",
> - OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
> { "coder", "Entropy coder type",
> OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, "coder" },
> { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN,
> INT_MAX, FLAGS, "coder" },
More information about the ffmpeg-devel
mailing list