MPEG Encoder Modes Explained

In the beginning, there was Constant Bit Rate encoding. Chiariglione spake, "Let there be CBR," and CBR came to BE and he saw that it was good... — 1 Iso 11:72

CBR works, it's simple to code (by MPEG standards, at any rate) and only planets are more predictable. But nothing good ever stays simple. From the humble CBR root sprang three major varieties of Variable Bit Rate encoding:

Mode Comments
  1-Pass VBR This is the most common VBR mode because it's the simplest of the bunch: you supply the encoder with either an average bit rate to maintain or a minimum and maximum to stay between, and it varies picture quality to meet those goals.
  N-Pass VBR With 1-pass VBR, the encoder doesn't have advance knowledge of what is coming up in the stream, so it has to simply guess. 2-pass VBR lets the encoder make a purely exploratory pass over the video before doing the actual encoding. With 3 and more passes, the encoder can re-encode sections of the video a second time using the data from previous tries. This asymptotically approaches the best possible video stream that the encoder is capable of.
  CQ CQ can stand for "constant quality", or "constant quantization". The effect is the same, though they come at the same issue from different sides. The quantization (Q) level of an MPEG stream is a measure of the amount of data the encoder threw away to bring the bit rate down. Higher Q values mean the encoder threw away a lot of data, implying a low bit rate, but also low visual quality. A low Q level implies a high bit rate, and high visual fidelity. Coming at the issue from the other direction, setting a "constant quality" implies a particular MPEG Q level, with higher quality numbers implying lower Q numbers. Usually an encoder that expresses the issue as one of setting the quality doesn't show you the resulting MPEG quantization (Q) level. Because every encoder is different, there is no standard mapping from one "quality level" to an MPEG Q level. Indeed, the Q level for a given quality level might well depend on the video characteristics as much as the encoder.

(By the way, in MPEG, if you see Q written alone, it always means quantization, and not quality. Some would therefore say it's confusing to use "CQ" to mean "constant quality." CQ as shorthand for "constant quantization" has a very long history. CQ as shorthand for "constant quality" is a more recent coinage.)

In regular VBR modes, the quality level is varied continuously to keep to a desired bit rate. CQ modes let you pick a desired quality/Q level, and let the bit rate vary to compensate. This means that you cannot predict the bitrate output from a plain CQ mode: the complexity of the video, the encoder's settings, the encoder's particular algorithm, and the pre-filtering you've done on the video all affect the output bit rate. You can't possibly take all this into account and make an accurate guess at the output bit rate when using a CQ mode.

Variances

There are four variables you can add to any of the three main VBR styles: you can ask it to keep a minimum, maximum or average bit rate, or you can ask it to keep to a given Q level. All of the modes above imply at least one of these variables. Common combinations are:

    1. Simple 1-pass VBR based on average bit rate only.

    2. 1-pass VBR with minimum and maximum bit rate caps. This allows for some variances, but it will not allow the bit rate to stray too far.

    3. 2-pass VBR with minimum and maximum. Unlike the previous mode, the min and max aren't just caps, they're used to modify the encoder's goal-seeking algorithm: the encoder tries to keep to an average of the two limits, so that it never approaches the limits unless it's absolutely necessary. A 1-pass min/max encoder will sometimes blindly bump up against the limits repeatedly, forcing it to sacrifice quality or use extra bits to force the stream to comply with the user's stated goals.

    4. 2-pass VBR with min, max and a fixed Q level. This asks the encoder to try and stick to the given Q level, but when it hits either the upper or lower limits, to adjust the Q level temporarily to stay within bounds. This is useful with things like DVD encoding: the spec says you have to stay over 2 Mbit/s but under 9.8 Mbit/s. This lets you come close to a pure CQ mode without the danger of creating an out-of-spec output stream.

    5. Simple CQ mode: the output bit rate is totally unpredictable, but the quality level will stay constant throughout the video.

Predictability

As you've seen, there are two main parameters an encoder is able to vary: quality and bit rate. With CBR, you've fixed the bit rate to a particular value, so the encoder can only vary the quality level to achieve that bit rate. A 1-pass average-based VBR mode works this way as well: it mainly varies the quality level to manage the bit rate. It will also let the bit rate vary a little as well, but in general, simple VBR encoders won't give a wildly variable bit rate curve.

Modes with adjustable Q levels give the least predictable bit rates. (Or, if you will, they give the best-optimized bit rates for the video conditions.) How "unpredictable" are adjustable-Q modes, exactly? Just as one example, in a previous version of my TMPGEnc review, I reported that I used a quality level of 45 to achieve 3 Mbit/s with my test video. When I revised the review to cover a new version of the encoder, I needed a quality level of 53 to hit the same bit rate with the same video clip. This only goes to show that it's pointless to try and become expert in guessing the Q value required to hit a particular bit rate. Any time the smallest thing changes — the encoder's algorithm, the video's color balance, the video prefiltering setup, or any of a hundred other things — all your hard-won expertise becomes worthless. The best you can do is learn how to minimize the amount of experimentation you require to zero in on an acceptable bit rate.

Your other option is to give the unpredictable modes a miss and use one of the predictable modes: a simple average-based VBR mode, most any N-pass VBR mode, or CBR. The main problem is that these modes usually give worse quality than pure CQ modes. With CBR the encoder is forced to vary the quality level to stick to your chosen bit rate. N-pass VBR is significantly better than CBR mode, but it doesn't give quality as high as the CQ modes. N-pass VBR's real advantage is that it has predictable encoding time as well as a predictable bit rate.

As a compromise, you can choose a modified CQ mode, if one is available to you. If you use a min/max/Q mode, you can set the min and max far apart to mimic a plain CQ mode. Then, by sliding the min and max closer together, you mimic N-pass VBR modes a little better: by giving up absolute quality assurances, you gain the ability to predict the final bit rate a little better. The closer the min and max come together in this kind of encoder, the closer you approach a simple 1-pass average-based VBR mode.

If you have an N-pass VBR mode that allows 3 or more passes, you can approach CQ quality, but with the assurance that you will only have to encode once. (This as opposed to most CQ modes, where you may miss the bit rate target because you chose not to constrain the encoder's min, max or average bit rates. Then you have to adjust your encoding parameters and try again, doubling your effective encode time.)

Working With CQ Modes

Because CQ modes always give better results than regular VBR modes in all the encoders I've tried, I'm willing to tolerate their unpredictability. I prefer the completely unpredictable pure CQ modes to the ones with min/average/max settings, because these latter modes work more like regular VBR modes: the quality level ends up varying to satisfy the min/average/max constraints you've set.

I rarely get the result I want with CQ modes on the first try. Instead, I usually have to make several tries. To avoid re-encoding the entire clip multiple times, I usually do my initial tests on a short but representative sample of the video. Then when I've got that video encoding the way I want it, I use those settings to do the whole video. If I've picked a truly representative test sample, the final output is close to what I expect it to be.

Conclusion

VBR modes are worth using, when you're not forced to use CBR. And when you can get away with it, pure CQ modes are the best VBR types of all. You have to work harder to get good video, but you can achieve absolutely stunning results with a properly-tuned CQ encoder.


Updated Sat Feb 25 2006 22:18 MST Go back to Videographica Go to my home page