How to Extract Every 10th Frame Using FFmpeg
This article provides a quick, step-by-step guide on how to use the FFmpeg command-line tool to extract every 10th frame from a video file and save them as a sequentially numbered series of JPEG images. You will learn the exact command to use and how each parameter works to customize the output for your project.
To extract every 10th frame from a video, open your terminal or command prompt and run the following FFmpeg command:
ffmpeg -i input.mp4 -vf "select='not(mod(n,10))'" -vsync vfr output_%04d.jpgCommand Breakdown
-i input.mp4: Specifies the path to your input video file. Replaceinput.mp4with your actual file name.-vf "select='not(mod(n,10))'": This is the video filter (-vf) that selects which frames to keep.nrepresents the frame sequential number (starting at 0).mod(n,10)divides the frame number by 10 and returns the remainder.not(...)evaluates to true (1) only when the remainder is 0. This successfully selects frames 0, 10, 20, 30, and so on.
-vsync vfr: This tells FFmpeg to use a Variable Frame Rate (VFR) for the output. It prevents FFmpeg from duplicating frames to fill in the gaps of the dropped frames. Note: In newer versions of FFmpeg, you can use-fps_mode vfrinstead.output_%04d.jpg: This defines the output format and naming convention. The%04dplaceholder format tells FFmpeg to number the output images sequentially with four digits, padded with leading zeros (e.g.,output_0001.jpg,output_0002.jpg,output_0003.jpg).
Adjusting Image Quality
By default, FFmpeg exports JPEGs with a medium quality level. If you
want to maximize the quality of the exported JPEG images, add the
-q:v (or -qscale:v) option set to a low value,
where 2 represents high quality:
ffmpeg -i input.mp4 -vf "select='not(mod(n,10))'" -vsync vfr -q:v 2 output_%04d.jpg