encoding.info
You are hereSourcePredictionTransformEntropy codingFiltersFramesDecisionsRate controlPerceptionQualityBitstreamSettingsEncoder map
Page 4 of 6 in Perceptual optimization

Macroblock-tree and coding-unit tree

Perceptual optimization · concept · added 2026-11-15

In Brief:
Some blocks help predict many later frames. Macroblock-tree estimates that reuse in x264's lookahead and gives useful reference blocks a lower quantization parameter relative to the frame's base level. It works from estimates of prediction cost, not from how the result looks. x265 calls its counterpart coding-unit tree.

Some blocks are seen once. Others, like a still background, are used to predict many later frames, and a bit spent improving such a block can save coding work in each frame that depends on it. Macroblock-tree, in x264, and coding-unit tree, its counterpart in x265, estimate for each block how useful it is as a reference and lower its quantization parameter (QP) accordingly, relative to the frame's base level.

Passing value backward

The lookahead already has, for every block of every coming frame, an estimated intra cost and inter cost. Macroblock-tree walks those frames from the last to the first. In a simplified form of x264's rule, a block passes back to the block it was predicted from a share of what it holds:

passed back = (intra cost + received)
              x (intra - inter) / intra

The fraction estimates how much cheaper predicting the block from its reference is than intra coding, and the rule uses that saving as a weight. If the inter cost is near zero, prediction was very cheap under this estimate, and almost all the block's value, including what later frames passed to it, goes back. If the inter cost equals the intra cost, the reference saved nothing and nothing goes back. A block's QP is then lowered by the logarithm of how much it ended up holding:

QP offset = -strength x log2(share)
share = (intra + received) / intra

With an intra cost of 1,000 and an inter cost of 500, the last block passes 500 back. The block before it then passes (1,000 + 500) × 0.5 = 750. Over many steps the amount received approaches 1,000 and the share 2, so a strength of 2 gives an offset approaching −2 QP.

Follow three kinds of block

Three blocks are followed through the frames ahead, with no motion: a still background whose inter cost is 5% of its intra cost (a value chosen for the demo), a block that is new in every frame (100%), and one in between that you set. Each row shows the QP offset the block would get in the frame being coded ("now") and in the frames after it, given the lookahead left to each. Darker is a larger drop. The grid shows only the extra macroblock-tree offset, relative to a base QP: zero means no extra reduction. Rate control sets the base level; this experiment computes no final QP, no bitrate and no redistribution of a fixed budget.

12
← 0 frames: no future known12 frames →
50%
← 0%: zero inter cost100%: no saving over intra →
0.6
← 0: strongest1: off →
Still background
Middle block
New every frame
Strength
Simplified demo: the two formulas are a simplified form of x264's rule in continuous arithmetic, and the strength, 5 × (1 − qcomp), is x264's. x264 also limits the inter cost to the intra cost, scales by inverse quantizer factors and frame duration, rounds and saturates, and adjusts for weighted prediction; here those are normalized away. Invented: every block has the same intra cost, each block is predicted only from the same block of the frame before, and the costs do not change from frame to frame. Not modeled: motion, which splits what is passed back among the blocks a vector overlaps; B frames and two references; adaptive quantization, whose offset this one is added to and whose quantizer factors also weigh what is passed back; frame durations. The first three tiles are the QP offsets for the frame being coded.

With 12 frames of lookahead and qcomp 0.6:

In x264 and x265

x264's macroblock-tree is on by default, and --no-mbtree turns it off. Ordinarily --rc-lookahead limits the future it can use, and with it on --qcomp sets its strength. x265's --cutree is on by default; its code was not read.

Presets, the path with no lookahead, qcomp and block QP

Trade-offs

Sources

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