encoding.info
You are hereSourcePredictionTransformEntropy codingFiltersFramesDecisionsRate controlPerceptionQualityBitstreamSettingsEncoder map
Page 4 of 4 in Frame structure

Scene cuts and lookahead

Frame structure · concept · added 2026-11-15

In Brief:
At a scene change, prediction from earlier frames may stop saving much. The encoder compares a frame's estimated cost as intra and as predicted to decide where to place an intra frame. A frame it flags does not always become a keyframe, and a fade can pass the test.

When the picture changes from one frame to the next, predicting from the earlier frame may save little, and the new frame may be better coded as an intra frame. To decide, an encoder estimates what the frame would cost as intra and as predicted from an earlier frame, and compares. Frames further ahead help it tell a lasting change from a short flash. The same lookahead decides where B frames go.

The test x264 uses

In its lookahead, x264 estimates two costs for a frame: its I cost, as if every block were intra, and its P cost against an earlier frame, in which each block takes the cheaper of intra and inter. Both are estimates, not bits. Since the P estimate can already take intra for a block, a P cost close to the I cost means inter prediction saves little. The frame is a scene cut if

P cost >= (1 - bias) x I cost

The bias comes from --scenecut, and it grows with the distance from the last keyframe, so x264 is slow to call a cut right after a keyframe and readier as the group of pictures ages. With the defaults (--scenecut 40, --keyint 250, --min-keyint 25 at 25 frames a second) the bias is 0.025 just after a keyframe, 0.1 at 25 frames and 0.4 at 250. With an I cost of 100 and a bias of 0.1 the level to reach is 90: a P cost of 60 is well under it, and 95 passes.

Find the cuts

Thirty-six frames: the cat walks; from frame 15 to frame 20 the picture is the cat upside down and in negative, which makes two cuts; from frame 27 the picture fades darker by 24 levels a frame for six frames. The abrupt changes were made easy to see: they show the test, not how well x264 finds cuts. The bars are each frame's modeled P cost, against the frame before, divided by its modeled I cost. The teal line is the level a bar must reach, one minus the bias. Coral bars are frames the test flags. The experiment assumes closed groups of pictures and no B frames: a flagged frame becomes an instantaneous decoding refresh (IDR) frame, starting a new group, only if at least Min-keyint frames have passed since the last keyframe; otherwise it is an I frame that is not a keyframe. With open groups x264 would keep an eligible frame as an I frame and mark it as a keyframe.

40
← 0: off100: readiest to cut →
25
← keyframes may be closekept far apart →
Frame
P cost ÷ I costthe same, where the test flags the frameneeded for a cut
15
← frame 2frame 36 →
Previous
This frame
Cheaper as
coral blocks: cheaper as intra teal blocks: cheaper from the previous frame
P cost ÷ I cost
Needed for a cut
Frame type
Frames flagged
Simplified demo: the pictures are invented and the costs are modeled. For each 8×8 block the intra cost is the sum of absolute differences from the block's own average, not from a prediction built out of neighboring pixels, and the inter cost is the sum from the same block of the previous frame, with no motion search; x264 uses transformed differences on half-resolution frames, with motion search and penalties. The cut test and the bias are x264's formula, with --keyint fixed at 250. Not modeled: the extra frames x264 examines to avoid calling a short flash a cut, B frames and open groups of pictures. A frame the test does not flag is shown as P. The two ratio readouts are rounded to three decimals.

For these frames:

The lookahead's other job, and its settings

Trade-offs

Sources

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