Groups of pictures, open and closed
Rebuilding one intra frame is not the same as being able to carry on from it. A keyframe is a frame the encoder offers as a place to begin decoding, and the frames from one keyframe up to the next form a group of pictures (GOP). The keyframe interval sets how often such entry points come. Whether a GOP is open or closed sets whether prediction may cross them. Both can affect coding efficiency, through different mechanisms.
What a keyframe has to promise
An intra frame needs no other frame for its own reconstruction, but that is not enough: a frame after it could still be predicted from a frame before it. An instantaneous decoding refresh (IDR) frame is an intra frame that also ends that possibility. When x264 codes one it empties its list of reference frames, so nothing after the IDR frame in decoding order can use anything before it. A GOP that starts this way is closed.
The open GOP on this page is x264's. A keyframe after the first is an I frame that is not an IDR frame, and x264 marks it with a recovery point. The B frames shown just before it may use it and the last P frame of the previous GOP. They are coded after the I frame, so a decoder that starts there receives them without the older reference and cannot rebuild them correctly; they come before the starting point in display order. H.264 can also signal a gradual recovery with no whole intra frame, which this page does not cover.
Build a sequence and follow a frame's needs
Sixteen frames are laid out twice: in display order, and in the order they are coded. Choose the keyframe interval, the most B frames in a row and the kind of GOP, then move Frame along. The chosen frame has a dark outline, and every frame it depends on, directly or through its references, stays solid while the rest fade. The numbers under the boxes are display positions. The dashed outline marks the last keyframe coded at or before the chosen frame, and the last readout says whether the chosen frame needs anything coded before it; if so, a decoder starting at that keyframe cannot rebuild the frame. Start with Frame at 8 and switch GOP between Open and Closed, then try frame 9.
With an interval of 8 and up to 2 B frames:
- Open: frame 8 is a B frame that needs frames 1, 4, 7 and 9. It is predicted from frames 7 and 9. Frames 1, 4 and 7 are coded before frame 9, the next GOP's I frame, so a decoder that starts at frame 9 cannot rebuild frame 8; showing it means decoding from frame 1.
- Closed: frame 8 is a P frame that needs frames 1, 4 and 7. Frame 9 is an IDR frame, and no frame is predicted across it. The sequence has 6 P frames and 8 B frames; open has 5 and 9. That extra B frame belongs to this pattern: with B frames at 0, open and closed give the same dependencies.
- Coded order moves each reference ahead of the B frames that use it. Open, the order begins 1, 4, 2, 3, 7, 5, 6, 9, 8.
- A shorter interval means more keyframes, open or closed. At 4 frames this sequence has 4 of them; at 16 it has 1.
The settings
- x264
--keyintis the longest distance between keyframes, 250 frames by default.--min-keyintis the shortest distance at which x264 turns an I frame it has placed into a keyframe: by default the smaller of a tenth of--keyintand the frame rate. An I frame that falls closer than that to the last keyframe, for instance at a scene cut, stays a plain I frame and does not start a new GOP. The rule covers x264's own placement: a frame given to x264 as IDR closes the GOP at any distance. - x264
--open-gopis off by default. In x265--open-gopis on by default, with the same 250 for--keyint.
Trade-offs
- Keyframes cost bits and buy entry points. A viewer joining a live stream cannot begin before a keyframe arrives. Showing a frame in the middle of a GOP means decoding forward from a keyframe before it, so a shorter interval shortens that run. The previous page's cat needed more levels as intra than with a reference one frame away.
- In this pattern an open GOP keeps a B frame where a closed one needs a P frame. In exchange, a decoder starting there must discard the B frames that reach back. Where streams are cut or switched at keyframes, closed GOPs avoid that.
- A correctly decoded IDR frame stops earlier reference errors. Nothing after it in decoding order uses anything before it, so corruption in an earlier reference cannot carry past it through prediction. It does not repair a lost IDR frame or later damage.
Sources
Read 2026-11-15, at the commits linked.
- x264 at commit c24e06c (GitHub mirror): in
encoder/encoder.c, the reference list emptied at an IDR frame, a recovery point written with a keyframe that is not an IDR frame, its count zero for an open GOP and the default shortest interval; inencoder/slicetype.c, the keyframe at the longest interval, IDR or I, an I frame far enough from the last keyframe becoming one, a frame type taken from the caller, the GOP closed at any IDR frame and the B frame before an IDR frame turned into a P frame; incommon/base.c, the defaults,--keyint,--min-keyintand--open-gop; the options in the command-line list. - x265 at commit 4191822, defaults only:
--keyintand--open-gop. - RFC 6184, the RTP payload format for H.264 video, read as extracted text through a fetch tool, not as the document itself: sections 4.1 and 4.2 for the definition of an IDR picture and the words the abbreviation stands for, and section 8.5.2 for gradual recovery signaled with a recovery point.
- Not checked: the H.264 specification's text on IDR frames, recovery points and which pictures a decoder may discard; x264's
--intra-refresh, which replaces keyframes with a moving band of intra blocks; how players and packagers treat open GOPs; x265's code beyond the two defaults.