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?
VBV Buffer:4000 kbps. Well we probably also should also compensate for audio, but in this case just subtract 1 x audio bitrate from your VBV Max Rate and 4 x audio bitrate form your VBV Buffer and then you are set.
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.
buffersize: The size of the main buffer. Once streaming data comes into the main buffer, it is immediately split into the audio and video buffers. The default size of the main buffer is 1.5MB for HD models, 3MB for XD models, and 6MB for 4K models. vcdbsize: The size of the video-coded data buffer.
ffmpeg bufsize is simply the amount of data processed (number of bits) before ffmpeg re-calculates the current bitrate, based on the content being transcoded. You may think of bufsize as similar to key frames.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With