Tool

How to Set maxrate and bufsize: A VBV Planner by Use Case

"What should maxrate be, and how many times that for bufsize?" Old mailing lists and forums are full of rules of thumb, but few come with numbers. Pick a use case (live streaming, HLS, an upload limit, or device compatibility) and the tool builds the values and an ffmpeg command. Next to them it shows our own data on CRF with a cap: whether that cap will bind, and if it does, how far VMAF dropped. All processing happens inside this browser.

Use case

Codec

Preset

We only measured medium. The preset is just a value in the command; it is not reflected in the measured tables below.

bufsize (seconds' worth of maxrate)

Keyframe interval (seconds)

If your streaming platform or streaming spec requires a particular interval, use that value. This tool has no built-in value.

Generated settings

maxrate 6,000kbufsize 12,000k

Sets maxrate and minrate equal to the 6,000k target to get close to CBR. bufsize = 2 s worth.

ffmpeg -i input.mp4 -c:v libx264 -preset veryfast -pix_fmt yuv420p -b:v 6000k -minrate 6000k -maxrate 6000k -bufsize 12000k -g 60 -keyint_min 60 -c:a aac -b:a 160k -f flv "RTMP_URL"

The bitrate numbers are for video only. Add the audio bitrate separately and check that the total fits within your upload speed. This site has not measured the quality of CBR-style encoding.

What are maxrate and bufsize?

Inside the encoder there is a virtual decoder buffer called the VBV (Video Buffering Verifier). It is assumed to fill at the maxrate rate and to drain by the size of each frame as that frame is played. bufsize is the size of this buffer. So bufsize ÷ maxrate is how many seconds' worth of bits can be saved up and spent above the cap. The tool's “bufsize as seconds of maxrate” option is exactly that value. It is a limit on a different layer from -b:v and -crf, which set the average bitrate, and it only comes into play in difficult scenes.

What does it build for each use case?

Use caseSettings it buildsSource of the numbers
Live streaming-b:v = -minrate = -maxrate, bufsize is the number of seconds you chooseThe target you enter. No data
HLS / DASH-b:v target, -maxrate = target × the multiple you choose, keyframe = segment lengthValues you enter or choose. No data
Upload limit (average)-crf + vbv-maxrate = limit ÷ the measured ratioMeasured: the largest value of actual average ÷ cap when the cap bound
Device compatibility (instantaneous)-crf + vbv-maxrate = the device limit, bufsize at or below the device buffer limitThe device limit you enter. No data

The rows marked “No data” just translate the values you enter into the command format. What this site measured itself is the row marked “Measured” in the last column and the measured tables in the middle of the tool.

Where do the measured numbers come from?

The tool reads the raw data from What Does Capped CRF (maxrate + bufsize) Cost in Quality? as is: four 10-second 1080p25 clips, x264 and x265 at medium, three CRF steps, caps of 2, 4 and 8 Mbps (bufsize is 2× maxrate), on one Ryzen 5 PRO 4650G PC. The tool computes three things.

  1. The ratio to use when fitting an average limit: among the cells where the uncapped average was higher than the cap, the largest value of (actual average with the cap ÷ cap). The limit divided by this value is the maxrate for the “upload limit” use case. With a limit of 8,000 kbps and x264, that is 8,000 ÷ 1.081 = about 7,400 kbps (if the ratio in the table changes, this value changes too).
  2. The cap cost table: for the same clip and the same CRF, the change in size and in mean, bottom-5% and minimum VMAF compared with no cap.
  3. The binding-zone table: for each cell it computes (uncapped average ÷ cap), splits the cells into 80% or lower, 80–100%, and above 100%, and shows for each zone how many cells shrank by more than 2% and the worst values.

How to use it

  1. Pick a use case and enter the limit or target number. Numbers from streaming platforms, streaming specs and device manuals change with the service and over time, so check them yourself before entering them.
  2. The most important step is to run a test encode of a representative segment with uncapped CRF first and measure its average bitrate. Enter that value in the “Will my video hit the cap?” field and the binding-zone table tells you which row you are in. In our measurements, when the average was 80% of the cap or lower, the cap had practically no effect.
  3. If you are in a row where the cap binds, look at the bottom-5% and minimum VMAF drops in the cap cost table. In some cells the minimum fell a lot even though the mean VMAF barely moved.
  4. Copy the command, run it on a short segment, and check the per-second bitrate of the result with the Bitrate Over Time Graph. This tool builds the settings; checking that they were honored is that tool's job.
  5. For streaming, first choose a target bitrate that fits your upload speed in the Streaming Upload Speed Bitrate and Resolution Planner and enter it here. The H.264 and HEVC level calculator helps with the level numbers for a device limit.

Limitations worth knowing

  • We did not measure the peak (the maximum bitrate over 1-second windows). The data has only the average over the whole 10 seconds (file size ÷ 10 s), so we cannot tell how far the actual maximum 1-second average exceeded maxrate. The “multiple of the cap” shown in the tool is based on the 10-second average.
  • We measured bufsize only at 2× maxrate. Choices such as 1× and 4× are reflected in the command, but the measured tables are for 2×. We did not measure quality or compliance with a smaller or larger buffer.
  • We did not measure CBR or ABR modes for the live and HLS use cases. What we measured is CRF with a cap, and the command values for those two use cases are your target translated into the right format. A same-size comparison of 2-pass and CBR is in 2-Pass vs CRF Tested, but that article did not use maxrate.
  • Four 10-second clips, 8-bit, 1080p25, preset medium, one PC. The initial VBV buffer is a larger share of 10 seconds than of a longer video, so we could not separate the causes (overhead, the initial buffer and so on) of the actual average coming out higher than the cap in the cells where it bound. The ratio may differ for longer videos.
  • VMAF is not the same as quality as seen by human eyes. Whether a limit is an “average” or an “instantaneous” one, check in the service's own spec. The tool's “upload (average)” and “device (instantaneous)” split does not replace that check.
  • Hardware encoders (NVENC, QSV and so on), AV1 and VP9 are out of scope, and the tool does not build commands for them.