Scene cuts and lookahead
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.
--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 two abrupt changes stand far above everything else. Frames 15 and 21 have a ratio of 1.000: every block was cheaper as intra. A walking frame is between 0.133 and 0.205.
- At the defaults both are flagged, and both become I frames that are not keyframes. Frame 15 is 14 frames after the first keyframe, under the Min-keyint of 25. With Min-keyint at 4 both become IDR frames.
- The fade is flagged only at high settings. Its frames reach 0.686 to 0.779. At Scenecut 100 with Min-keyint 25, frame 27 needs 0.747 and is flagged; at 40 it needs 0.899 and is not.
- The needed level depends on what was flagged earlier. Each new keyframe restarts the count that the bias is computed from; in this experiment the keyframes are IDR frames.
The lookahead's other job, and its settings
--rc-lookaheadsets how far ahead x264's rate control and frame planning look: 40 frames by default, 0 in the ultrafast and superfast presets, 60 in slower and above. It is not the total delay: x264 counts it into its input delay only when macroblock-tree or a buffer limit is on, and B frames and threads add their own. At 0 the cut test and the B frame decisions still run: superfast sets it to 0 and leaves--scenecutand--b-adaptat their defaults.--scenecutis 40 by default; 0,--no-scenecutor the ultrafast preset turns the test off. x265 uses the same default of 40.--b-adaptchooses how the lookahead places B frames: 0 uses a fixed pattern, B frames up to the limit and then a P frame, cut short at keyframes and at the end of the video; 1 (the default) is a fast decision, 2 searches over patterns and is used by the slower presets. Both adaptive modes work from the same estimated costs as the cut test.
Trade-offs
- A missed I frame and an extra one can both change efficiency. A P frame may use intra blocks, and many may be chosen where inter prediction is poor. An extra I frame is placed where prediction might have worked, as a setting of 100 does on this fade. The experiment flags frames without encoding them, so it measures neither bits nor quality.
- Lookahead is delay and memory, but not one number. x264's zerolatency tuning sets
--rc-lookaheadto 0 and also turns off B frames, the threaded lookahead's buffer and macroblock-tree. - The estimate is not the encode. x264 decides from half-resolution source frames. How often that disagrees with the full encode was not measured.
Sources
Read 2026-11-15, at the commits linked.
- x264 at commit c24e06c (GitHub mirror): in
encoder/slicetype.c,scenecut_internalwith the two costs, the threshold from--scenecut, the three cases of the bias and the test; a block of the P estimate taking intra when it is cheaper; the extra checks against flashes; the test applied, when the threshold is not zero, and the frame made an I frame; an I frame becoming a keyframe only at the shortest interval or beyond, as an I frame with open groups and as an IDR frame with closed ones; a run of B frames ended at the limit or at the last frame; the pattern search and the fast decision for B frames; incommon/base.c, the defaults, the lookahead default, ultrafast, superfast, slower, zerolatency,--scenecut,--b-adaptand--rc-lookahead; the default shortest interval; inencoder/encoder.c, the input delay built from B frames and the pattern search, the lookahead when macroblock-tree or a buffer limit is on and threads; the three B frame modes; the options in the command-line list. - x265 at commit 4191822, default only:
--scenecut. - Not checked: how x264 computes the two cost estimates in full (only the choice between intra and inter per block was read); the flash checks beyond their existence; how the two adaptive B frame modes decide; the lookahead's use by macroblock-tree and rate control, which later pages cover; x265's scene-cut code; how often the estimate disagrees with the full encode.