Roly's Blog

Whatever will be, will be, the future's not ours to see.

0%

Video Buffer Verifier

The Video Buffering Verifier (VBV) is a theoretical MPEG video buffer model, used to ensure that an encoded video stream can be correctly buffered, and played back at the decoder device.

By definition, the VBV shall not overflow nor underflow when its input is a compliant stream, (except in the case of low_delay). It is therefore important when encoding such a stream that it comply with the VBV requirements.

One way to think of the VBV is to consider both a maximum bitrate and a maximum buffer size. You’ll need to know how quickly the video data is coming into the buffer. Keep in mind that video data is always changing the bitrate so there is no constant number to note how fast the data is arriving. The larger question is how long before the buffer overflows. A larger buffer size simply means that the decoder will tolerate high bitrates for longer periods of time, but no buffer is infinite, so eventually even a large buffer will overflow.

There are two operational modes of VBV: Constant Bit Rate (CBR) and Variable Bit Rate (VBR). In CBR, the decoder’s buffer is filled over time at a constant data rate. In VBR, the buffer is filled at a non-constant rate. In both cases, data is removed from the buffer in varying chunks, depending on the actual size of the coded frames.

VBV and CPB

Consider a water outlet, a water tank, and a series of “picture decode guys” lined up in front of the tank.

image

The water (coded MPEG-2 or H.264 stream) is constantly flowing into the tank. The guys are lined up in front of the tank and remove the water for each frame to be decoded. The removal happens at the fixed time interval in most cases.

Even though Mr.I, P, and B are removing different amount of water (=each frame needs different number of bits), the water outlet speed is constant thanks to the tank (buffer).

In MPEG-2, the buffer is called VBV buffer (Video Buffer Verifier Buffer). In H.264, the buffer is called CPB (Coded Picture Buffer).

The water level of the tank at certain time instance is called buffer fullness and described in number of bits. The size of the tank is called VBV buffer size in MPEG-2 and CPB buffer size in H.264.

The coded stream must be constructed so that the tank (=buffer) never overflow or underflow.

bufsize and maxrate

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 ( as shown above, it is the speed at which water comes out of the water outlet). If you have a large buffer, 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.

Reference

https://en.wikipedia.org/wiki/Video_buffering_verifier

https://codesequoia.wordpress.com/2010/04/19/what-are-cbr-vbv-and-cpb/

https://stackoverflow.com/questions/33611900/what-is-vbv-video-buffering-verifier-in-h-264

https://trac.ffmpeg.org/wiki/Encode/H.264

https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate