Limit Bitrate

All modern video encodings fluctuate in bitrate from scene to scene. Fast moving scenes, such as a car chase, need more bits to encode. Slow moving scenes, such as a person talking, doesn't need many bits to encode. To see this in action, play any video in VLC and go to Tools > Codec Information > Statistics > Input/Read > Content Bitrate. Notice how that number jumps up and down? For more detailed information about how video is encoded, view our x264 tutorial.

There are two reasons for controlling the fluctuation of your video's bitrate. The first is that you're often exceeding the upload capacity provided by your Internet service provider. Many ISP's only provide 1 to 2 Mbps upload. When you're stream exceeds that limit, you will drop frames and viewers will complain about lag. The second reason is that you want to serve a stable stream to people with poor Internet connections. People with bad Internet connections cannot watch streams that peak at extreme bitrates.

Warning! These fluctuations are optimal for video quality. Attempting to limit the bitrate will always result in a worse quality stream, especially for fast moving scenes. Only do rate limiting if either of the above two conditions apply. Note that realtime encodings often do not fluctuate as wildly as 2-pass offline encodings.

vbv-maxrate & vbv-bufsize

To tame the wild fluctuations of bitrate, we use two x264 parameters: vbv-maxrate & vbv-bufsize. You must specify both parameters. If either one is left out, there will be no effect. Set vbv-maxrate to the maximum kbps you want your stream to peak at. Set vbv-bufsize to be twice vbv-maxrate. This ratio is dependent on the buffering of the video playback. A 1:2 ratio works well for Veetle's player. For example, if I wanted a peak of 2000 kbps (2 Mbps), I would use this stream output:

#transcode{vb=900, vcodec=h264, venc=x264{vbv-maxrate=2000, vbv-bufsize=4000, bpyramid=none, weightp=0}, acodec=mp3, ab=96, channels=2, threads=2}:duplicate{dst=standard{access=http, mux=asf, dst=localhost:1234}}

Consult the external VLC tutorial if you don't where where to paste this code. These parameters are not only used in VLC. Any x264 transcoder, such as Handbrake, can also use them.

A small caveat: these x264 settings only limit your video bitrate. Audio and network packet headers also add to your total bitrate. So sometimes you'll see you're total bitrate exceed 2000 kbps even though you set vbv-maxtrate to 2000. Since audio and headers are so small in comparison to video, I wouldn't worry too much about this. But if you're pumping out extremely high bitrate audio (above 128 kbps), I'd cut back on vbv-maxrate/bufsize.