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] lavc/qsvenc: update the selection of bitrate control method
Date: Tue, 27 Feb 2024 06:02:49 +0000
Message-ID: <ecdb8ea67611f22503ae6b1d91ffa69a36baedf6.camel@intel.com> (raw)
In-Reply-To: <20240208073936.1246837-1-haihao.xiang@intel.com>

On Do, 2024-02-08 at 15:39 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang <haihao.xiang@intel.com>
> 
> The default method is changed to CQP
> 
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
>  Changelog                 |  1 +
>  doc/encoders.texi         |  7 +++--
>  libavcodec/qsvenc.c       | 59 +++++++++++++++++++++++++++------------
>  libavcodec/qsvenc_av1.c   |  2 +-
>  libavcodec/qsvenc_h264.c  |  2 +-
>  libavcodec/qsvenc_hevc.c  |  2 +-
>  libavcodec/qsvenc_mpeg2.c |  2 +-
>  libavcodec/qsvenc_vp9.c   |  2 +-
>  8 files changed, 52 insertions(+), 25 deletions(-)
> 
> diff --git a/Changelog b/Changelog
> index c5fb21d198..b9e4536233 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -24,6 +24,7 @@ version <next>:
>  - ffmpeg CLI options may now be used as -/opt <path>, which is equivalent
>    to -opt <contents of file <path>>
>  - showinfo bitstream filter
> +- Change the default bitrate control method from VBR to CQP for QSV encoders.
>  
>  version 6.1:
>  - libaribcaption decoder
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index c9fe6d6143..d1363c2174 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3332,8 +3332,8 @@ quality range is 1 to 51, with 1 being the best quality.
>  @end itemize
>  
>  @item
> -Otherwise, a bitrate-based mode is used. For all of those, you should specify
> at
> -least the desired average bitrate with the @option{b} option.
> +Otherwise when the desired average bitrate is specified with the @option{b}
> +option, a bitrate-based mode is used.
>  @itemize @minus
>  @item
>  @var{LA} - VBR with lookahead, when the @option{look_ahead} option is
> specified.
> @@ -3354,6 +3354,9 @@ than the average bitrate.
>  @option{avbr_accuracy} and @option{avbr_convergence} are set to non-zero.
> This
>  mode is available for H264 and HEVC on Windows.
>  @end itemize
> +
> +@item
> +Otherwise the default ratecontrol method @var{CQP} is used.
>  @end itemize
>  
>  Note that depending on your system, a different mode than the one you
> specified
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index c63b72e384..8c6414f8ca 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -597,6 +597,12 @@ static int select_rc_mode(AVCodecContext *avctx,
> QSVEncContext *q)
>      else if (want_vcm) {
>          rc_mode = MFX_RATECONTROL_VCM;
>          rc_desc = "video conferencing mode (VCM)";
> +
> +        if (!avctx->bit_rate) {
> +            av_log(avctx, AV_LOG_ERROR, "Using the %s ratecontrol method.
> Please "
> +                   "use the b option to set the desired bitrate.\n",
> rc_desc);
> +            return AVERROR(EINVAL);
> +        }
>      }
>  #endif
>      else if (want_la) {
> @@ -606,32 +612,49 @@ static int select_rc_mode(AVCodecContext *avctx,
> QSVEncContext *q)
>          if (avctx->global_quality > 0) {
>              rc_mode = MFX_RATECONTROL_LA_ICQ;
>              rc_desc = "intelligent constant quality with lookahead (LA_ICQ)";
> +        } else if (!avctx->bit_rate) {
> +            av_log(avctx, AV_LOG_ERROR, "Using the %s ratecontrol method.
> Please "
> +                   "use the b option to set the desired bitrate.\n",
> rc_desc);
> +            return AVERROR(EINVAL);
>          }
>      }
>      else if (avctx->global_quality > 0 && !avctx->rc_max_rate) {
>          rc_mode = MFX_RATECONTROL_ICQ;
>          rc_desc = "intelligent constant quality (ICQ)";
>      }
> -    else if (avctx->rc_max_rate == avctx->bit_rate) {
> -        rc_mode = MFX_RATECONTROL_CBR;
> -        rc_desc = "constant bitrate (CBR)";
> -    }
> +    else if (avctx->bit_rate) {
> +        if (avctx->rc_max_rate == avctx->bit_rate) {
> +            rc_mode = MFX_RATECONTROL_CBR;
> +            rc_desc = "constant bitrate (CBR)";
> +        }
>  #if QSV_HAVE_AVBR
> -    else if (!avctx->rc_max_rate &&
> -             (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id ==
> AV_CODEC_ID_HEVC) &&
> -             q->avbr_accuracy &&
> -             q->avbr_convergence) {
> -        rc_mode = MFX_RATECONTROL_AVBR;
> -        rc_desc = "average variable bitrate (AVBR)";
> -    }
> +        else if (!avctx->rc_max_rate &&
> +                 (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id ==
> AV_CODEC_ID_HEVC) &&
> +                 q->avbr_accuracy &&
> +                 q->avbr_convergence) {
> +            rc_mode = MFX_RATECONTROL_AVBR;
> +            rc_desc = "average variable bitrate (AVBR)";
> +        }
>  #endif
> -    else if (avctx->global_quality > 0) {
> -        rc_mode = MFX_RATECONTROL_QVBR;
> -        rc_desc = "constant quality with VBR algorithm (QVBR)";
> -    }
> -    else {
> -        rc_mode = MFX_RATECONTROL_VBR;
> -        rc_desc = "variable bitrate (VBR)";
> +        else if (avctx->global_quality > 0) {
> +            rc_mode = MFX_RATECONTROL_QVBR;
> +            rc_desc = "constant quality with VBR algorithm (QVBR)";
> +        } else {
> +            rc_mode = MFX_RATECONTROL_VBR;
> +            rc_desc = "variable bitrate (VBR)";
> +        }
> +    } else {
> +        rc_mode = MFX_RATECONTROL_CQP;
> +        rc_desc = "constant quantization parameter (CQP)";
> +        if (avctx->codec_id == AV_CODEC_ID_AV1)
> +            avctx->global_quality = FF_QP2LAMBDA * 128;
> +        else
> +            avctx->global_quality = FF_QP2LAMBDA * 26;
> +        av_log(avctx, AV_LOG_WARNING, "Using the constant quantization "
> +               "parameter (CQP) by default. Please use the global_quality "
> +               "option and other options for a quality-based mode or the b "
> +               "option and other options for a bitrate-based mode if the "
> +               "default is not the desired choice.\n");
>      }
>  
>      q->param.mfx.RateControlMethod = rc_mode;
> diff --git a/libavcodec/qsvenc_av1.c b/libavcodec/qsvenc_av1.c
> index c697845d7b..c298eeb61c 100644
> --- a/libavcodec/qsvenc_av1.c
> +++ b/libavcodec/qsvenc_av1.c
> @@ -129,7 +129,7 @@ static const AVClass class = {
>  };
>  
>  static const FFCodecDefault qsv_enc_defaults[] = {
> -    { "b",         "1M"   },
> +    { "b",         "0"    },
>      { "g",         "-1"   },
>      { "bf",        "-1"   },
>      { "refs",      "0"    },
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> index 071a9a79e9..004ed8076a 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -178,7 +178,7 @@ static const AVClass class = {
>  };
>  
>  static const FFCodecDefault qsv_enc_defaults[] = {
> -    { "b",         "1M"    },
> +    { "b",         "0"     },
>      { "refs",      "0"     },
>      { "g",         "-1"    },
>      { "bf",        "-1"    },
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index c5b7ac7cc4..c94855e99a 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -374,7 +374,7 @@ static const AVClass class = {
>  };
>  
>  static const FFCodecDefault qsv_enc_defaults[] = {
> -    { "b",         "1M"    },
> +    { "b",         "0"     },
>      { "refs",      "0"     },
>      { "g",         "248"   },
>      { "bf",        "-1"    },
> diff --git a/libavcodec/qsvenc_mpeg2.c b/libavcodec/qsvenc_mpeg2.c
> index 22f1ff7c0d..c2fb6fd8ff 100644
> --- a/libavcodec/qsvenc_mpeg2.c
> +++ b/libavcodec/qsvenc_mpeg2.c
> @@ -82,7 +82,7 @@ static const AVClass class = {
>  };
>  
>  static const FFCodecDefault qsv_enc_defaults[] = {
> -    { "b",         "1M"    },
> +    { "b",         "0"     },
>      { "refs",      "0"     },
>      // same as the x264 default
>      { "g",         "250"   },
> diff --git a/libavcodec/qsvenc_vp9.c b/libavcodec/qsvenc_vp9.c
> index d0340ef94b..8d26ec529c 100644
> --- a/libavcodec/qsvenc_vp9.c
> +++ b/libavcodec/qsvenc_vp9.c
> @@ -93,7 +93,7 @@ static const AVClass class = {
>  };
>  
>  static const FFCodecDefault qsv_enc_defaults[] = {
> -    { "b",         "1M"    },
> +    { "b",         "0"     },
>      { "refs",      "0"     },
>      { "g",         "250"   },
>      { "trellis",   "-1"    },

Will apply, 

- 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:[~2024-02-27  6:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08  7:39 Xiang, Haihao
2024-02-27  6:02 ` 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=ecdb8ea67611f22503ae6b1d91ffa69a36baedf6.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