Intra prediction
Intra prediction estimates a block from samples of the same picture that are already reconstructed, mostly the row above it and the column to its left. The difference between the source and the prediction is the residual, which is what usually goes on to the transform. The encoder names the mode it used and codes the residual. It is the encoder copying its neighbor's homework, which is allowed here because the decoder sits next to the same neighbor.
Which samples a mode may read
The decoder has to form the identical prediction, so a mode may read only samples the decoder already holds in reconstructed form. Those mostly lie above and to the left. Some modes reach further along the same edges: two of x264's nine 4×4 modes read above and to the right, and x265's planar mode reads one sample above-right and one below-left. Where a neighbor is missing, as at a picture edge, the codec substitutes: x264's average mode has versions for a missing top, a missing left, or both. Every intra mode is a rule for extending the available edge samples across the block.
Try the modes
Pick a block and a mode. In the Source and Prediction panels the samples outside the teal line are the neighbors; the Prediction panel fades those the chosen mode does not read. The demo uses source samples as neighbors and assumes all of them are available; a real encoder uses reconstructed neighbors, which can already carry coding error. The residual panel is mid-gray where the prediction is exact and lighter where the source is brighter. The score is the sum of absolute differences (SAD): the absolute difference between each source sample and its prediction, added up.
- For these blocks, the mode that matches the structure has the lowest score. Stripes: vertical 602 against 3,672 for horizontal. Bands: horizontal 626 against 3,560 for vertical. Diagonal edge: diagonal 142, with planar next at 1,755. Gradient: planar 952, with vertical next at 1,449.
- A mismatched direction can score worse than no direction. On the stripes, horizontal scores 3,672 and the plain average 3,528.
- None of these five rules predicts this noise block closely. Its five scores run from 1,915 to 2,681, and the lowest is the average. There is nothing in the neighbors that says what an independent pixel will be.
A low SAD is a ranking score, not a bit count: the demo counts no bits for naming the mode or for coding the residual. More on Distortion measures.
Intra modes in x264
x264 has nine modes for 4×4 and 8×8 luma blocks (vertical, horizontal, average and six diagonals) and four for 16×16 luma and for chroma (vertical, horizontal, average and plane). Its fast ranking scores each mode as a distortion measure plus an estimated cost for naming the mode. The mode itself is predicted: for a 4×4 block the expected mode is the smaller-numbered of the modes used to the left and above, or the average mode when either is unavailable, and any other mode adds 3 × lambda to the score. Lambda is the weight x264 puts on a bit; see Rate-distortion optimization. The 3 is the extra bits x264's variable-length coder writes for an unexpected mode; the arithmetic coder's cost is not fixed. It is a ranking estimate: from --subme 6 the leaders are compared again by reconstruction-based cost. --partitions selects which block sizes are tried; i8x8 is dropped when the 8×8 transform is off.
| Codec | Block | Modes |
|---|---|---|
| H.264 (x264) | 4×4, 8×8 luma | 9 |
| H.264 (x264) | 16×16 luma, 4:2:0 chroma | 4 |
| HEVC (x265) | luma | 35 |
The 35 in x265 are planar, average and 33 directions. Block sizes per codec are on Block partitioning.
Trade-offs
- A mode cannot read samples that are not available. If a new feature has no continuation in the available neighbors, these modes can leave a large residual.
- More modes mean more candidates to evaluate, and a cost for naming the one chosen. Each candidate costs encoder time. x264's 3 × lambda is its fast estimate of the naming cost.
- The prediction can only be as good as the neighbors. An encoder predicts from reconstructed pixels, so quantization error in the neighbors is carried into the prediction. The demo uses source pixels and does not show this.
- A useful reference picture can make inter prediction more economical. When an earlier frame holds the same content, motion compensation often leaves a smaller residual. Not measured on this page.
Sources
Read 2026-11-13, at the commits linked.
- x264 at commit c24e06c (GitHub mirror): the mode lists for chroma, 16×16 and 4×4, the neighbors each 4×4 mode needs,
x264_mb_predict_intra4x4_mode, the 1-bit and 4-bit mode lengths, where reconstruction-based decision starts, the 3 × lambda mode cost,mb_analyse_intra, wherei8x8is dropped without the 8×8 transform. - x265 at commit 4191822:
NUM_INTRA_MODEthe planar, average, horizontal and vertical indexes and the planar rule. - Not checked: the H.264 and HEVC specifications, how x265 searches its modes, the neighbor smoothing either codec applies, chroma formats other than 4:2:0, the bits the arithmetic coder spends on a mode, and AV1. The trade-offs are general reasoning, not measurements.