diff mbox

[FFmpeg-devel] lavc/vaapi_encode_h265: Enable VBR mode

Message ID 46d44c28-1ad9-e0a2-e135-137f27fd1ee4@gmail.com
State Accepted
Commit 385cafb07ac1e46433931ea9749a134efd7350be
Headers show

Commit Message

Jun Zhao Aug. 25, 2017, 7:56 a.m. UTC
From 483204cf7c25077d556c86b9e70f591fc2c0d4a3 Mon Sep 17 00:00:00 2001
From: Jun Zhao <jun.zhao@intel.com>
Date: Fri, 25 Aug 2017 03:50:37 -0400
Subject: [PATCH] lavc/vaapi_encode_h265: Enable VBR mode

Follow vaapi_h264 style, enable the VBR mode.

Signed-off-by: Jun Zhao <jun.zhao@intel.com>
---
 libavcodec/vaapi_encode_h265.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Mark Thompson Aug. 28, 2017, 12:11 p.m. UTC | #1
On 25/08/17 08:56, Jun Zhao wrote:
> From 483204cf7c25077d556c86b9e70f591fc2c0d4a3 Mon Sep 17 00:00:00 2001
> From: Jun Zhao <jun.zhao@intel.com>
> Date: Fri, 25 Aug 2017 03:50:37 -0400
> Subject: [PATCH] lavc/vaapi_encode_h265: Enable VBR mode
> 
> Follow vaapi_h264 style, enable the VBR mode.
> 
> Signed-off-by: Jun Zhao <jun.zhao@intel.com>
> ---
>  libavcodec/vaapi_encode_h265.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
> index cf6b9388d1..971458db87 100644
> --- a/libavcodec/vaapi_encode_h265.c
> +++ b/libavcodec/vaapi_encode_h265.c
> @@ -1185,13 +1185,15 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
>                 "%d / %d / %d for IDR- / P- / B-frames.\n",
>                 priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
>  
> -    } else if (ctx->va_rc_mode == VA_RC_CBR) {
> +    } else if (ctx->va_rc_mode == VA_RC_CBR ||
> +               ctx->va_rc_mode == VA_RC_VBR) {
>          // These still need to be  set for pic_init_qp/slice_qp_delta.
>          priv->fixed_qp_idr = 30;
>          priv->fixed_qp_p   = 30;
>          priv->fixed_qp_b   = 30;
>  
> -        av_log(avctx, AV_LOG_DEBUG, "Using constant-bitrate = %"PRId64" bps.\n",
> +        av_log(avctx, AV_LOG_DEBUG, "Using %s-bitrate = %"PRId64" bps.\n",
> +               ctx->va_rc_mode == VA_RC_CBR ? "constant" : "variable",
>                 avctx->bit_rate);
>  
>      } else {
> @@ -1251,9 +1253,12 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
>      }
>      ctx->va_entrypoint = VAEntrypointEncSlice;
>  
> -    if (avctx->bit_rate > 0)
> -        ctx->va_rc_mode = VA_RC_CBR;
> -    else
> +    if (avctx->bit_rate > 0) {
> +        if (avctx->rc_max_rate == avctx->bit_rate)
> +            ctx->va_rc_mode = VA_RC_CBR;
> +        else
> +            ctx->va_rc_mode = VA_RC_VBR;
> +    } else
>          ctx->va_rc_mode = VA_RC_CQP;
>  
>      ctx->va_packed_headers =
> -- 
> 2.11.0
> 

Applied.

Thanks!

- Mark
diff mbox

Patch

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index cf6b9388d1..971458db87 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1185,13 +1185,15 @@  static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
                "%d / %d / %d for IDR- / P- / B-frames.\n",
                priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
 
-    } else if (ctx->va_rc_mode == VA_RC_CBR) {
+    } else if (ctx->va_rc_mode == VA_RC_CBR ||
+               ctx->va_rc_mode == VA_RC_VBR) {
         // These still need to be  set for pic_init_qp/slice_qp_delta.
         priv->fixed_qp_idr = 30;
         priv->fixed_qp_p   = 30;
         priv->fixed_qp_b   = 30;
 
-        av_log(avctx, AV_LOG_DEBUG, "Using constant-bitrate = %"PRId64" bps.\n",
+        av_log(avctx, AV_LOG_DEBUG, "Using %s-bitrate = %"PRId64" bps.\n",
+               ctx->va_rc_mode == VA_RC_CBR ? "constant" : "variable",
                avctx->bit_rate);
 
     } else {
@@ -1251,9 +1253,12 @@  static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
     }
     ctx->va_entrypoint = VAEntrypointEncSlice;
 
-    if (avctx->bit_rate > 0)
-        ctx->va_rc_mode = VA_RC_CBR;
-    else
+    if (avctx->bit_rate > 0) {
+        if (avctx->rc_max_rate == avctx->bit_rate)
+            ctx->va_rc_mode = VA_RC_CBR;
+        else
+            ctx->va_rc_mode = VA_RC_VBR;
+    } else
         ctx->va_rc_mode = VA_RC_CQP;
 
     ctx->va_packed_headers =