diff mbox series

[FFmpeg-devel] lavc/qsvenc: add support for external bitrate control for HEVC

Message ID 1581598044-7703-1-git-send-email-linjie.fu@intel.com
State New
Headers show
Series [FFmpeg-devel] lavc/qsvenc: add support for external bitrate control for HEVC
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Fu, Linjie Feb. 13, 2020, 12:47 p.m. UTC
Enables option for hevc_qsv encoder:
    -extbrc

Improvements in BD-Rate could be observed with extbrc on.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
Details for extbrc:
https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#external-bit-rate-control

The improvement differs depending on the platform/clips/bitrate.
Based on the verifying on ICL, ~20% improvement in BD-Rate could be observed.

 libavcodec/qsvenc.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Zhong Li Feb. 15, 2020, 6:07 a.m. UTC | #1
Linjie Fu <linjie.fu@intel.com> 于2020年2月13日周四 下午8:50写道:
>
> Enables option for hevc_qsv encoder:
>     -extbrc
>
> Improvements in BD-Rate could be observed with extbrc on.
>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
> Details for extbrc:
> https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#external-bit-rate-control
>
> The improvement differs depending on the platform/clips/bitrate.
> Based on the verifying on ICL, ~20% improvement in BD-Rate could be observed.

Is there any HW platform requirement for this feature? And how much
quality improvement  for H264?

>  libavcodec/qsvenc.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 9e41650..7f964ad 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -681,11 +681,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>
>          q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco;
>
> -        if (avctx->codec_id == AV_CODEC_ID_H264) {
>  #if QSV_HAVE_CO2
> -            q->extco2.Header.BufferId     = MFX_EXTBUFF_CODING_OPTION2;
> -            q->extco2.Header.BufferSz     = sizeof(q->extco2);
> -
> +        if (avctx->codec_id == AV_CODEC_ID_H264) {
>              if (q->int_ref_type >= 0)
>                  q->extco2.IntRefType = q->int_ref_type;
>              if (q->int_ref_cycle_size >= 0)
> @@ -697,8 +694,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
>                  q->extco2.BitrateLimit = q->bitrate_limit ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
>              if (q->mbbrc >= 0)
>                  q->extco2.MBBRC = q->mbbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
> -            if (q->extbrc >= 0)
> -                q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
>
>              if (q->max_frame_size >= 0)
>                  q->extco2.MaxFrameSize = q->max_frame_size;
> @@ -746,9 +741,20 @@ FF_ENABLE_DEPRECATION_WARNINGS
>                  q->extco2.MaxQPP = q->extco2.MaxQPB = q->extco2.MaxQPI;
>              }
>  #endif
> +        }
> +
> +        if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC) {
> +            if (q->extbrc >= 0)
> +                q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
> +
> +            q->extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
> +            q->extco2.Header.BufferSz = sizeof(q->extco2);
> +
>              q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco2;
> +        }
>  #endif
>
> +        if (avctx->codec_id == AV_CODEC_ID_H264) {
>  #if QSV_HAVE_MF
>              if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 25)) {
>                  q->extmfp.Header.BufferId     = MFX_EXTBUFF_MULTI_FRAME_PARAM;
> --
> 2.7.4

Patch LGTM
Fu, Linjie Feb. 15, 2020, 8:30 a.m. UTC | #2
> -----Original Message-----
> From: Zhong Li <lizhong1008@gmail.com>
> Sent: Saturday, February 15, 2020 14:08
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Cc: Fu, Linjie <linjie.fu@intel.com>
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: add support for external
> bitrate control for HEVC
> 
> Linjie Fu <linjie.fu@intel.com> 于2020年2月13日周四 下午8:50写道:
> >
> > Enables option for hevc_qsv encoder:
> >     -extbrc
> >
> > Improvements in BD-Rate could be observed with extbrc on.
> >
> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > ---
> > Details for extbrc:
> > https://github.com/Intel-Media-
> SDK/MediaSDK/blob/master/doc/mediasdk-man.md#external-bit-rate-
> control
> >
> > The improvement differs depending on the platform/clips/bitrate.
> > Based on the verifying on ICL, ~20% improvement in BD-Rate could be
> observed.
> 
> Is there any HW platform requirement for this feature? And how much
> quality improvement  for H264?

Should also work on KBL or latest platforms, however didn't test the detailed
quality improvement data yet on other platforms or H264.

>
...
> 
> Patch LGTM

Thanks for the review.
Fu, Linjie Feb. 17, 2020, 4:05 p.m. UTC | #3
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Fu,
> Linjie
> Sent: Saturday, February 15, 2020 16:31
> To: Zhong Li <lizhong1008@gmail.com>; FFmpeg development discussions
> and patches <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: add support for external
> bitrate control for HEVC
> 
> > -----Original Message-----
> > From: Zhong Li <lizhong1008@gmail.com>
> > Sent: Saturday, February 15, 2020 14:08
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Cc: Fu, Linjie <linjie.fu@intel.com>
> > Subject: Re: [FFmpeg-devel] [PATCH] lavc/qsvenc: add support for external
> > bitrate control for HEVC
> >
> > Linjie Fu <linjie.fu@intel.com> 于2020年2月13日周四 下午8:50写道:
> > >
> > > Enables option for hevc_qsv encoder:
> > >     -extbrc
> > >
> > > Improvements in BD-Rate could be observed with extbrc on.
> > >
> > > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > > ---
> > > Details for extbrc:
> > > https://github.com/Intel-Media-
> > SDK/MediaSDK/blob/master/doc/mediasdk-man.md#external-bit-rate-
> > control
> > >
> > > The improvement differs depending on the platform/clips/bitrate.
> > > Based on the verifying on ICL, ~20% improvement in BD-Rate could be
> > observed.
> >
> > Is there any HW platform requirement for this feature? And how much
> > quality improvement  for H264?
> 
> Should also work on KBL or latest platforms, however didn't test the detailed
> quality improvement data yet on other platforms or H264.
> 

To elaborate more, some inputs from Media SDK:

Explicit list of codecs for which extbrc is supported: AVC, HEVC

Explicit comment on which HW it is supported: there are no HW limitations. Note
that SWBRC is available since 1.24 API:
(https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#mfxBRCFrameCtrl)

EXTBRC for HEVC should be supported ever since HEVC encoder is reday. (gen 9 +)

Explicit comment whether features is enabled for VME and VDENC encoders: there is no limitations.

> >
> ...
> >
> > Patch LGTM
> 
> Thanks for the review.
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 9e41650..7f964ad 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -681,11 +681,8 @@  FF_ENABLE_DEPRECATION_WARNINGS
 
         q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco;
 
-        if (avctx->codec_id == AV_CODEC_ID_H264) {
 #if QSV_HAVE_CO2
-            q->extco2.Header.BufferId     = MFX_EXTBUFF_CODING_OPTION2;
-            q->extco2.Header.BufferSz     = sizeof(q->extco2);
-
+        if (avctx->codec_id == AV_CODEC_ID_H264) {
             if (q->int_ref_type >= 0)
                 q->extco2.IntRefType = q->int_ref_type;
             if (q->int_ref_cycle_size >= 0)
@@ -697,8 +694,6 @@  FF_ENABLE_DEPRECATION_WARNINGS
                 q->extco2.BitrateLimit = q->bitrate_limit ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
             if (q->mbbrc >= 0)
                 q->extco2.MBBRC = q->mbbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
-            if (q->extbrc >= 0)
-                q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
 
             if (q->max_frame_size >= 0)
                 q->extco2.MaxFrameSize = q->max_frame_size;
@@ -746,9 +741,20 @@  FF_ENABLE_DEPRECATION_WARNINGS
                 q->extco2.MaxQPP = q->extco2.MaxQPB = q->extco2.MaxQPI;
             }
 #endif
+        }
+
+        if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC) {
+            if (q->extbrc >= 0)
+                q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
+
+            q->extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
+            q->extco2.Header.BufferSz = sizeof(q->extco2);
+
             q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco2;
+        }
 #endif
 
+        if (avctx->codec_id == AV_CODEC_ID_H264) {
 #if QSV_HAVE_MF
             if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 25)) {
                 q->extmfp.Header.BufferId     = MFX_EXTBUFF_MULTI_FRAME_PARAM;