Extract Video Frames as JPEGs Using FFmpeg

This guide explains how to extract multiple frames from a video file and save them as JPEG images using FFmpeg. You will learn the command-line syntax for extracting a sequence of frames, pulling frames at specific intervals, and automating the process across multiple videos using loop scripts in Bash and Windows PowerShell.

Basic Frame Extraction Sequence

FFmpeg has a built-in mechanism to loop through a video and output numbered JPEG files. The %04d placeholder in the output filename acts as a sequential counter, formatting the numbers with leading zeros (e.g., 0001, 0002).

To extract every single frame from a video, use the following command:

ffmpeg -i input.mp4 output_%04d.jpg

Extracting Frames at Specific Intervals

If you do not want to extract every frame, you can use video filters (-vf) to define how often FFmpeg should output a JPEG.

Extract One Frame Per Second

To extract one frame for every second of video, use the fps filter set to 1:

ffmpeg -i input.mp4 -vf "fps=1" output_%04d.jpg

Extract One Frame Per Minute

To extract one frame every minute, set the fps filter to 1/60:

ffmpeg -i input.mp4 -vf "fps=1/60" output_%04d.jpg

Extract a Specific Number of Frames

To extract only a set number of sequential frames starting from the beginning of the video, use the -vframes option:

ffmpeg -i input.mp4 -vframes 100 output_%04d.jpg

Looping Through Multiple Video Files

If you need to extract frames from multiple videos in a folder, you can wrap the FFmpeg command in a shell loop.

Using Bash (Linux and macOS)

Run this command in your terminal to loop through all .mp4 files in a directory and extract one frame per second from each:

for file in *.mp4; do
    ffmpeg -i "$file" -vf "fps=1" "${file%.*}_frame_%03d.jpg"
done

Using PowerShell (Windows)

Open PowerShell in your video directory and run the following command:

Get-ChildItem *.mp4 | ForEach-Object {
    ffmpeg -i $_.FullName -vf "fps=1" "$($_.BaseName)_frame_%03d.jpg"
}

Controlling JPEG Quality

By default, FFmpeg may compress the JPEGs. To control the quality, use the -q:v (or -qscale:v) option. The value ranges from 1 to 31, where 1 is the highest quality (least compression) and 31 is the worst quality.

ffmpeg -i input.mp4 -vf "fps=1" -q:v 2 output_%04d.jpg