diff mbox series

[FFmpeg-devel] lavc/qsvenc_hevc: add qmax/qmin support for HEVC encoding

Message ID 1583923168-9324-1-git-send-email-linjie.fu@intel.com
State New
Headers show
Series [FFmpeg-devel] lavc/qsvenc_hevc: add qmax/qmin support for HEVC encoding
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 March 11, 2020, 10:39 a.m. UTC
Add qmax/qmin support for HEVC software bitrate control(SWBRC).

Limitations:
    - RateControlMethod != MFX_RATECONTROL_CQP
    - with EXTBRC ON

Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---

Relative code in MSDK for the limitation:
https://github.com/Intel-Media-SDK/MediaSDK/blob/master/_studio/mfx_lib/encode_hw/hevc/agnostic/g9/hevcehw_g9_legacy.cpp#L4267

 libavcodec/qsvenc.c      | 11 +++++------
 libavcodec/qsvenc_hevc.c |  2 ++
 2 files changed, 7 insertions(+), 6 deletions(-)

Comments

Max Dmitrichenko March 11, 2020, 11:36 a.m. UTC | #1
On Wed, Mar 11, 2020 at 11:44 AM Linjie Fu <linjie.fu@intel.com> wrote:

> Add qmax/qmin support for HEVC software bitrate control(SWBRC).
>
> Limitations:
>     - RateControlMethod != MFX_RATECONTROL_CQP
>     - with EXTBRC ON
>
> Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
>
> Relative code in MSDK for the limitation:
>
> https://github.com/Intel-Media-SDK/MediaSDK/blob/master/_studio/mfx_lib/encode_hw/hevc/agnostic/g9/hevcehw_g9_legacy.cpp#L4267
>
>  libavcodec/qsvenc.c      | 11 +++++------
>  libavcodec/qsvenc_hevc.c |  2 ++
>  2 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 52b4e43..2c22eb7 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -732,6 +732,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
>              if (q->adaptive_b >= 0)
>                  q->extco2.AdaptiveB = q->adaptive_b ? MFX_CODINGOPTION_ON
> : MFX_CODINGOPTION_OFF;
>  #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;
>
>  #if QSV_VERSION_ATLEAST(1, 9)
>              if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin >
> avctx->qmax) {
> @@ -747,12 +752,6 @@ 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);
>
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index 27e2232..3bdca7d 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -262,6 +262,8 @@ static const AVCodecDefault qsv_enc_defaults[] = {
>      // same as the x264 default
>      { "g",         "248"   },
>      { "bf",        "8"     },
> +    { "qmin",      "-1"    },
> +    { "qmax",      "-1"    },
>      { "trellis",   "-1"    },
>      { "flags",     "+cgop" },
>  #if FF_API_PRIVATE_OPT
> --
> 2.7.4
>
>
>
looks reasonable

regards
Max
Fu, Linjie March 11, 2020, 12:45 p.m. UTC | #2
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Max Dmitrichenko
> Sent: Wednesday, March 11, 2020 19:37
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/qsvenc_hevc: add qmax/qmin
> support for HEVC encoding
> 
> On Wed, Mar 11, 2020 at 11:44 AM Linjie Fu <linjie.fu@intel.com> wrote:
> 
> > Add qmax/qmin support for HEVC software bitrate control(SWBRC).
> >
> > Limitations:
> >     - RateControlMethod != MFX_RATECONTROL_CQP
> >     - with EXTBRC ON
> >
> > Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > ---
> >
> > Relative code in MSDK for the limitation:
> >
> > https://github.com/Intel-Media-
> SDK/MediaSDK/blob/master/_studio/mfx_lib/encode_hw/hevc/agnostic/g9
> /hevcehw_g9_legacy.cpp#L4267
> >
> >  libavcodec/qsvenc.c      | 11 +++++------
> >  libavcodec/qsvenc_hevc.c |  2 ++
> >  2 files changed, 7 insertions(+), 6 deletions(-)
> >
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index 52b4e43..2c22eb7 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -732,6 +732,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
> >              if (q->adaptive_b >= 0)
> >                  q->extco2.AdaptiveB = q->adaptive_b ?
> MFX_CODINGOPTION_ON
> > : MFX_CODINGOPTION_OFF;
> >  #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;
> >
> >  #if QSV_VERSION_ATLEAST(1, 9)
> >              if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin >
> > avctx->qmax) {
> > @@ -747,12 +752,6 @@ 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);
> >
> > diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> > index 27e2232..3bdca7d 100644
> > --- a/libavcodec/qsvenc_hevc.c
> > +++ b/libavcodec/qsvenc_hevc.c
> > @@ -262,6 +262,8 @@ static const AVCodecDefault qsv_enc_defaults[] = {
> >      // same as the x264 default
> >      { "g",         "248"   },
> >      { "bf",        "8"     },
> > +    { "qmin",      "-1"    },
> > +    { "qmax",      "-1"    },
> >      { "trellis",   "-1"    },
> >      { "flags",     "+cgop" },
> >  #if FF_API_PRIVATE_OPT
> > --
> > 2.7.4
> >
> >
> >
> looks reasonable

Thanks for review.
Zhong Li March 12, 2020, 2:07 a.m. UTC | #3
Linjie Fu <linjie.fu@intel.com> 于2020年3月11日周三 下午6:44写道:
>
> Add qmax/qmin support for HEVC software bitrate control(SWBRC).
>
> Limitations:
>     - RateControlMethod != MFX_RATECONTROL_CQP
>     - with EXTBRC ON
>
> Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
>
> Relative code in MSDK for the limitation:
> https://github.com/Intel-Media-SDK/MediaSDK/blob/master/_studio/mfx_lib/encode_hw/hevc/agnostic/g9/hevcehw_g9_legacy.cpp#L4267
>
>  libavcodec/qsvenc.c      | 11 +++++------
>  libavcodec/qsvenc_hevc.c |  2 ++
>  2 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 52b4e43..2c22eb7 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -732,6 +732,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
>              if (q->adaptive_b >= 0)
>                  q->extco2.AdaptiveB = q->adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
>  #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;
>
>  #if QSV_VERSION_ATLEAST(1, 9)
>              if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) {
> @@ -747,12 +752,6 @@ 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);
>
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index 27e2232..3bdca7d 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -262,6 +262,8 @@ static const AVCodecDefault qsv_enc_defaults[] = {
>      // same as the x264 default
>      { "g",         "248"   },
>      { "bf",        "8"     },
> +    { "qmin",      "-1"    },
> +    { "qmax",      "-1"    },
>      { "trellis",   "-1"    },
>      { "flags",     "+cgop" },
>  #if FF_API_PRIVATE_OPT
> --
> 2.7.4

LGTM, will apply
diff mbox series

Patch

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 52b4e43..2c22eb7 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -732,6 +732,11 @@  FF_ENABLE_DEPRECATION_WARNINGS
             if (q->adaptive_b >= 0)
                 q->extco2.AdaptiveB = q->adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
 #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;
 
 #if QSV_VERSION_ATLEAST(1, 9)
             if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) {
@@ -747,12 +752,6 @@  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);
 
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 27e2232..3bdca7d 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -262,6 +262,8 @@  static const AVCodecDefault qsv_enc_defaults[] = {
     // same as the x264 default
     { "g",         "248"   },
     { "bf",        "8"     },
+    { "qmin",      "-1"    },
+    { "qmax",      "-1"    },
     { "trellis",   "-1"    },
     { "flags",     "+cgop" },
 #if FF_API_PRIVATE_OPT