lavc/qsvenc: allow to set qp range for h264 BRC

Message ID 1535358211-32379-1-git-send-email-zhong.li@intel.com
State Committed
Commit e16b20782a597e36a9c7488487c3179375a25b97
Headers show
Series
  • lavc/qsvenc: allow to set qp range for h264 BRC
Related show

Commit Message

Li, Zhong Aug. 27, 2018, 8:23 a.m.
Signed-off-by: Zhong Li <zhong.li@intel.com>
---
 libavcodec/qsvenc.c      | 14 ++++++++++++++
 libavcodec/qsvenc_h264.c |  2 ++
 2 files changed, 16 insertions(+)

Comments

Luca Barbato Sept. 1, 2018, 7:59 a.m. | #1
On 27/08/2018 10:23, Zhong Li wrote:
> Signed-off-by: Zhong Li <zhong.li@intel.com>
> ---
>  libavcodec/qsvenc.c      | 14 ++++++++++++++
>  libavcodec/qsvenc_h264.c |  2 ++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index e7ca62f..c2c2911 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -665,6 +665,20 @@ FF_ENABLE_DEPRECATION_WARNINGS
>                  q->extco2.AdaptiveB = q->adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
>  #endif
>  
> +#if QSV_VERSION_ATLEAST(1, 9)
> +            if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) {
> +                av_log(avctx, AV_LOG_ERROR, "qmin and or qmax are set but invalid, please make sure min <= max\n");
> +                return AVERROR(EINVAL);
> +            }
> +            if (avctx->qmin >= 0) {
> +                q->extco2.MinQPI = avctx->qmin > 51 ? 51 : avctx->qmin;
> +                q->extco2.MinQPP = q->extco2.MinQPB = q->extco2.MinQPI;
> +            }
> +            if (avctx->qmax >= 0) {
> +                q->extco2.MaxQPI = avctx->qmax > 51 ? 51 : avctx->qmax;
> +                q->extco2.MaxQPP = q->extco2.MaxQPB = q->extco2.MaxQPI;
> +            }
> +#endif
>              q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco2;
>          }
>  #endif
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> index 2b9401f..164f573 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -118,6 +118,8 @@ static const AVCodecDefault qsv_enc_defaults[] = {
>      // same as the x264 default
>      { "g",         "250"   },
>      { "bf",        "3"     },
> +    { "qmin",      "-1"    },
> +    { "qmax",      "-1"    },
>  #if FF_API_CODER_TYPE
>      { "coder",     "-1"    },
>  #endif
> 

Also this seems fine. I'd push it during this weekend.

lu

Patch

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index e7ca62f..c2c2911 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -665,6 +665,20 @@  FF_ENABLE_DEPRECATION_WARNINGS
                 q->extco2.AdaptiveB = q->adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
 #endif
 
+#if QSV_VERSION_ATLEAST(1, 9)
+            if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) {
+                av_log(avctx, AV_LOG_ERROR, "qmin and or qmax are set but invalid, please make sure min <= max\n");
+                return AVERROR(EINVAL);
+            }
+            if (avctx->qmin >= 0) {
+                q->extco2.MinQPI = avctx->qmin > 51 ? 51 : avctx->qmin;
+                q->extco2.MinQPP = q->extco2.MinQPB = q->extco2.MinQPI;
+            }
+            if (avctx->qmax >= 0) {
+                q->extco2.MaxQPI = avctx->qmax > 51 ? 51 : avctx->qmax;
+                q->extco2.MaxQPP = q->extco2.MaxQPB = q->extco2.MaxQPI;
+            }
+#endif
             q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco2;
         }
 #endif
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 2b9401f..164f573 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -118,6 +118,8 @@  static const AVCodecDefault qsv_enc_defaults[] = {
     // same as the x264 default
     { "g",         "250"   },
     { "bf",        "3"     },
+    { "qmin",      "-1"    },
+    { "qmax",      "-1"    },
 #if FF_API_CODER_TYPE
     { "coder",     "-1"    },
 #endif