How to Extract B-Frames Using FFmpeg Select Filter

This article explains how to use the FFmpeg select video filter to isolate and extract B-frames (bi-directional predictive frames) from a video file. You will learn the exact command-line syntax required to save these frames as a sequence of images or compile them into a new video file.

Understanding the Select Filter for B-Frames

In video compression, B-frames rely on both past and future frames for temporal prediction. To extract only these frames, FFmpeg utilizes the select filter paired with the pict_type constant.

By evaluating the expression eq(pict_type,B), FFmpeg discards all I-frames (keyframes) and P-frames (predictive frames), processing only the B-frames.

Extracting B-Frames as Images

To extract every B-frame from a video and save them as individual PNG or JPG images, use the following command:

ffmpeg -i input.mp4 -vf "select='eq(pict_type,B)'" -vsync vfr bframe_%04d.png

Command Breakdown:

Extracting B-Frames into a New Video

If you want to extract the B-frames and package them directly into a new video container, you must reset the presentation timestamps (PTS). Otherwise, the output video will stutter or freeze during the timestamps where the deleted I and P frames used to be.

Use this command to output a smooth video consisting solely of B-frames:

ffmpeg -i input.mp4 -vf "select='eq(pict_type,B)',setpts=N/FRAME_RATE/TB" -an output_bframes.mp4

Command Breakdown: