From: "Xiang, Haihao" <haihao.xiang-at-intel.com@ffmpeg.org>
To: "ffmpeg-devel@ffmpeg.org" <ffmpeg-devel@ffmpeg.org>
Cc: "Wang, Fei W" <fei.w.wang@intel.com>
Subject: Re: [FFmpeg-devel] [PATCH v3] lavc/vaapi_encode: Enable block level bitrate control
Date: Fri, 15 Mar 2024 02:46:06 +0000
Message-ID: <197fd297b7236438ab3d008c12e75a902be01559.camel@intel.com> (raw)
In-Reply-To: <20240308084529.70683-1-fei.w.wang@intel.com>
On Vr, 2024-03-08 at 16:45 +0800, fei.w.wang-at-intel.com@ffmpeg.org wrote:
> From: Fei Wang <fei.w.wang@intel.com>
>
> Signed-off-by: Fei Wang <fei.w.wang@intel.com>
> ---
> doc/encoders.texi | 4 ++++
> libavcodec/vaapi_encode.c | 13 ++++++++++++-
> libavcodec/vaapi_encode.h | 9 ++++++++-
> 3 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 5f7864770e..7c223ed74c 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -4089,6 +4089,10 @@ Quality-defined variable-bitrate.
> Average variable bitrate.
> @end table
>
> +@item blbrc
> +Enable block level rate control, which assigns different bitrate block by
> block.
> +Invalid for CQP mode.
> +
> @end table
>
> Each encoder also has its own specific options:
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 808b79c0c7..940f0678a5 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -1805,6 +1805,11 @@ static av_cold int
> vaapi_encode_init_rate_control(AVCodecContext *avctx)
> int i, first = 1, res;
>
> supported_va_rc_modes = rc_attr.value;
> + if (ctx->blbrc && !(supported_va_rc_modes & VA_RC_MB)) {
> + ctx->blbrc = 0;
> + av_log(avctx, AV_LOG_WARNING, "Driver does not support
> BLBRC.\n");
> + }
> +
> for (i = 0; i < FF_ARRAY_ELEMS(vaapi_encode_rc_modes); i++) {
> rc_mode = &vaapi_encode_rc_modes[i];
> if (supported_va_rc_modes & rc_mode->va_mode) {
> @@ -2016,13 +2021,18 @@ rc_mode_found:
> ctx->va_bit_rate = rc_bits_per_second;
>
> av_log(avctx, AV_LOG_VERBOSE, "RC mode: %s.\n", rc_mode->name);
> +
> + if (ctx->blbrc && ctx->va_rc_mode == VA_RC_CQP)
> + ctx->blbrc = 0;
> + av_log(avctx, AV_LOG_VERBOSE, "Block Level bitrate control: %s.\n", ctx-
> >blbrc ? "ON" : "OFF");
> +
> if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
> // This driver does not want the RC mode attribute to be set.
> } else {
> ctx->config_attributes[ctx->nb_config_attributes++] =
> (VAConfigAttrib) {
> .type = VAConfigAttribRateControl,
> - .value = ctx->va_rc_mode,
> + .value = ctx->blbrc ? ctx->va_rc_mode | VA_RC_MB : ctx-
> >va_rc_mode,
> };
> }
>
> @@ -2051,6 +2061,7 @@ rc_mode_found:
> #if VA_CHECK_VERSION(1, 1, 0)
> .ICQ_quality_factor = av_clip(rc_quality, 1, 51),
> .max_qp = (avctx->qmax > 0 ? avctx->qmax : 0),
> + .rc_flags.bits.mb_rate_control = ctx->blbrc ? 1 : 2,
> #endif
> #if VA_CHECK_VERSION(1, 3, 0)
> .quality_factor = rc_quality,
> diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
> index 6964055b93..0eed9691ca 100644
> --- a/libavcodec/vaapi_encode.h
> +++ b/libavcodec/vaapi_encode.h
> @@ -216,6 +216,9 @@ typedef struct VAAPIEncodeContext {
> // available modes).
> int explicit_rc_mode;
>
> + // Block Level based bitrate control.
> + int blbrc;
> +
> // Explicitly-set QP, for use with the "qp" options.
> // (Forces CQP mode when set, overriding everything else.)
> int explicit_qp;
> @@ -538,7 +541,11 @@ int ff_vaapi_encode_close(AVCodecContext *avctx);
> VAAPI_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \
> VAAPI_ENCODE_RC_MODE(ICQ, "Intelligent constant-quality"), \
> VAAPI_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate"), \
> - VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate")
> + VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate"), \
> + { "blbrc", \
> + "Block level based bitrate control",\
> + OFFSET(common.blbrc), AV_OPT_TYPE_BOOL, \
> + { .i64 = 0 }, 0, 1, FLAGS }
>
>
> #endif /* AVCODEC_VAAPI_ENCODE_H */
LGTM, I will push this patch if there is no objection.
Thanks
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".
next prev parent reply other threads:[~2024-03-15 2:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 8:45 fei.w.wang-at-intel.com
2024-03-15 2:46 ` Xiang, Haihao [this message]
2024-03-18 6:05 ` Xiang, Haihao
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=197fd297b7236438ab3d008c12e75a902be01559.camel@intel.com \
--to=haihao.xiang-at-intel.com@ffmpeg.org \
--cc=fei.w.wang@intel.com \
--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