[FFmpeg-devel,v2,1/2] vaapi_encode: ensure correct VBR bitrate is used in h264 SPS

Submitted by Aman Gupta on Aug. 13, 2019, 1:04 a.m.

Details

Message ID 20190813010456.91644-1-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Gupta Aug. 13, 2019, 1:04 a.m.
From: Aman Gupta <aman@tmm1.net>

This is a regression from 2562dd9e7831743ba6dc5680501fb7d26a2ec62c
which surfaces a pathological bug in some Intel hardware encoders,
causing very low bitrates to be generated whenever VBR mode is used.

/cc intel/intel-vaapi-driver#480

Signed-off-by: Aman Gupta <aman@tmm1.net>
---
 libavcodec/vaapi_encode.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Mark Thompson Aug. 20, 2019, 9:05 p.m.
On 13/08/2019 02:04, Aman Gupta wrote:
> From: Aman Gupta <aman@tmm1.net>
> 
> This is a regression from 2562dd9e7831743ba6dc5680501fb7d26a2ec62c
> which surfaces a pathological bug in some Intel hardware encoders,
> causing very low bitrates to be generated whenever VBR mode is used.
> 
> /cc intel/intel-vaapi-driver#480
> 
> Signed-off-by: Aman Gupta <aman@tmm1.net>
> ---
>  libavcodec/vaapi_encode.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index e69b59fa37..231efba6cc 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -1665,6 +1665,9 @@ rc_mode_found:
>      ctx->va_rc_mode  = rc_mode->va_mode;
>      ctx->va_bit_rate = rc_bits_per_second;
>  
> +    if (ctx->va_rc_mode == VA_RC_VBR)
> +        ctx->va_bit_rate = rc_bits_per_second * rc_target_percentage / 100;
> +
>      av_log(avctx, AV_LOG_VERBOSE, "RC mode: %s.\n", rc_mode->name);
>      if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
>          // This driver does not want the RC mode attribute to be set.
> 

The bits_per_second value in the sequence parameters has to match the one in the rate control parameters.  That's the max rate value, not the target as modified by target_percentage.

For i965, see <https://github.com/intel/intel-vaapi-driver/blob/master/src/i965_encoder.c> (lines 392, 584, 743).  When they don't match, it will repeatedly try to change the target bitrate and reset everything.


On 13/08/2019 03:42, Fu, Linjie wrote:
> 
> If it's a driver related issue, IMHO we'd better have it fixed in specific driver.

This.

Thanks,

- Mark

Patch hide | download patch | download mbox

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index e69b59fa37..231efba6cc 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1665,6 +1665,9 @@  rc_mode_found:
     ctx->va_rc_mode  = rc_mode->va_mode;
     ctx->va_bit_rate = rc_bits_per_second;
 
+    if (ctx->va_rc_mode == VA_RC_VBR)
+        ctx->va_bit_rate = rc_bits_per_second * rc_target_percentage / 100;
+
     av_log(avctx, AV_LOG_VERBOSE, "RC mode: %s.\n", rc_mode->name);
     if (rc_attr.value == VA_ATTRIB_NOT_SUPPORTED) {
         // This driver does not want the RC mode attribute to be set.