Extract Frames by Duration Using FFmpeg Select Filter

This article explains how to use the FFmpeg select video filter to extract specific video frames based on time duration and timestamps. You will learn the exact command-line syntax to capture frames within a precise time range, extract frames at regular duration intervals, and save them as images.

Extracting Frames Within a Specific Time Range

To extract frames that fall within a specific start and end time, use the between(t, start, end) evaluation function inside the select filter. The variable t represents the timestamp of the frame in seconds.

Run the following command to extract frames between the 10-second and 15-second marks of a video:

ffmpeg -i input.mp4 -vf "select='between(t,10,15)'" -vsync vfr output_%03d.png

Extracting Frames at Regular Time Intervals

If you want to extract one frame at a specific duration interval (for example, every 5 seconds), you can calculate the difference between the current frame’s timestamp and the previously selected frame’s timestamp using the prev_selected_t variable.

Run this command to extract one frame every 5 seconds:

ffmpeg -i input.mp4 -vf "select='isnan(prev_selected_t)+gte(t-prev_selected_t,5)'" -vsync vfr output_%03d.png

Combining Duration with Scene Changes

The select filter allows you to combine duration rules with other parameters, such as scene change detection. If you want to detect scene changes but only within a specific part of the video, you can combine expressions using logical operators.

To extract scene-change frames (where the change threshold is 40%) only between the 30-second and 60-second marks:

ffmpeg -i input.mp4 -vf "select='between(t,30,60)*gt(scene,0.4)'" -vsync vfr output_%03d.png