[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(+)

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.