Macroblock-tree and 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.
With 12 frames of lookahead and qcomp 0.6:
- The still background was lowered 6.6 QP, the half-predicted block 2.0, and the new content not at all. In this model the background holds nearly all the value of every frame predicted from it.
- The effect depends on how far the encoder can see. With 3 frames of lookahead the background's offset is −3.8; with none it is 0, since this model does not extrapolate. The half-predicted block is already at −1.8 with 3 frames, because half of what it holds is lost at every step back.
- Frames near the end of the lookahead get less. The same background block 10 frames on, with 2 frames left to see, gets −3.0. In a real encode the window moves, so every frame is "now" in its turn.
- Qcomp scales everything. At 0.6 the strength is 2.0. At 1 it is 0 and the offsets vanish, and x264 turns macroblock-tree off there; at 0 it is 5 and the background's offset is −16.4.
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
- The ultrafast and superfast presets and the zerolatency tuning switch macroblock-tree off as well. x264 also has a restricted path with no lookahead, which it allows only with intra refresh or an infinite keyframe interval; the demo does not simulate it.
- With macroblock-tree running,
--qcompno longer acts as the ordinary frame-complexity exponent, and it also enters the rate factor's calibration. x264 also sets the B frame ratio to 1, and at--qcomp1 it turns macroblock-tree off. Frame QPs still differ. - When a block is coded, its stored offset is added to the frame's base QP, then rounded and clipped. A frame that is not a reference gets adaptive quantization's offset alone.
- For x265's
--cutree, the name and the default are all this page claims.
Trade-offs
- It favors blocks estimated to be useful references, not still ones as such. A moving object can stay predictable, and a still region with changing noise can be hard to predict. The offsets here only lower QP; rate control can compensate elsewhere, especially when working toward a bitrate, and the total size can change. Whether the result looks better on given content was not measured here.
- It depends on the estimates. The costs come from the lookahead's half-resolution search. Where that search is wrong, value is passed to the wrong place.
- It overlaps with other tools. Adaptive quantization also moves QP block by block, for a different reason, and the final offset is the sum of the two. They are not independent: adaptive quantization's offsets also weigh the costs being passed back.
Sources
Read 2026-11-15, at the commits linked.
- x264 at commit c24e06c (GitHub mirror):
mbtree_propagate_costwith the inter cost limited to the intra cost, the inverse quantizer and duration factors and rounding and saturation, andmbtree_propagate_list, which shares the amount among the blocks a vector overlaps; inencoder/slicetype.c,macroblock_tree_finishwith the strength, the logarithm and the offset added to adaptive quantization's, and the walk over the lookahead and the path with no lookahead; inencoder/ratecontrol.c, the offset applied to a block's QP, the rate factor's calibration with macroblock-tree and the B ratio and the exponent set to 1; inencoder/encoder.c, macroblock-tree off at a quantizer compression of 1 and without a lookahead unless intra refresh or an infinite interval is set; incommon/base.c, the default, ultrafast, superfast, zerolatency and the option;--no-mbtreein the command-line list. - x265 at commit 4191822, default and option only:
--cutreeon and its parsing. - Not checked: the order of the walk with B frames and reference B frames; what the weighted-prediction and frame-duration terms do in practice; the path with no lookahead beyond its place in the code; x265's coding-unit tree beyond its default; any effect on how video looks or on any metric.