If you're browsing this thread chances are you're not satisfied with the CBR that still spikes to very unpredictable bitrates resulting in ping problems or dropped frames, this is a guide to achieve a more "strict" CBR aswell as an explanation to why each setting would be helpful in this scenario.
Basically the setting we want to control/change here is the bufsize. we want to find a custom bufsize that the encoder is most aware of how to efficiently calculate CBR without blindly often dropping quality to try and keep the bitrate more less fluctuate.
(bitrate/fps) x (rc-lookahead - 1) = bufsize
What is rc-lookahead and how can i find this value ?
this describe the number of next frames the encoder consider as well as other factors before making a decision on the current frame size type and quality, you can directly control this setting by adding the custom encoder option rc-lookahead=number
Higher values/numbers are slower and the default used value depend on the preset you're using.
ultrafast 0, superfast 0, veryfast 10, faster 20, fast 30, medium 40.
So here's an example of a strict CBR 3000 bitrate 40fps stream,
3000/40 x 10 - 1 = 675
You can clearly see how the encoder started utilizing more of the small bframes and reducing frame sizes in general way before and as well as holding more data for the upcoming big key frame.
In general and in a constraint CBR scenario the more the bframes and lookahead the better, if you don't know how much is enough try adding tune=animation as a custom setting or you can control the maximum the encoder allow sequentially with the custom value bframes=number the maximum number you should ever use is 16 the default is 3.
tune=animation will allow the use of a couple more than the current but also tweaks other settings which also help with the motion scenes such as doubling the number of reference frames for the presets above "veryfast".
Also note that each additional bframe and lookahead frame you allow those also count as latency frames, So for example an rc-lookahead of 60 and bframes 16 on a 60 fps stream means about 1 second more delay.
TL, DR?
(bitrate/fps) x (rc-lookahead - 1) = use the result as a custom bufsize
then add tune=animation as a custom encoder setting.
Basically the setting we want to control/change here is the bufsize. we want to find a custom bufsize that the encoder is most aware of how to efficiently calculate CBR without blindly often dropping quality to try and keep the bitrate more less fluctuate.
(bitrate/fps) x (rc-lookahead - 1) = bufsize
What is rc-lookahead and how can i find this value ?
this describe the number of next frames the encoder consider as well as other factors before making a decision on the current frame size type and quality, you can directly control this setting by adding the custom encoder option rc-lookahead=number
Higher values/numbers are slower and the default used value depend on the preset you're using.
ultrafast 0, superfast 0, veryfast 10, faster 20, fast 30, medium 40.
So here's an example of a strict CBR 3000 bitrate 40fps stream,
3000/40 x 10 - 1 = 675
You can clearly see how the encoder started utilizing more of the small bframes and reducing frame sizes in general way before and as well as holding more data for the upcoming big key frame.
In general and in a constraint CBR scenario the more the bframes and lookahead the better, if you don't know how much is enough try adding tune=animation as a custom setting or you can control the maximum the encoder allow sequentially with the custom value bframes=number the maximum number you should ever use is 16 the default is 3.
tune=animation will allow the use of a couple more than the current but also tweaks other settings which also help with the motion scenes such as doubling the number of reference frames for the presets above "veryfast".
Also note that each additional bframe and lookahead frame you allow those also count as latency frames, So for example an rc-lookahead of 60 and bframes 16 on a 60 fps stream means about 1 second more delay.
TL, DR?
(bitrate/fps) x (rc-lookahead - 1) = use the result as a custom bufsize
then add tune=animation as a custom encoder setting.