FFMPEG - bufsize formula
Asked Answered
P

2

7

Does anyone know what the formula is for bufsize along with the rate it checks in FFMPEG?

I can't seem to find any concrete answer to this.

Is it: bufsize = bitrate / rate ?

And should it be using maxrate as opposed to bitrate in the calculation?

Example on working out the rate at which the checks are done:

bitrate: 700Kbps
maxrate: 700Kbps
bufsize: 70Kb

700Kbps/70Kb = 10 sec

Is that right? To me that doesn't sound right because a smaller bufsize should be running the check at a higher rate and 10 seconds seems too long of a gap.

Would the formula need to be inverted?

Does anyone have an idea on the correct syntax for the formula and units?

Pentlandite answered 15/6, 2021 at 13:42 Comment(3)
Does anyone have an idea on this or is it a hidden secret? I understand the concept behind it, just need concrete fact on its formula and working outs etcPentlandite
Can anyone assist?Pentlandite
I'm thinking inverted. Any experts free to clarify?Pentlandite
I
7

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. The difference is bufsize triggers a re-evaluation of ffmpeg's current algorithm usage after X bits of data have been processed. While commands related to key frame evaluation (e.g. -g parameter) operate based on how many frames have been processed since the last time the key frame evaluation took place.

For example, let's say you setup ffmpeg in Constant Bit Rate (CBR) mode and set -bufsize to 2x your bit rate. The formula will be simple. Every 2 frames, ffmpeg will adjust. On the other hand, if you are using VBR and set -bufsize at 2x the target bit rate, exactly how often ffmpeg adjusts its encoding formula (and the actual bitrate) will vary depending on what the bitrate is at any given moment (since it is variable). So, the frequency - in terms of frames and/or bits processed - will vary throughout the encode.

Thinking strictly of bit rate constrained encoding modes only (i.e. non-CQ/CRF), a good ballpark concept of a -bufsize target is to use between 1x - 2x your -maxsize bit rate (or target bit rate, depending on the codec and encoding mode).

EDIT: Clarifying a bit further.... -bufsize is used in conjunction with -maxsize to determine exactly when the maximum number of bits should be re-calculated (bufsize will dictate when that happens).

Ioves answered 8/9, 2021 at 12:48 Comment(2)
"set -bufsize to 2x your bit rate [...] Every 2 frames, ffmpeg will adjust." As the bitrate is specified in bits-per-seconds I would assume that FFmpeg will adjust every 2 seconds, instead of every 2 frames.Poulson
@Poulson it should equate to 2 seconds of playback time (i.e. content) with regards to the completed encoded product, but not 2 seconds of encoding time. ffmpeg will tweak its analysis of the frame evaluation based on frames, regardless of how long it takes the hardware to meet that goal during the encoding process.Ioves
A
0

Inverted. Basing on units alone, bps is b/s so (b/s)/b is 1/s which means every second(10 on the example). Formula should be bufsize/maxrate (b/(b/s) or s)

Amur answered 31/3, 2023 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.