Quantizer compression and frame-type offsets
Inside whatever target a rate control mode sets, two further choices decide which frames get the bits. Quantizer compression says how far the quantization parameter (QP) follows a frame's complexity. Frame-type offsets give I, P and B frames different QPs on purpose, because a better reference can lower the cost of the frames predicted from it.
Two rules
This is x264's baseline path, with macroblock-tree off; with it on, which is the default, both rules change, as the list further down says. x264 sets a frame's quantizer scale, which doubles every 6 QP, from its complexity:
scale = complexity^(1 - qcomp)
/ rate factor
With --qcomp at 1 the exponent is 0 and the base level stops following complexity; the frame types still differ. At 0 the scale is proportional to complexity, which makes frames of one type nearly equal in size. The default of 0.6 sits between.
The frame types are then spread around that level. An I frame's scale comes from a running average of recent P frames' QP, divided by --ipratio; the default 1.4 is 2.9 QP lower. A B frame between two P frames gets their QPs averaged by distance, plus an offset from --pbratio; the default 1.3 is 2.3 QP higher. When one of its neighbors is an I frame it starts from the other's QP. A B frame that is itself a reference gets half that offset.
Move the three settings
The sequence is this unit's: quiet, busy, in between, coded at a constant rate factor of 26. Here it has frame types: an I frame where each section starts, then P, B, B repeating. In the upper plot the gray line is the P frames' QP, the teal line the B frames', and the coral dots the three I frames. The lower plot is the size of each P and B frame.
For this sequence at rate factor 26:
- The default ratios are offsets of −2.91 and +2.27 QP, and section averages need not differ by those amounts. In the last section: I 24.9, P 26.0, B 28.3, where the I value is the one frame at the section's start. Set Qcomp to 1, which flattens the base level, to see the offsets directly: I 23.1, P 26.0, B 28.3. B frames are about two thirds of the frames and took 39% of the bits; the stream averaged 400 kbit/s.
- The ratios moved bits between types and changed the total. With both at 1, P and B frames are level at QP 26.0 and the stream is 443 kbit/s. With both at 2, B frames are at QP 32.0, their share is 27%, and the stream is 356 kbit/s.
- Qcomp traded a flat base quantizer for flatter sizes. At 1, P frames are at QP 26.0 in the quiet and the busy sections and average 10.1 and 40.7 kilobits. At 0 their QP is 20.0 and 32.0 and they average 21.6 and 19.0 kilobits.
In x264
--qcomp is 0.6, --ipratio 1.4 and --pbratio 1.3 by default. With macroblock-tree on, which is the default, neither rule above is applied as described: x264 sets the B ratio to 1, and --qcomp sets the strength of macroblock-tree instead.
The grain tuning, macroblock-tree and constant quantizer
- The grain tuning sets the three options to 0.8, 1.1 and 1.1, values that hold quantizers closer together across frames and types.
- What macroblock-tree changes. The B ratio becomes 1, so the configured
--pbratio, the grain tuning's included, is not applied as a fixed offset. The complexity term drops out of the frame's quantizer, and the strength that--qcompgives it is 5 × (1 − qcomp), which makes a related trade block by block. What macroblock-tree does is a later page. - Constant quantizer applies the type offsets too, rounded to whole QPs:
--qpis the P frame QP, and a reference B frame gets the average of the P and B values.
Trade-offs
- Type offsets bet that a better reference helps later frames. Bits spent on an I or P frame can lower the residual cost of the frames predicted from it; they do not guarantee a visible gain in each. When prediction is poor, as with unpredictable detail or changing grain, the bet pays less, which is the direction the grain tuning leans. This demo cannot test the bet: its sizes do not depend on reference quality.
- B frames coded much coarser than their neighbors can show as a pulse. Whether it is visible depends on the content; the demo measures sizes only.
- Even quantizers are not even quality, and even sizes are not either. The same QP leaves more visible error on some content than on other, which is the business of the perceptual tools in the next unit.
Sources
Read 2026-11-15, at the commit linked.
- x264 at commit c24e06c (GitHub mirror): in
encoder/ratecontrol.c, complexity raised to 1 minus qcomp and the macroblock-tree form without it, the quantizer scale for a QP, an I frame's scale divided by the ratio, from the running average of P frame QP (its update), the two ratios as QP offsets, a B frame's QP from its neighbors by distance, the cases with an I frame as a neighbor, plus the offset or half of it for a reference B frame, and the three constant quantizers, the reference B frame under constant quantizer and the B ratio set to 1 with macroblock-tree; macroblock-tree strength from qcomp; incommon/base.c, the default qcomp, ipratio and pbratio, the grain tuning,--qcomp,--ipratioand--pbratio; the options in the command-line list. - Not checked: how the running average of P frame QP behaves over a real sequence; macroblock-tree itself; quantizer offsets by hierarchy level in other encoders; x265's equivalents; any effect on how video looks.