Extract frames from a video with FFmpeg

Use the fps filter with a numbered file name: ffmpeg -i in.mp4 -vf fps=1:round=up -q:v 2 frame_%04d.jpg. Add round=up so the frames land on whole seconds, and -q:v 2 so the JPEGs are sharp. Every command below ran on a 2-minute clip with the frame number burned in, so you can see which frames each one wrote.

Per second Re-encode

A frame at each second, for previews, datasets or picking a still.

ffmpeg -i in.mp4 -vf fps=1:round=up -q:v 2 frame_%04d.jpg

120 JPEGs, frame_0001.jpg to frame_0120.jpg. Each is the frame exactly on the second: 0:00.000, 0:01.000, 0:02.000 and on.

Images
120, frames 0, 24, 48...
Per image
120 KB average
Run time
1.0 s
Output
14.5 MB
Every frame Re-encode

You need all of them, for frame-by-frame work. Mind the disk space.

ffmpeg -i in.mp4 -q:v 2 frame_%04d.jpg

2880 JPEGs, one per frame, 336 MB from a 30 MB video.

Images
2880
Per image
117 KB average
Run time
3.3 s
Output
336.3 MB

Proof

Which frames "one per second" really gives

The first four images each command wrote, cropped to the burned-in timecode and frame number.
-vf fps=1:round=up On the second
First four images from fps=1:round=up: 0:00.000 frame 0, 0:01.000 frame 24, 0:02.000 frame 48, 0:03.000 frame 72
0:00.000 Frames 0, 24, 48, 72. Image N is the frame at second N minus one.
-vf fps=1 Half a second late
First four images from fps=1: 0:00.458 frame 11, 0:01.458 frame 35, 0:02.458 frame 59, 0:03.458 frame 83
0:00.458 The default rounding picks the last frame before each half second: frames 11, 35, 59, 83.
-r 1 Two images of the first second
First four images from -r 1: 0:00.000 frame 0, 0:00.042 frame 1, 0:00.875 frame 21, 0:01.875 frame 45
122 images Frames 0 and 1 both come out, then 21, 45 and on. 122 images for 120 seconds.
no -q:v vs -q:v 2 The default is blocky
The same frame as a JPEG with no -q:v on the left, blocky, and with -q:v 2 on the right, sharp
26 KB vs 160 KB The same image from the fps=1 run, without -q:v on the left and with -q:v 2 on the right.

Footage: Sintel, © Blender Foundation, CC BY 3.0. Timecode added by us.

Run it

Run it on Rendobar

Send the same command from your code. The job fetches each input from its URL and returns the output file's URL when it finishes.

job.ts
import { createClient } from "@rendobar/sdk";
const rb = createClient({ apiKey: process.env.RENDOBAR_API_KEY });
const job = await rb.jobs.run({
type: "ffmpeg",
inputs: {
"in.mp4": "https://cdn.rendobar.com/examples/video-to-frames/in.mp4",
},
params: {
command: "ffmpeg -i in.mp4 -vf fps=1:round=up -q:v 2 frame_%04d.jpg",
},
});
console.log(job.output.file.url);

Install with npm i @rendobar/sdk. jobs.run() submits and waits, so it returns the finished job in one call.

terminal
curl https://api.rendobar.com/jobs \
-H "Authorization: Bearer $RENDOBAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "ffmpeg",
"inputs": {
"in.mp4": "https://cdn.rendobar.com/examples/video-to-frames/in.mp4"
},
"params": {
"command": "ffmpeg -i in.mp4 -vf fps=1:round=up -q:v 2 frame_%04d.jpg"
}
}'

Returns immediately with a job id. Poll GET /jobs/{id} or register a webhook rather than blocking on the request.

Every variant

Pick the command for your case

Each one ran on the same input. The line under it is what came out. Run times are the best of three runs with FFmpeg 8.0 on one desktop machine, so read them as relative.

  1. Extract one frame every 10 seconds

    Re-encode
    ffmpeg -i in.mp4 -vf fps=1/10:round=up -q:v 2 frame_%04d.jpg

    12 JPEGs at 0:00, 0:10, 0:20 and on to 1:50. Without round=up they came out at 0:04.958, 0:14.958, 5 s late.

    911 ms run 1.4 MB

  2. Extract only the keyframes

    Re-encode
    ffmpeg -skip_frame nokey -i in.mp4 -fps_mode vfr -q:v 2 frame_%04d.jpg

    12 JPEGs, the keyframes at every 10 s. The decoder skips all the other frames, so it decoded 12 frames instead of 2880. Where keyframes fall depends on how the video was encoded.

    188 ms run 1.4 MB

  3. Extract every frame between 1:00 and 1:05

    Re-encode
    ffmpeg -ss 60 -i in.mp4 -t 5 -q:v 2 frame_%04d.jpg

    120 JPEGs, 5 s at 24 fps. The first is frame 1440, exactly 1:00.000.

    217 ms run 20.4 MB

  4. Extract every 48th frame

    Re-encode
    ffmpeg -i in.mp4 -vf "select=not(mod(n\,48))" -fps_mode vfr -q:v 2 frame_%04d.jpg

    60 JPEGs: frames 0, 48, 96 and on. n counts frames, not seconds.

    915 ms run 7.4 MB

  5. Extract lossless PNG frames

    Re-encode
    ffmpeg -i in.mp4 -vf fps=1:round=up frame_%04d.png

    120 PNGs, 84 MB. The same frames as -q:v 2 JPEGs took 14 MB, so PNG cost 5.8 times the space.

    1.4 s run 84.3 MB

  6. Name each image by its second

    Re-encode
    ffmpeg -i in.mp4 -vf fps=1:round=up -frame_pts 1 -q:v 2 frame_%04d.jpg

    frame_0000.jpg to frame_0119.jpg. The number in each name is the second the frame comes from.

    960 ms run 14.5 MB

  7. Extract smaller frames, 640 wide

    Re-encode
    ffmpeg -i in.mp4 -vf "fps=1:round=up,scale=640:-2" -q:v 2 frame_%04d.jpg

    120 JPEGs at 640x274, 4.6 MB in total, a third of the full-size set.

    929 ms run 4.6 MB

Gotchas

Where it goes wrong

Does fps=1 give the frame at each second?

No. With default rounding, fps=1 keeps the last frame before each half second. On a 24 fps clip that is 0:00.458, 0:01.458 and so on. fps=1/10 was worse: 0:04.958, 0:14.958, nearly 5 s after each mark.

round=up moves every pick onto the second itself. The proof above shows all three.

-r 1 as an output option is a different mechanism. It drops and duplicates frames to hit 1 fps:

ffmpeg -i in.mp4 -r 1 frame_%04d.jpg

122 images for 120 s. The first two are frames 0 and 1, 1/24 s apart, then 0:00.875, 0:01.875 and on.

Why do my extracted JPEGs look blocky?

FFmpeg's default JPEG quality is low. Without -q:v, the fps=1 set averaged 27 KB per image and showed blocks in skin and hair. With -q:v 2 the same set averaged 115 KB and looked clean.

-q:v runs from 2 (best) to 31. PNG ignores it, because PNG is lossless.

Why does select write thousands of duplicate frames?

Image outputs default to a constant frame rate. When select drops frames, FFmpeg fills the gaps by repeating the ones it kept:

ffmpeg -i in.mp4 -vf "select=not(mod(n\,48))" frame_%04d.jpg

2879 images instead of 60, mostly copies.

Add -fps_mode vfr and FFmpeg writes only the frames the filter passed. Older answers use -vsync, the deprecated name of -fps_mode.

PNG or JPG for extracted frames?

  • JPEG with -q:v 2: 120 KB per frame here. Right for previews, thumbnails, labelling and most computer vision work.
  • PNG: 703 KB per frame, 5.8 times the JPEG. Right when the frames go back into an edit or a quality comparison, where any loss counts.

Related: Extract a thumbnail, Contact sheet, Images to video, Change frame rate.

Your command. Our infrastructure.

Bring your own commands. Run them on scalable CPU and GPU infrastructure, and pay only for compute time.