encoding.info
You are hereSourcePredictionTransformEntropy codingFiltersFramesDecisionsRate controlPerceptionQualityBitstreamSettingsEncoder map
Page 3 of 4 in Rate control

Two-pass encoding and complexity estimation

Rate control · concept · added 2026-11-15

In Brief:
One-pass rate control works from the frames and the limited lookahead available so far. For stored video, a first pass can collect statistics across the whole sequence. A second pass uses those estimates to plan a bitrate budget, and corrects when actual sizes differ from the plan.

An encoder working in one pass has to decide each frame's quantizer before it has seen the rest of the video, beyond a limited lookahead. If the whole file is available, it can encode twice: a first pass to measure how hard every frame is, and a second that spends a fixed budget with that knowledge. The second pass plans from estimates, not certainties, so it still corrects as it goes.

What the first pass leaves behind

x264's first pass writes a line of statistics for every frame: its type, the quantizer it used, and the bits it spent on residual, on motion and on everything else. From those x264 can estimate how a frame's size would change at another quantizer. Its complexity measure is the bits predicted at a quantizer scale of 1, without the bits for everything else, adjusted for the frame's duration. It smooths that over neighboring frames, and then looks for a single rate factor: the one number that, applied to every frame's smoothed complexity, makes the predicted total equal the target, subject to its other limits. That is the same formula constant rate factor uses, with the constant found by search and not given. While it encodes, the second pass compares the bits spent with the plan and corrects when they diverge.

Same target, one pass and two

The sequence is the one from the earlier pages of this unit: quiet, busy, then in between. Compare the earlier one-pass controller, x264's average bitrate feedback, with an ideal planner that is given the whole sequence's complexity, shown as Two passes. Both aim at the bitrate you set. The planner predicts sizes with the same formula that generates them, so it can hit the target almost exactly; real first-pass statistics only estimate second-pass sizes. As on the earlier pages, macroblock-tree is off and there are no frame types. The plots show the quantization parameter (QP) and size of each frame.

700
← 300 kbit/s1,200 kbit/s →
one passtwo passes
One passTwo passes
Average, kbit/s
QP, quiet section
QP, busy section
QP, medium section
One pass, off target
Two passes, off target
QP spread, one and two
Simplified demo: complexities are invented and a frame's size is modeled exactly, so the second pass's plan comes true to the bit; a real second pass works from the first pass's measurements, which were made at other quantizers, and x264 corrects as it goes. The smoothing weights (falling off as exp(−j²/200) over up to 40 frames each way) and the search for one rate factor follow x264's second-pass planning, with --qcomp 0.6. x264 also multiplies each weight by a running factor from the share of intra-coded blocks, which ends the smoothing at a frame that is all intra; the demo leaves that out and smooths across every boundary. Not modeled: frame types, the further smoothing of quantizers, and the buffer limit. QP spread is the highest QP of any frame minus the lowest.

At a target of 700 kbit/s:

The settings in x264

--pass 1 writes the statistics file and --pass 2 reads it. The second pass needs --bitrate.

The file, the smoothing options and constant rate factor
  • --stats names the statistics file.
  • --cplxblur (default 20) sets the extent of the complexity smoothing, and --qblur (default 0.5) smooths the resulting quantizer scales among frames of the same type.
  • x264 offers no second pass for constant rate factor: that mode needs no total to aim at.

Trade-offs

Sources

Read 2026-11-15, at the commit linked.