Intra, predicted and bidirectional frames
A frame can be predicted in three ways, and each way gives the frame a type. An intra (I) frame uses only pixels of its own picture. In a predicted (P) frame a block may also be predicted from a frame decoded before it. In a bidirectional (B) frame a block may also combine two such predictions, often one from a frame shown before it and one from a frame shown after it. The types differ in how much is left to code and in what a decoder must already have.
Three types, two orders
The names describe what a frame is allowed to use, not what every block does. A block in a P or B frame can still be coded as intra when nothing in the references matches it, and a block in a B frame can use a single prediction. Blocks of one frame can also use different references. x264 sets a slice type from each frame's type; this page uses I, P and B as names for whole frames.
Code one frame three ways
The cat walks a third of a pixel per frame. The demo codes frame 13 of the walk at quantization parameter (QP) 28, three ways. Intra predicts each 4×4 block from the reconstructed pixels above and to its left. P copies the block from the frame Distance frames earlier. B takes, block by block, the earlier frame, the frame the same distance later, or their average, whichever has the smallest sum of absolute differences from the source. Neither P nor B falls back to intra here, as a real encoder's blocks can. There is no motion search, so a reference further away is a worse match. Type chooses the frame shown in the four pictures; the table always lists all three types at the chosen Distance. It counts nonzero levels, the integers left after quantization, and gives the error: the mean squared error of the reconstruction against the source, in squared 8-bit levels.
| Type | Nonzero levels | Error |
|---|---|---|
| Intra (I) | ||
| Predicted (P) | ||
| Bidirectional (B) |
For this cat at QP 28:
- With references one frame away, P left fewer levels than intra, and B far fewer. Intra 363, P 252, B 88. Of B's 64 blocks, 53 took the average of the two references.
- Averaging helped because the motion was steady. The earlier frame is a third of a pixel behind and the later one a third ahead, so their average lands close to the frame between them.
- With this forced copy and no motion search, a distant reference was no better than intra. At distance 2, P left 362 levels against intra's 363, and at distance 4 it left 446. B at distance 4 left 324.
- At this fixed QP the error stayed between 10.95 and 12.99, while the level counts ran from 88 to 446. The quantization step strongly influences the error, but the residual and how it quantizes matter too.
The types in x264
x264 normally keeps I and P frames as references for later frames and marks an ordinary B frame as disposable: nothing is predicted from it. Leaving such a frame out takes no reference away from another frame, but it does remove a moment from what is shown. --bframes sets the most B frames x264 will place in a row, 3 by default; the lookahead decides how many to use at each point. The ultrafast preset, the zerolatency tuning and the Baseline profile set it to 0, veryslow uses 8 and placebo 16. x265's default is 4. B frames that are kept as references are the subject of Hierarchical B-frames.
Trade-offs
- B frames that use a later frame add delay. The encoder must wait for that frame, and the decoder receives it before showing the B frame, as in the drawing above. x264's zerolatency tuning sets
--bframesto 0. - An I frame needs no other frame for its own reconstruction, given the stream's headers. That does not guarantee the frames after it can be decoded from the same starting point; the next page separates an ordinary I frame from a keyframe. Here intra left more levels than P or B with references one frame away.
- The gain depends on the match. Steady motion suits averaging. A reference that matches badly can be worse than intra, as this demo's forced copy was at distance 4. A real encoder searches for motion and chooses per block.
Sources
Read 2026-11-15, at the commits linked.
- x264 at commit c24e06c (GitHub mirror): in
encoder/encoder.c, I frames and P frames marked as references, ordinary B frames as disposable, and the slice type set from the frame's type (I, P, B); incommon/macroblock.h, the macroblock types of a B frame; incommon/base.c, the default of 3,--bframes, ultrafast, veryslow, placebo, zerolatency and the Baseline profile; the option in the command-line list. - x265 at commit 4191822: the default of 4.
- Not checked: any specification text on slice and frame types, including H.264's definitions of I, P and B slices; how x264 codes a bidirectional block (direct modes, weighted averages, motion vectors); how its lookahead chooses the number of B frames; the claim that a B frame needs a later frame is by construction of the diagram, and real B frames may also use two earlier frames.