Back to Blog
GOP Architectures & Frame Types: The Engineering Mechanics of I, P, and B-Frames
Dilip NayakMay 20, 202618 min readCodec Engineering

Public media guide

GOP Architectures & Frame Types: The Engineering Mechanics of I, P, and B-Frames

An engineering deep-dive into Group of Pictures (GOP) structures: IDR intra-frames, forward predicted P-frames, bidirectional B-frames, closed vs open GOP tradeoffs, and keyframe tuning.

Raw video is an extremely redundant signal. In a typical 60 frames-per-second video stream, 95% or more of visual information in any given frame is virtually identical to the frame immediately preceding it.

To achieve the massive 50:1 to 200:1 compression ratios that make digital video streaming possible, modern video compression standards (including H.264, HEVC, and AV1) rely on inter-frame prediction structured into a Group of Pictures (GOP).

Inside a GOP, frames are categorized into three fundamental picture types: Intra-coded frames (I-frames), Predictive frames (P-frames), and Bidirectionally predictive frames (B-frames). How an encoder arranges these frame types directly determines compression efficiency, seek latency, error resilience, and decoding memory footprints.

This technical guide breaks down the motion compensation mathematics of temporal prediction, contrasts Open vs Closed GOP topologies, and provides battle-tested FFmpeg recipes for live streaming and archival pipelines.

1. The Frame Hierarchy: Intra vs Inter Picture Types

The compression pipeline partitions a raw frame sequence into a repeating cadence of anchor frames and motion-compensated difference vectors.

  • Intra-Coded Frames (I-Frames): Encoded independently using purely spatial (intra) prediction. They consume the largest number of bits (often 5x to 10x larger than P-frames) but are required to initialize playback.
  • Predictive Frames (P-Frames): Use motion estimation to find matching macroblocks in previously decoded frames. Only the motion vector coordinates and residual prediction error are saved.
  • Bidirectional Predictive Frames (B-Frames): Reference both past and future anchor pictures. By averaging motion from two directions, B-frames suppress noise and reduce bit allocation to minimal levels.

2. Closed GOP vs Open GOP Architecture

The boundary rule governing inter-frame reference dependencies distinguishes Open GOP from Closed GOP topologies.

  • Closed GOP: No frame inside the GOP may reference any picture outside its boundaries. Every Closed GOP begins with an IDR frame. This is mandatory for HLS and DASH adaptive streaming because segments can be spliced seamlessly.
  • Open GOP: B-frames immediately following the initial I-frame are permitted to reference the trailing P/B-frames of the preceding GOP. This yields 5% to 8% higher compression efficiency but creates dependency chains that complicate random-access seeking.
  • Adaptive GOP Length (Scene Cut Detection): Advanced encoders dynamically insert an IDR frame upon detecting major scene changes, preventing inefficient P-frame compensation across discontinuous visual cuts.

3. Hierarchical B-Frame Pyramids & Decode Reordering

Because B-frames reference future frames, the order in which frames are decoded (Decode Order) differs from the order in which they are displayed on screen (Presentation Order / PTS).

  • Presentation Order: I0 -> B1 -> B2 -> P3 -> B4 -> B5 -> P6
  • Decode Order: I0 -> P3 -> B1 -> B2 -> P6 -> B4 -> B5 (future references must be decoded into reference buffers before dependent frames can be reconstructed).
  • Pyramid Structures: Modern encoders designate select high-quality B-frames as references for other B-frames (b-pyramid in x264/x265), maximizing compression while keeping reference latency bounded.

Format & Use Table

PropertyI-Frame (Intra)P-Frame (Predicted)B-Frame (Bi-directional)
Reference DependencyNone (Self-contained)References preceding I/P framesReferences past and future I/P frames
Relative Bit SizeHighest (Baseline 100%)Moderate (20% to 35% of I-frame)Lowest (5% to 15% of I-frame)
Random Access SeekingDirect seek point (instant)Cannot seek without prior I-frameCannot seek without prior I/P frames
Encoding ComplexityLow (spatial only)Moderate (unidirectional search)High (bidirectional vector search)
Primary FunctionRecovery anchor, scene cut, seek headTemporal tracking across motionMaximum data compaction in stable scenes

Step-by-Step Workflow

01

Inspect frame types of an MP4 using ffprobe: ffprobe -show_frames -select_streams v:0 -show_entries frame=pict_type,pts_time input.mp4

02

Enforce fixed 2-second Closed GOP for HLS: ffmpeg -i raw.mov -c:v libx264 -g 60 -keyint_min 60 -sc_threshold 0 -flags +cgop hls_ready.mp4

03

Configure 4-level B-frame pyramid for archival: ffmpeg -i raw.mov -c:v libx265 -crf 20 -bf 4 -b-pyramid 1 archive.mp4

04

Analyze frame distribution with grep: ffprobe -select_streams v -show_frames input.mp4 | grep pict_type | sort | uniq -c

Frequently Asked Questions

Why does live streaming require shorter GOP lengths than VOD?

Live streaming requires low latency (typically 2-second or 1-second GOPs) so new viewers can tune in and begin decoding almost instantly. Long GOPs (such as 10 seconds) delay player startup by several seconds until the next keyframe arrives.

What is the difference between an I-frame and an IDR frame?

All IDR frames are I-frames, but not all I-frames are IDR. An IDR frame completely purges the decoded picture buffer (DPB), strictly guaranteeing that no subsequent frames can reference pictures prior to the IDR. Standard non-IDR I-frames allow reference overlap in Open GOP structures.

#GOP structure#I-frames#P-frames#B-frames#IDR frames#motion estimation#video encoding#FFmpeg

Related Articles