* [FFmpeg-devel] [PATCH] lavc/qsvenc: use VBR if maxrate is not specified on Windows
@ 2022-09-01 2:12 Xiang, Haihao
2022-09-05 2:48 ` Xiang, Haihao
0 siblings, 1 reply; 2+ messages in thread
From: Xiang, Haihao @ 2022-09-01 2:12 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Haihao Xiang
From: Haihao Xiang <haihao.xiang@intel.com>
Currently AVBR is disabled and VBR is the default method if maxrate is
not specified on Linux, but AVBR is the default one if maxrate is not
specified on Windows. In order to make user experience better accross
Linux and Windows, use VBR by default on Windows if maxrate is not
specified. User need to set both avbr_accuracy and avbr_convergence to
non-zero explicitly and not to specify maxrate if AVBR is expected.
In addition, AVBR works for H264 and HEVC only in the SDK.
$ ffmpeg.exe -v verbose -f lavfi -i yuvtestsrc -vf "format=nv12" -c:v
vp9_qsv -f null -
---
doc/encoders.texi | 45 ++++++++++++++++++++++++++--------------
libavcodec/qsvenc.c | 5 ++++-
libavcodec/qsvenc.h | 6 ++++--
libavcodec/qsvenc_h264.c | 1 +
libavcodec/qsvenc_hevc.c | 1 +
5 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index d36464d629..d2046e437d 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3244,9 +3244,9 @@ the average bitrate.
than the average bitrate.
@item
-@var{AVBR} - average VBR mode, when @option{maxrate} is not specified. This mode
-is further configured by the @option{avbr_accuracy} and
-@option{avbr_convergence} options.
+@var{AVBR} - average VBR mode, when @option{maxrate} is not specified, both
+@option{avbr_accuracy} and @option{avbr_convergence} are set to non-zero. This
+mode is available for H264 and HEVC on Windows.
@end itemize
@end itemize
@@ -3300,19 +3300,6 @@ Specifies how many asynchronous operations an application performs
before the application explicitly synchronizes the result. If zero,
the value is not specified.
-@item @var{avbr_accuracy}
-Accuracy of the AVBR ratecontrol (unit of tenth of percent).
-
-@item @var{avbr_convergence}
-Convergence of the AVBR ratecontrol (unit of 100 frames)
-
-The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the
-average variable bitrate control (AVBR) algorithm.
-The algorithm focuses on overall encoding quality while meeting the specified
-bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy},
-after a @var{avbr_Convergence} period. This method does not follow HRD and the
-instant bitrate is not capped or padded.
-
@item @var{preset}
This option itemizes a range of choices from veryfast (best speed) to veryslow
(best quality).
@@ -3518,6 +3505,19 @@ Provides a hint to encoder about the scenario for the encoding session.
@item remotegaming
@end table
+@item @var{avbr_accuracy}
+Accuracy of the AVBR ratecontrol (unit of tenth of percent).
+
+@item @var{avbr_convergence}
+Convergence of the AVBR ratecontrol (unit of 100 frames)
+
+The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the
+average variable bitrate control (AVBR) algorithm.
+The algorithm focuses on overall encoding quality while meeting the specified
+bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy},
+after a @var{avbr_Convergence} period. This method does not follow HRD and the
+instant bitrate is not capped or padded.
+
@end table
@subsection HEVC Options
@@ -3681,6 +3681,19 @@ Provides a hint to encoder about the scenario for the encoding session.
@item remotegaming
@end table
+@item @var{avbr_accuracy}
+Accuracy of the AVBR ratecontrol (unit of tenth of percent).
+
+@item @var{avbr_convergence}
+Convergence of the AVBR ratecontrol (unit of 100 frames)
+
+The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the
+average variable bitrate control (AVBR) algorithm.
+The algorithm focuses on overall encoding quality while meeting the specified
+bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy},
+after a @var{avbr_Convergence} period. This method does not follow HRD and the
+instant bitrate is not capped or padded.
+
@end table
@subsection MPEG2 Options
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 7ac5390f10..31ff3b76ed 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -479,7 +479,10 @@ static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q)
rc_desc = "constant bitrate (CBR)";
}
#if QSV_HAVE_AVBR
- else if (!avctx->rc_max_rate) {
+ 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)";
}
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index a983651dda..ff859f2a7e 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -52,8 +52,6 @@
#define QSV_COMMON_OPTS \
{ "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VE }, \
-{ "avbr_accuracy", "Accuracy of the AVBR ratecontrol (unit of tenth of percent)", OFFSET(qsv.avbr_accuracy), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, UINT16_MAX, VE }, \
-{ "avbr_convergence", "Convergence of the AVBR ratecontrol (unit of 100 frames)", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, UINT16_MAX, VE }, \
{ "preset", NULL, OFFSET(qsv.preset), AV_OPT_TYPE_INT, { .i64 = MFX_TARGETUSAGE_BALANCED }, MFX_TARGETUSAGE_BEST_QUALITY, MFX_TARGETUSAGE_BEST_SPEED, VE, "preset" }, \
{ "veryfast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BEST_SPEED }, INT_MIN, INT_MAX, VE, "preset" }, \
{ "faster", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_6 }, INT_MIN, INT_MAX, VE, "preset" }, \
@@ -124,6 +122,10 @@
{ "gamestreaming", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCENARIO_GAME_STREAMING }, .flags = VE, "scenario" }, \
{ "remotegaming", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCENARIO_REMOTE_GAMING }, .flags = VE, "scenario" },
+#define QSV_OPTION_AVBR \
+{ "avbr_accuracy", "Accuracy of the AVBR ratecontrol (unit of tenth of percent)", OFFSET(qsv.avbr_accuracy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE }, \
+{ "avbr_convergence", "Convergence of the AVBR ratecontrol (unit of 100 frames)", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE },
+
extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
typedef int SetEncodeCtrlCB (AVCodecContext *avctx,
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index a0dc31e24a..4b29ccac0f 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -115,6 +115,7 @@ static const AVOption options[] = {
QSV_OPTION_LOW_DELAY_BRC
QSV_OPTION_MAX_MIN_QP
QSV_OPTION_SCENARIO
+ QSV_OPTION_AVBR
{ "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 e59747fda3..29086337fb 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -236,6 +236,7 @@ static const AVOption options[] = {
QSV_OPTION_ADAPTIVE_I
QSV_OPTION_ADAPTIVE_B
QSV_OPTION_SCENARIO
+ QSV_OPTION_AVBR
{ "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" },
--
2.17.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: use VBR if maxrate is not specified on Windows
2022-09-01 2:12 [FFmpeg-devel] [PATCH] lavc/qsvenc: use VBR if maxrate is not specified on Windows Xiang, Haihao
@ 2022-09-05 2:48 ` Xiang, Haihao
0 siblings, 0 replies; 2+ messages in thread
From: Xiang, Haihao @ 2022-09-05 2:48 UTC (permalink / raw)
To: ffmpeg-devel
On Thu, 2022-09-01 at 10:12 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang <haihao.xiang@intel.com>
>
> Currently AVBR is disabled and VBR is the default method if maxrate is
> not specified on Linux, but AVBR is the default one if maxrate is not
> specified on Windows. In order to make user experience better accross
> Linux and Windows, use VBR by default on Windows if maxrate is not
> specified. User need to set both avbr_accuracy and avbr_convergence to
> non-zero explicitly and not to specify maxrate if AVBR is expected.
>
> In addition, AVBR works for H264 and HEVC only in the SDK.
>
> $ ffmpeg.exe -v verbose -f lavfi -i yuvtestsrc -vf "format=nv12" -c:v
> vp9_qsv -f null -
> ---
> doc/encoders.texi | 45 ++++++++++++++++++++++++++--------------
> libavcodec/qsvenc.c | 5 ++++-
> libavcodec/qsvenc.h | 6 ++++--
> libavcodec/qsvenc_h264.c | 1 +
> libavcodec/qsvenc_hevc.c | 1 +
> 5 files changed, 39 insertions(+), 19 deletions(-)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index d36464d629..d2046e437d 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -3244,9 +3244,9 @@ the average bitrate.
> than the average bitrate.
>
> @item
> -@var{AVBR} - average VBR mode, when @option{maxrate} is not specified. This
> mode
> -is further configured by the @option{avbr_accuracy} and
> -@option{avbr_convergence} options.
> +@var{AVBR} - average VBR mode, when @option{maxrate} is not specified, both
> +@option{avbr_accuracy} and @option{avbr_convergence} are set to non-zero.
> This
> +mode is available for H264 and HEVC on Windows.
> @end itemize
> @end itemize
>
> @@ -3300,19 +3300,6 @@ Specifies how many asynchronous operations an
> application performs
> before the application explicitly synchronizes the result. If zero,
> the value is not specified.
>
> -@item @var{avbr_accuracy}
> -Accuracy of the AVBR ratecontrol (unit of tenth of percent).
> -
> -@item @var{avbr_convergence}
> -Convergence of the AVBR ratecontrol (unit of 100 frames)
> -
> -The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the
> -average variable bitrate control (AVBR) algorithm.
> -The algorithm focuses on overall encoding quality while meeting the specified
> -bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy},
> -after a @var{avbr_Convergence} period. This method does not follow HRD and
> the
> -instant bitrate is not capped or padded.
> -
> @item @var{preset}
> This option itemizes a range of choices from veryfast (best speed) to
> veryslow
> (best quality).
> @@ -3518,6 +3505,19 @@ Provides a hint to encoder about the scenario for the
> encoding session.
> @item remotegaming
> @end table
>
> +@item @var{avbr_accuracy}
> +Accuracy of the AVBR ratecontrol (unit of tenth of percent).
> +
> +@item @var{avbr_convergence}
> +Convergence of the AVBR ratecontrol (unit of 100 frames)
> +
> +The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the
> +average variable bitrate control (AVBR) algorithm.
> +The algorithm focuses on overall encoding quality while meeting the specified
> +bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy},
> +after a @var{avbr_Convergence} period. This method does not follow HRD and
> the
> +instant bitrate is not capped or padded.
> +
> @end table
>
> @subsection HEVC Options
> @@ -3681,6 +3681,19 @@ Provides a hint to encoder about the scenario for the
> encoding session.
> @item remotegaming
> @end table
>
> +@item @var{avbr_accuracy}
> +Accuracy of the AVBR ratecontrol (unit of tenth of percent).
> +
> +@item @var{avbr_convergence}
> +Convergence of the AVBR ratecontrol (unit of 100 frames)
> +
> +The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the
> +average variable bitrate control (AVBR) algorithm.
> +The algorithm focuses on overall encoding quality while meeting the specified
> +bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy},
> +after a @var{avbr_Convergence} period. This method does not follow HRD and
> the
> +instant bitrate is not capped or padded.
> +
> @end table
>
> @subsection MPEG2 Options
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 7ac5390f10..31ff3b76ed 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -479,7 +479,10 @@ static int select_rc_mode(AVCodecContext *avctx,
> QSVEncContext *q)
> rc_desc = "constant bitrate (CBR)";
> }
> #if QSV_HAVE_AVBR
> - else if (!avctx->rc_max_rate) {
> + 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)";
> }
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index a983651dda..ff859f2a7e 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -52,8 +52,6 @@
>
> #define QSV_COMMON_OPTS \
> { "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth),
> AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VE
> }, \
> -{ "avbr_accuracy", "Accuracy of the AVBR ratecontrol (unit of tenth of
> percent)", OFFSET(qsv.avbr_accuracy), AV_OPT_TYPE_INT, { .i64 = 1 }, 1,
> UINT16_MAX, VE }, \
> -{ "avbr_convergence", "Convergence of the AVBR ratecontrol (unit of 100
> frames)", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 1 }, 1,
> UINT16_MAX, VE }, \
> { "preset", NULL, OFFSET(qsv.preset), AV_OPT_TYPE_INT, { .i64 =
> MFX_TARGETUSAGE_BALANCED }, MFX_TARGETUSAGE_BEST_QUALITY,
> MFX_TARGETUSAGE_BEST_SPEED, VE, "preset" }, \
> { "veryfast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> MFX_TARGETUSAGE_BEST_SPEED }, INT_MIN, INT_MAX, VE, "preset"
> }, \
> { "faster", NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> MFX_TARGETUSAGE_6 }, INT_MIN, INT_MAX, VE, "preset"
> }, \
> @@ -124,6 +122,10 @@
> { "gamestreaming", NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> MFX_SCENARIO_GAME_STREAMING }, .flags = VE, "scenario"
> }, \
> { "remotegaming", NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> MFX_SCENARIO_REMOTE_GAMING }, .flags = VE, "scenario" },
>
> +#define QSV_OPTION_AVBR \
> +{ "avbr_accuracy", "Accuracy of the AVBR ratecontrol (unit of tenth of
> percent)", OFFSET(qsv.avbr_accuracy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0,
> UINT16_MAX, VE }, \
> +{ "avbr_convergence", "Convergence of the AVBR ratecontrol (unit of 100
> frames)", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 0 }, 0,
> UINT16_MAX, VE },
> +
> extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[];
>
> typedef int SetEncodeCtrlCB (AVCodecContext *avctx,
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> index a0dc31e24a..4b29ccac0f 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -115,6 +115,7 @@ static const AVOption options[] = {
> QSV_OPTION_LOW_DELAY_BRC
> QSV_OPTION_MAX_MIN_QP
> QSV_OPTION_SCENARIO
> + QSV_OPTION_AVBR
>
> { "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 e59747fda3..29086337fb 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -236,6 +236,7 @@ static const AVOption options[] = {
> QSV_OPTION_ADAPTIVE_I
> QSV_OPTION_ADAPTIVE_B
> QSV_OPTION_SCENARIO
> + QSV_OPTION_AVBR
>
> { "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" },
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-05 2:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-01 2:12 [FFmpeg-devel] [PATCH] lavc/qsvenc: use VBR if maxrate is not specified on Windows Xiang, Haihao
2022-09-05 2:48 ` Xiang, Haihao
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