How to Extract Every 24th Frame with FFmpeg
This guide explains how to extract every 24th frame from a video file and save the output as a sequentially numbered series of PNG images using the FFmpeg command-line tool. By leveraging FFmpeg's video filtering capabilities, you can systematically sample frames at precise intervals without manually scrubbing through footage.
The Command
To extract every 24th frame, open your terminal or command prompt and run the following command:
ffmpeg -i input.mp4 -vf "select='not(mod(n\,24))'" -fps_mode vfr output_%04d.pngCommand Breakdown
-i input.mp4: Specifies the path to your source video file.-vf "select='not(mod(n\,24))'": Applies a video filter using theselectexpression:nrepresents the zero-based index of the current frame.mod(n\,24)calculates the modulo (remainder) of the frame number divided by 24.not(...)evaluates to true (1) when the remainder is 0, selecting frames 0, 24, 48, 72, and so on.
-fps_mode vfr: Sets the output frame rate mode to variable frame rate (VFR). This ensures that unselected frames are discarded entirely rather than duplicated to maintain the original frame rate. (Note: If you are using an older version of FFmpeg prior to version 5.1, use-vsync vfrinstead).output_%04d.png: Defines the naming pattern for the exported images. The%04dspecifier formats the sequence numbers with four digits padded by leading zeros (e.g.,output_0001.png,output_0002.png).
Adjusting the Output
- Change the Interval: To capture a different
interval, replace
24with your desired frame step (for example,mod(n\,30)for every 30th frame). - Change Image Format: Replace the
.pngextension with.jpgor.webpif you require smaller file sizes or compressed formats.