What is VBV (Video Buffering Verifier) in H.264?

Oleksandr picture Oleksandr · Nov 9, 2015 · Viewed 19k times · Source

I can't understand what is a VBV (Video Buffering Verifier) and what relations it have with a maxrate.
When I use this command:

ffmpeg -i input.mp4 -crf 21 -maxrate 750k -bufsize 750k -codec:v:0 libx264 -s 640x360 -r 30 output.mp4

output.mp4 video have a bit rate about 730 kb/s
But when I use this command (same command but with -bufsize 5000k):

ffmpeg -i input.mp4 -crf 21 -maxrate 750k -bufsize 5000k -codec:v:0 libx264 -s 640x360 -r 30 output.mp4

output.mp4 video have more bit rate than 750kb/s (about 800-900 kb/s).
Why it happens? Why we need the the bufsize? What does the bufsize do?

Answer

aergistal picture aergistal · Nov 9, 2015

Basically the VBV enables you to make sure the encoded stream doesn't overflow or underflow the decoder's buffer. If too much data comes in fast the buffer will overflow and you'll be forced to drop some of it. If data is coming in too slow the buffer will run out and the playback will stall.

It's a bit counter-intuitive but a VBV underflow signals an encoder rate buffer overflow (video bitrate larger than the input rate) while a VBV overflow signals an encoder rate buffer underflow (video bitrate lower than input the rate).

For ffmpeg the bufsize is the size of the buffer. minrate and maxrate are used in conjunction with bufsize to set the max and min bitrate change tolerance for VBR (variable bitrate).

minrate is typically used along with maxrate to achieve near-CBR (constant bitrate).

maxrate is not the peak bitrate, it's rather the maximum bitrate that can enter the buffer. If you have a large buffer, like in your second example, you can tolerate a higher bitrate for a greater amount of time until the buffer overflows. VBV makes sure your bitrate is lowered before that happens. That's why your stream can reach 800-900 kbps.

You can read more here: The relationship between --vbv-bufsize and --vbv-maxrate