Extract Keyframes with FFmpeg Select Filter

Extracting only the keyframes (I-frames) from a video is a highly efficient way to generate thumbnails, summarize video content, or analyze scene changes. This article provides a straightforward guide on how to use the FFmpeg select filter to isolate and export only the keyframes of a video, along with the command-line options needed to customize your output.

The Basic Command

To extract only keyframes using the select filter, use the following FFmpeg command:

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

Command Breakdown

Alternative Shorthand Command

FFmpeg also provides a simpler shorthand expression specifically for selecting keyframes:

ffmpeg -i input.mp4 -vf "select=key" -vsync vfr output_%03d.png

Both the eq(pict_type,I) expression and the key constant achieve the exact same result.

Speed Optimization: Skipping Non-Keyframes

By default, the commands above decode the entire video stream to evaluate each frame, which can be slow for large files. To drastically speed up the extraction process, you can instruct the decoder to discard non-keyframes before the video is even filtered:

ffmpeg -skip_frame nokey -i input.mp4 -vf "select=key" -vsync vfr output_%03d.png

The -skip_frame nokey option tells FFmpeg to skip decoding any frame that is not a keyframe, making the extraction process almost instantaneous.