Dictionary

What Are B-Frames in a Video?

A B-frame is a video frame that can use both an earlier and a later frame. Learn how B-frames work and what the Has B Frames value in your file means.

b-frames

A B-frame is a video frame that can use both an earlier frame and a later frame to build its picture. The B stands for bidirectional. B-frames offer more compression than the other frame types, which helps keep a video small.

In a video file's metadata, you may see a field called Has B Frames, also written has_b_frames. The name suggests a yes or no answer, but the value is a number. The number tells you how many frames a decoder must be able to keep in memory to show the video in the right order.

How B-frames differ from I-frames and P-frames

Video compression generally works by comparing frames and recording the differences between them. MPEG-2 video defines these 3 frame types:

  • I-frame: coded without reference to other frames, so decoding can start here
  • P-frame: can use the previous I-frame or P-frame
  • B-frame: can use the previous and the next I-frame or P-frame

A B-frame can depend on a frame that comes later in time, so that later frame must be stored first. The stored order therefore differs from the order you see on screen. A typical MPEG-2 sequence looks like this:

  • Display order: B1 B2 I3 B4 B5 P6 B7 B8 P9 B10 B11 P12
  • Stored order: I3 B1 B2 P6 B4 B5 P9 B7 B8 P12 B10 B11

What the values look like

Has B Frames is a whole number. FFmpeg describes the value as the size of the frame reordering buffer in the decoder. For MPEG-2 video, FFmpeg names 2 values:

  • 0: low delay video with I-frames and P-frames only
  • 1: video with I-frames, P-frames, and B-frames

H.264 and HEVC encoders can also keep some B-frames as references for other frames. FFmpeg's test files for H.264 show how this changes the value. The file names give the encoder settings:

  • At most 3 B-frames in a row, none kept as references: 1
  • At most 3 B-frames in a row, some kept as references: 2
  • At most 4 B-frames in a row, some kept as references: 2

So the value is not a count of B-frames. The ffprobe program shows the type of each frame as a pict_type value: I, P, or B. The field NB Frames gives the number of frames, but not their types.

Where the value comes from

The field name comes from FFmpeg, whose ffprobe program prints has_b_frames for video streams. An H.264 stream can state the number in its own header. If the header does not state the number, FFmpeg works it out from the frames and their times.

The encoder settings decide whether a video uses B-frames. In FFmpeg and in the Microsoft H.264 encoder, a setting of 0 turns B-frames off.

Which files carry it

The field exists for video streams only. You can see the field for video in MP4, MOV, MKV, WebM, and AVI files. A MOV file with reordered frames also stores a table with the time between decoding and display for each frame.

The codec decides whether B-frames are possible. MPEG-2 video and the H.264 Main profile can use them, but the H.264 Baseline profile cannot. VP8, a codec used in WebM files, has no B-frames, because its frames are never predicted from later frames.

Why it matters

B-frames help keep a video small, but they add delay. The encoder must reorder frames before it stores them, and this delay depends on the number of B-frames in a row.

Reordered video also has 2 different times for each frame: when to decode the frame and when to show it. FFmpeg gives both as timestamps in the stream's time base.