Extract Keyframes from Video as Images Using FFmpeg

Extracting keyframes (also known as I-frames) from a video is a crucial task for video analysis, thumbnail generation, and editing. This article provides a straightforward, step-by-step guide on how to use the powerful command-line tool FFmpeg to identify, isolate, and save all keyframes from a video stream as individual image files.

The Standard FFmpeg Command

To extract only the I-frames (keyframes) from a video, you can use FFmpeg’s video filter (-vf) option with the select filter. Run the following command in your terminal:

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

Command Breakdown

The Fast Extraction Method

The standard method decodes the entire video stream to find the keyframes, which can be slow for long videos. You can speed up the process significantly by telling the decoder to skip reading non-keyframes entirely using the -skip_frame option:

ffmpeg -skip_frame nokey -i input.mp4 -vsync vfr output_%04d.jpg

Choosing the Output Format

While the examples above use JPEG (.jpg), you can export to other formats simply by changing the file extension in the output pattern: