Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Xiang, Haihao" <haihao.xiang-at-intel.com@ffmpeg.org>
To: "ffmpeg-devel@ffmpeg.org" <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v2] libavcodec/qsvenc: Add min/max QP control options for I/P/B frame
Date: Wed, 1 Jun 2022 16:09:21 +0000
Message-ID: <e746431b9cfcf08eca112781b9a67ae0cc286996.camel@intel.com> (raw)
In-Reply-To: <20220525131341.3203743-1-wenbin.chen@intel.com>

On Wed, 2022-05-25 at 21:13 +0800, Wenbin Chen wrote:
> From: Yue Heng <yue.heng@intel.com>
> 
> To do more accurate QP control, add min/max QP control on I/P/B frame
> separately to qsv encoder. qmax and qmin still work but newly-added
> options have higher priority.
> 
> Signed-off-by: Yue Heng <yue.heng@intel.com>
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  doc/encoders.texi        | 36 ++++++++++++++++++++++++++++++++++++
>  libavcodec/qsvenc.c      | 21 +++++++++++++++++++--
>  libavcodec/qsvenc.h      | 15 +++++++++++++++
>  libavcodec/qsvenc_h264.c |  1 +
>  libavcodec/qsvenc_hevc.c |  1 +
>  5 files changed, 72 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 9796a606fa..e9df36de8f 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3472,6 +3472,24 @@ Multi-Frame Mode.
>  
>  @item @var{repeat_pps}
>  Repeat pps for every frame.
> +
> +@item @var{max_qp_i}
> +Maximum video quantizer scale for I frame.
> +
> +@item @var{min_qp_i}
> +Minimum video quantizer scale for I frame.
> +
> +@item @var{max_qp_p}
> +Maximum video quantizer scale for P frame.
> +
> +@item @var{min_qp_p}
> +Minimum video quantizer scale for P frame.
> +
> +@item @var{max_qp_b}
> +Maximum video quantizer scale for B frame.
> +
> +@item @var{min_qp_b}
> +Minimum video quantizer scale for B frame.
>  @end table
>  
>  @subsection HEVC Options
> @@ -3595,6 +3613,24 @@ range is [-63, 63] for 10 bit-depth or [-75, 75] for 12
> bit-depth respectively.
>  
>  @item @var{int_ref_cycle_dist}
>  Distance between the beginnings of the intra-refresh cycles in frames.
> +
> +@item @var{max_qp_i}
> +Maximum video quantizer scale for I frame.
> +
> +@item @var{min_qp_i}
> +Minimum video quantizer scale for I frame.
> +
> +@item @var{max_qp_p}
> +Maximum video quantizer scale for P frame.
> +
> +@item @var{min_qp_p}
> +Minimum video quantizer scale for P frame.
> +
> +@item @var{max_qp_b}
> +Maximum video quantizer scale for B frame.
> +
> +@item @var{min_qp_b}
> +Minimum video quantizer scale for B frame.
>  @end table
>  
>  @subsection MPEG2 Options
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 2b3b06767d..03e9e5523d 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -828,8 +828,13 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  
>              if (q->b_strategy >= 0)
>                  q->extco2.BRefType = q->b_strategy ? MFX_B_REF_PYRAMID :
> MFX_B_REF_OFF;
> -            if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx-
> >qmax) {
> -                av_log(avctx, AV_LOG_ERROR, "qmin and or qmax are set but
> invalid, please make sure min <= max\n");
> +            if ((avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx-
> >qmax) ||
> +                (q->max_qp_i >= 0 && q->min_qp_i >= 0 && q->min_qp_i > q-
> >max_qp_i) ||
> +                (q->max_qp_p >= 0 && q->min_qp_p >= 0 && q->min_qp_p > q-
> >max_qp_p) ||
> +                (q->max_qp_b >= 0 && q->min_qp_b >= 0 && q->min_qp_b > q-
> >max_qp_b)) {
> +                av_log(avctx, AV_LOG_ERROR,
> +                       "qmin and or qmax are set but invalid,"
> +                       " please make sure min <= max\n");
>                  return AVERROR(EINVAL);
>              }
>              if (avctx->qmin >= 0) {
> @@ -840,6 +845,18 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>                  q->extco2.MaxQPI = avctx->qmax > 51 ? 51 : avctx->qmax;
>                  q->extco2.MaxQPP = q->extco2.MaxQPB = q->extco2.MaxQPI;
>              }
> +            if (q->min_qp_i >= 0)
> +                q->extco2.MinQPI = q->min_qp_i > 51 ? 51 : q->min_qp_i;
> +            if (q->max_qp_i >= 0)
> +                q->extco2.MaxQPI = q->max_qp_i > 51 ? 51 : q->max_qp_i;
> +            if (q->min_qp_p >= 0)
> +                q->extco2.MinQPP = q->min_qp_p > 51 ? 51 : q->min_qp_p;
> +            if (q->max_qp_p >= 0)
> +                q->extco2.MaxQPP = q->max_qp_p > 51 ? 51 : q->max_qp_p;
> +            if (q->min_qp_b >= 0)
> +                q->extco2.MinQPB = q->min_qp_b > 51 ? 51 : q->min_qp_b;
> +            if (q->max_qp_b >= 0)
> +                q->extco2.MaxQPB = q->max_qp_b > 51 ? 51 : q->max_qp_b;
>              if (q->mbbrc >= 0)
>                  q->extco2.MBBRC = q->mbbrc ? MFX_CODINGOPTION_ON :
> MFX_CODINGOPTION_OFF;
>  
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index fec5e584db..b754ac4b56 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -100,6 +100,14 @@
>  #define QSV_OPTION_LOW_DELAY_BRC \
>  { "low_delay_brc",   "Allow to strictly obey avg frame size",
> OFFSET(qsv.low_delay_brc),  AV_OPT_TYPE_BOOL,{ .i64 = -1 }, -1,          1, VE
> },
>  
> +#define QSV_OPTION_MAX_MIN_QP \
> +{ "max_qp_i", "Maximum video quantizer scale for I
> frame",       OFFSET(qsv.max_qp_i),       AV_OPT_TYPE_INT, { .i64 = -1 },  -
> 1,          51, VE},                         \
> +{ "min_qp_i", "Minimum video quantizer scale for I
> frame",       OFFSET(qsv.min_qp_i),       AV_OPT_TYPE_INT, { .i64 = -1 },  -
> 1,          51, VE},                         \
> +{ "max_qp_p", "Maximum video quantizer scale for P
> frame",       OFFSET(qsv.max_qp_p),       AV_OPT_TYPE_INT, { .i64 = -1 },  -
> 1,          51, VE},                         \
> +{ "min_qp_p", "Minimum video quantizer scale for P
> frame",       OFFSET(qsv.min_qp_p),       AV_OPT_TYPE_INT, { .i64 = -1 },  -
> 1,          51, VE},                         \
> +{ "max_qp_b", "Maximum video quantizer scale for B
> frame",       OFFSET(qsv.max_qp_b),       AV_OPT_TYPE_INT, { .i64 = -1 },  -
> 1,          51, VE},                         \
> +{ "min_qp_b", "Minimum video quantizer scale for B
> frame",       OFFSET(qsv.min_qp_b),       AV_OPT_TYPE_INT, { .i64 = -1 },  -
> 1,          51, VE},
> +
>  extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
>  
>  typedef int SetEncodeCtrlCB (AVCodecContext *avctx,
> @@ -209,6 +217,13 @@ typedef struct QSVEncContext {
>      int co3_idx;
>      int exthevctiles_idx;
>      int vp9_idx;
> +
> +    int max_qp_i;
> +    int min_qp_i;
> +    int max_qp_p;
> +    int min_qp_p;
> +    int max_qp_b;
> +    int min_qp_b;
>  } QSVEncContext;
>  
>  int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> index cf77ea575b..87b09360cb 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -114,6 +114,7 @@ static const AVOption options[] = {
>      QSV_OPTION_B_STRATEGY
>      QSV_OPTION_DBLK_IDC
>      QSV_OPTION_LOW_DELAY_BRC
> +    QSV_OPTION_MAX_MIN_QP
>  
>      { "cavlc",          "Enable
> CAVLC",                           OFFSET(qsv.cavlc),          AV_OPT_TYPE_BOOL
> , { .i64 = 0 },   0,          1, VE },
>  #if QSV_HAVE_VCM
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index a6bf39c148..da2bf457af 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -233,6 +233,7 @@ static const AVOption options[] = {
>      QSV_OPTION_B_STRATEGY
>      QSV_OPTION_DBLK_IDC
>      QSV_OPTION_LOW_DELAY_BRC
> +    QSV_OPTION_MAX_MIN_QP
>  
>      { "idr_interval", "Distance (in I-frames) between IDR frames",
> OFFSET(qsv.idr_interval), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT_MAX, VE,
> "idr_interval" },
>      { "begin_only", "Output an IDR-frame only at the beginning of the
> stream", 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0, VE, "idr_interval" },

LGTM, will aplly.

-Haihao

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

      reply	other threads:[~2022-06-01 16:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25 13:13 Wenbin Chen
2022-06-01 16:09 ` Xiang, Haihao [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e746431b9cfcf08eca112781b9a67ae0cc286996.camel@intel.com \
    --to=haihao.xiang-at-intel.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git