[FFmpeg-devel] [PATCH v1] lavc/vaapi_encode_av1: Add qp option explicitly to set base q index

Wang, Fei W fei.w.wang at intel.com
Tue Dec 19 08:18:25 EET 2023


On Tue, 2023-11-28 at 03:15 +0000, Xiang, Haihao wrote:
> On Ma, 2023-11-27 at 13:36 +0000, Mark Thompson wrote:
> > On 27/11/2023 00:58, fei.w.wang-at-intel.com at ffmpeg.org wrote:
> > > From: Fei Wang <fei.w.wang at intel.com>
> > > 
> > > Keep same way with librav1e/libsvtav1/qsv_av1.. to make it more
> > > acceptable instead of using global option "-global_quality".
> > > 
> > > Fix #10615
> > > 
> > > Signed-off-by: Fei Wang <fei.w.wang at intel.com>
> > > ---
> > >   doc/encoders.texi             | 1 +
> > >   libavcodec/vaapi_encode_av1.c | 6 ++++++
> > >   2 files changed, 7 insertions(+)
> > > 
> > > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > > index 27a9acf076..2cffc32daf 100644
> > > --- a/doc/encoders.texi
> > > +++ b/doc/encoders.texi
> > > @@ -4079,6 +4079,7 @@ Each encoder also has its own specific
> > > options:
> > >   @table @option
> > >   
> > >   @item av1_vaapi
> > > + at option{qp} sets the value of @emph{base_q_index}.
> > >   @option{profile} sets the value of @emph{seq_profile}.
> > >   @option{tier} sets the value of @emph{seq_tier}.
> > >   @option{level} sets the value of @emph{seq_level_idx}.
> > > diff --git a/libavcodec/vaapi_encode_av1.c
> > > b/libavcodec/vaapi_encode_av1.c
> > > index 5a9ff0f798..2e327fec5a 100644
> > > --- a/libavcodec/vaapi_encode_av1.c
> > > +++ b/libavcodec/vaapi_encode_av1.c
> > > @@ -79,6 +79,7 @@ typedef struct VAAPIEncodeAV1Context {
> > >       int cdef_param_size;
> > >   
> > >       /** user options */
> > > +    int qp;
> > >       int profile;
> > >       int level;
> > >       int tier;
> > > @@ -786,6 +787,9 @@ static av_cold int
> > > vaapi_encode_av1_init(AVCodecContext
> > > *avctx)
> > >           return AVERROR(EINVAL);
> > >       }
> > >   
> > > +    if (priv->qp > 0)
> > > +        ctx->explicit_qp = priv->qp;
> > > +
> > >       ret = ff_vaapi_encode_init(avctx);
> > >       if (ret < 0)
> > >           return ret;
> > > @@ -864,6 +868,8 @@ static av_cold int
> > > vaapi_encode_av1_close(AVCodecContext
> > > *avctx)
> > >   static const AVOption vaapi_encode_av1_options[] = {
> > >       VAAPI_ENCODE_COMMON_OPTIONS,
> > >       VAAPI_ENCODE_RC_OPTIONS,
> > > +    { "qp", "Base q index (for P-frames; scaled by
> > > qfactor/qoffset for
> > > I/B)",
> > > +      OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 255, FLAGS
> > > },
> > >       { "profile", "Set profile (seq_profile)",
> > >         OFFSET(profile), AV_OPT_TYPE_INT,
> > >         { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff,
> > > FLAGS,
> > > "profile" },
> > 
> > Disagree; QP is not a concept in AV1. 
> 
> Yes, it not a concept in AV1.
> 
> nvenc h264/hevc/av1 encoders provide the same qp option:
> 
> libavcodec/nvenc_av1.c:    { "qp",           "Constant quantization
> parameter
> rate control method",
> libavcodec/nvenc_h264.c:    { "qp",           "Constant quantization
> parameter
> rate control method",
> libavcodec/nvenc_hevc.c:    { "qp",           "Constant quantization
> parameter
> rate control method",
> 
> May we provide the same qp option for vaapi h264/hevc/av1 encoders
> too? User
> will be able to use same options when using these encoders.
> 
> Thanks
> Haihao
> 
> 
> >  Further, your examples from other encoders do not have a
> > consistent view of
> > what it should mean.

We may also assign different meaning for different VAAPI encoder in its
individual option description. And it may be more reasonable to use
"-qp" together with "-rc_mode CQP" and "-i/b_qfactor/qoffset" options.

Thanks
Fei


> > 
> > librav1e.c:
> > 
> >      { "qp", "use constant quantizer mode", OFFSET(quantizer),
> > AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, VE },
> > 
> > 0-255 is presumably the base_q_idx scale.
> > 
> > libsvtav1.c:
> > 
> >      { "qp", "Initial Quantizer level value", OFFSET(qp),     
> > AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE },
> > 
> > 0-63 is presumably the H.26x-qp-ish scale used by some VP9/AV1
> > encoders which
> > maps nonlinearly to the internal scale.
> > 
> > qsv_av1 doesn't seem to have such an option.
> > 
> > Thanks,
> > 
> > - Mark
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list