[FFmpeg-devel] [V2 2/2] lavc/vaapi_encode: fix to set the default max bitrate for VBR

Pengfei Qu Pengfei.Qu at intel.com
Mon Mar 26 08:51:18 EEST 2018


The current RC(CBR/VBR) mode in ffmpeg-vaapi depends on the target bitrate
and max bitrate. CBR when target bitrate equal to max bitrate, or VBR.

Here is the background to have this solution. One issue I saw when doing
transcoding Mpeg2(interlace)->AVC on VBR mode, the real output bitrate go
away too much compared to target bitrate when there is no max bitrate
parameter in the command line. It work well when set the correct max
bitrate parameter in the command line.

And for VBR mode in the codec, generally the max bit rate is bigger than the taraget
bitrate. For CBR mode, the max bitrate is same as the target bitrate.
When there is no specfic setting for the max bit rate parameter in the command,
here the default value 95% is used to caculate the default max bitrate
accordingly. The original code set max bitrate same as the target bitrate
with the rc_target_percentage=100. The value "95" is also the experienced
value and here give an initial max bitrate closer to the target bitrate
and avoid bigger fluctuation.

Signed-off-by: Pengfei Qu <Pengfei.Qu at intel.com>
---
 libavcodec/vaapi_encode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 78347d4..47110cf 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1164,8 +1164,8 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
     } else {
         if (avctx->rc_max_rate < avctx->bit_rate) {
             // Max rate is unset or invalid, just use the normal bitrate.
-            rc_bits_per_second   = avctx->bit_rate;
-            rc_target_percentage = 100;
+            rc_target_percentage = 95;
+            rc_bits_per_second   = (unsigned long)(avctx->bit_rate * 100.0 / rc_target_percentage);
         } else {
             rc_bits_per_second   = avctx->rc_max_rate;
             rc_target_percentage = (unsigned long)(avctx->bit_rate * 100) / rc_bits_per_second;
-- 
2.9.3



More information about the ffmpeg-devel mailing list