How to Extract Every Nth Frame with FFmpeg Select

Extracting specific frames from a video is a fundamental task in video processing, useful for creating contact sheets, generating thumbnails, or preparing datasets for machine learning. This article provides a straightforward guide on how to use FFmpeg’s select video filter to extract every \(N\)-th frame (for example, every 10th or 100th frame) from a video file and save them as sequential image files.


The Basic Command

To extract every \(N\)-th frame, you use the select filter with the mathematical expression not(mod(n,N)). Here is the standard command to extract every 10th frame:

ffmpeg -i input.mp4 -vf "select='not(mod(n,10))'" -fps_mode vfr output_%04d.png

Command Breakdown

Examples for Different Intervals

To change the interval, simply replace the number 10 in the modulo function with your desired interval \(N\).

Alternative: Extracting Frames by Time Interval

If you prefer to extract frames based on time (seconds) rather than frame counts, you can use the t (time) variable instead of n (frame number).

To extract one frame every 5 seconds:

ffmpeg -i input.mp4 -vf "select='not(mod(t,5))'" -fps_mode vfr output_%04d.png