How to Extract I-frames with FFmpeg Select Filter

Extracting keyframes, or I-frames, from a video is a common task for video analysis, editing, and creating preview thumbnails. This article provides a quick, practical guide on how to use the FFmpeg select video filter to isolate and export only the I-frames from a video file, saving them as individual images.

Understanding the Command

An I-frame (Intra-coded frame) is a complete image that does not require data from other frames to be decoded. To extract these frames using FFmpeg, you use the select filter with the pict_type parameter set to I.

Here is the standard command to extract I-frames as PNG images:

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

Command Breakdown

Extracting I-frames as a New Video

If you want to concatenate the extracted I-frames into a new, fast-forwarded video instead of individual images, you must reset the presentation timestamps (PTS) using the setpts filter:

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

In this command, setpts=N/FRAME_RATE/TB recalculates the timestamps of the selected frames so they play sequentially without pauses. The -an flag removes the audio, as the original audio stream will no longer sync with the modified video stream.