Convert a video to an image sequence with ffmpeg, ready for the web
By Md Mahafuj Alam · Updated
Install ffmpeg and check your encoders
ffmpeg is a free command-line tool that reads almost any video and writes almost any image format. Install it from your package manager. On Windows, use one of the builds linked from the official download page.
# macOS (Homebrew)
brew install ffmpeg
# Debian / Ubuntu
sudo apt install ffmpeg
# Check the version and the image encoders this guide uses
ffmpeg -version
ffmpeg -hide_banner -encoders | grep -E 'libwebp|libaom|mjpeg'You want to see libwebp for WebP, mjpeg for JPEG and libaom-av1 for AVIF. Most packaged builds include all three. If one is missing, ffmpeg stops with Encoder not found and you need a fuller build.
If you would rather not install anything, the free video to frames tool does the same job in your browser, with WebP, JPEG or PNG output.
The basic command
The smallest useful command reads a video and writes every frame as a numbered image. ffmpeg will not create the output folder for you, so make it first.
mkdir -p frames
ffmpeg -i input.mp4 -c:v libwebp -quality 80 frames/frame_%04d.webpframe_%04d.webp is a pattern. ffmpeg replaces %04d with the frame number padded to four digits, so you get frame_0001.webp, frame_0002.webp and so on. Zero padding matters: the files sort in the right order everywhere, and your loader can build each URL with String(i).padStart(4, '0'). Use %05d if you will ever pass 9,999 frames. Add -start_number 0 before the output name if your code counts from zero.
This first pass keeps every frame at full size. A 30 fps, ten-second clip gives 300 full-resolution images, which is usually far more than a scroll story needs. The next two sections cut that down.
Choose the frame count: fps or select
Frame count is the biggest lever on page weight. Each frame is a separate download, so halving the count roughly halves the total. Start by reading what you have.
# Width, height and frame rate
ffprobe -v error -select_streams v:0 -show_entries stream=width,height,r_frame_rate -of csv=p=0 input.mp4
# Duration in seconds
ffprobe -v error -show_entries format=duration -of csv=p=0 input.mp4
# Exact frame count (decodes the whole file, so it takes a moment)
ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -of csv=p=0 input.mp4The fps filter
-vf fps=12 resamples the clip to 12 frames per second of footage. A ten-second clip becomes 120 frames. To hit an exact count, divide the frames you want by the duration: for 120 frames from an eight-second clip, use fps=120/8. ffmpeg accepts the fraction as written.
ffmpeg -i input.mp4 -vf fps=12 -c:v libwebp -quality 80 frames/frame_%04d.webpThe select filter
select keeps frames by number instead of by time. This keeps every third frame of the source and drops the rest. The -fps_mode vfr flag stops ffmpeg duplicating frames to fill the gaps (older builds call it -vsync vfr).
ffmpeg -i input.mp4 -vf "select='not(mod(n\,3))'" -fps_mode vfr -c:v libwebp -quality 80 frames/frame_%04d.webpUse fps when you think in seconds of footage and select when you want an exact subset of the original frames. For scroll animation, 10 to 15 frames per second of footage usually reads as smooth motion, because the reader controls the speed. Fast camera moves need more; slow drifts get away with fewer. The frame budget calculator turns a target page weight into a frame count and size.
Resize with scale and keep even dimensions
A 4K frame is wasted on a laptop screen and very wasted on a phone. Resize in the same pass with the scale filter. Chain filters with commas inside one -vf.
ffmpeg -i input.mp4 -vf "fps=12,scale=1920:-2" -c:v libwebp -quality 80 frames/frame_%04d.webpscale=1920:-2 sets the width to 1920 and works out the height from the aspect ratio, rounded to an even number. With -1 the height can come out odd: a 1920 × 1080 source scaled to a width of 1000 gives 563 with -1 and 562 with -2. WebP accepts odd sizes, but H.264 does not (ffmpeg reports width not divisible by 2), so even sizes save trouble if you also export a video fallback from the same settings.
For desktop, 1920 pixels wide is a sensible ceiling. Many sites go lower, to 1600 or 1280, and let the canvas scale up slightly. Pick the size from how large the canvas is on screen, not from the source.
WebP, JPEG or AVIF
All three formats work in current browsers. They differ in file size, encode time and how easy ffmpeg makes them.
| Format | Flag | Quality setting | Notes |
|---|---|---|---|
| WebP | -c:v libwebp | -quality 0–100 (higher is better) | Good default. Fast to encode, small files. |
| JPEG | .jpg output (mjpeg) | -q:v 2–31 (lower is better) | Fastest and universal. Larger files. |
| AVIF | -c:v libaom-av1 | -crf 0–63 (lower is better) | Smallest files. Slow, one frame per command. |
WebP
-quality 80 is a solid start for photographic footage. Drop to 60 or 70 for preview frames. Check a few frames by eye after each change, looking at gradients and dark areas first.
JPEG
ffmpeg picks the JPEG encoder from the .jpg extension. -q:v 3 gives high quality; values around 5 to 8 are lighter.
ffmpeg -i input.mp4 -vf "fps=12,scale=1920:-2" -q:v 3 frames/frame_%04d.jpgAVIF
AVIF needs care. In ffmpeg 6.1, giving a pattern like frame_%04d.avif does not write a numbered sequence: the .avif extension selects the AVIF muxer, which writes one file. The reliable route is to export lossless PNG frames, then convert each one with libaom-av1 in still-picture mode.
mkdir -p png avif
ffmpeg -i input.mp4 -vf "fps=12,scale=1920:-2" png/frame_%04d.png
for f in png/*.png; do
ffmpeg -y -i "$f" -c:v libaom-av1 -still-picture 1 -crf 32 -cpu-used 6 "avif/$(basename "${f%.png}").avif"
done-cpu-used trades encode speed for compression; higher is faster. Expect AVIF to take far longer than WebP for the same frames. If build time matters more than the last few kilobytes, use WebP.
Trim the clip and make portrait frames for phones
Trimming with -ss and -to
AI-generated and stock clips often have a weak first or last second. Cut it in the same command. Placed before -i, -ss and -to are times in the input file, in seconds or as 00:00:01.5.
# Keep 1.0 s to 2.5 s of the source
ffmpeg -ss 1 -to 2.5 -i input.mp4 -vf "fps=12,scale=1280:-2" -c:v libwebp -quality 80 frames/frame_%04d.webpPortrait frames for 9:16 screens
A landscape frame on a portrait phone either letterboxes or gets cropped by the canvas, and the phone still downloads the full width. A separate portrait set fixes both. Scale the height to 1280, then crop a 720-pixel-wide window from the centre.
mkdir -p frames/portrait
ffmpeg -i input.mp4 -vf "fps=12,scale=-2:1280,crop=720:1280" -c:v libwebp -quality 80 frames/portrait/frame_%04d.webpcrop=720:1280 centres the window by default. To follow the subject, add an x offset: crop=720:1280:200:0 starts 200 pixels from the left. A fixed crop cannot follow a subject that moves across the frame, so check the result, and if the subject leaves the window, frame the shot for both shapes before you generate or film it. Keep the same fps as the landscape set so frame numbers line up and one scroll timeline drives both.
The Kestra template follows the same principle: it ships separate 9:16 portrait frames for phones alongside its landscape set.
Export two tiers: light previews and HD
A scroll story should move as soon as the page opens. Waiting for hundreds of HD frames makes that impossible on a slow connection. The usual fix is two tiers: small, low-quality previews load first so every scroll position has something to draw, then HD frames replace them as they arrive.
mkdir -p frames/preview frames/hd
# Light previews: small and soft, loaded first
ffmpeg -i input.mp4 -vf "fps=12,scale=640:-2" -c:v libwebp -quality 60 frames/preview/frame_%04d.webp
# HD frames: streamed in afterwards
ffmpeg -i input.mp4 -vf "fps=12,scale=1920:-2" -c:v libwebp -quality 80 frames/hd/frame_%04d.webpBoth tiers must use the same fps and trim so frame_0042.webp is the same moment in each folder. The loading side of this, including which HD frames to fetch first, is covered in making scroll animation fast on mobile.
Check the total size before you ship
Count the frames and measure each folder. These numbers are your page weight for the sequence.
ls frames/hd | wc -l
du -sh frames/preview frames/hd frames/portraitDivide the folder size by the frame count to get the average frame weight, then compare it with your budget. As a reference point, Kestra ships 443 frames in 26 MB, which works out at roughly 59 KB per frame on average. If you are over budget, change one thing at a time in this order: fewer frames, smaller dimensions, lower quality. Fewer frames usually costs the least visible quality.
Common errors and fixes
- Could not open file : frames/frame_0001.webp — the output folder does not exist. Run
mkdir -p framesfirst. - Encoder not found — your build lacks that encoder. Check with
ffmpeg -encodersand install a fuller build. - Only one .avif file appears — the AVIF muxer wrote a single file. Use the PNG-then-loop method above.
- width not divisible by 2 — an encoder such as H.264 needs even sizes. Use
-2inscale. - Far more frames than expected — no
fpsfilter, orselectwithout-fps_mode vfr, which duplicates frames to fill gaps. - Files overwritten without warning, or a prompt mid-script — ffmpeg asks before overwriting. Add
-yto overwrite or-nto skip, and clear old frames before a re-export so stale files do not linger.
For every filter option used here, the ffmpeg filters documentation is the reference. Once your frames are ready, draw them on a canvas in Next.js, or see the full workflow in the guide to building a 3D website with Claude. To start from finished, tuned frame sequences, browse the Motion templates.
Questions, answered.
The questions people ask most about this topic.
01How many frames does a scroll animation need?
Usually 10 to 15 frames per second of footage is enough, because the reader controls the speed. A ten-second clip at 12 fps gives 120 frames. Fast camera moves need more frames; slow drifts need fewer.
02Which image format is best for an image sequence on the web?
WebP is the best default: small files, fast to encode and supported by current browsers. AVIF is smaller still but much slower to encode and needs one ffmpeg command per frame. JPEG is the fastest and most compatible but produces larger files.
03What size should the frames be?
Match the size the canvas shows on screen. 1920 pixels wide is a sensible ceiling for desktop, with a lighter preview tier around 640 wide. Phones are better served by a separate portrait set, such as 720 × 1280.
04Why does ffmpeg write only one AVIF file?
In ffmpeg 6.1 the .avif extension selects the AVIF muxer, which writes a single file rather than a numbered sequence. Export PNG frames first, then convert each PNG to AVIF with libaom-av1 and -still-picture 1 in a loop.
05Can I convert a video to frames without installing ffmpeg?
Yes. The free Edok Studio Motion video to frames tool runs in your browser and exports numbered frames you can drop into a canvas scroll animation.
Keep reading
- Start here · the full workflowHow to Build a 3D Motion Website with ClaudeBuild a 3D motion website with Claude: plan the story, generate keyframes and video, cut frames with ffmpeg, then build it in Next.js with GSAP and Lenis.Read the guide
- Guide · BuildCanvas image sequence scroll animation in Next.jsBuild an Apple-style canvas image sequence scroll animation in Next.js: frame preloading, cover-fit drawing, DPR sizing, GSAP scrub, portrait frames.Read the guide
- Guide · PerformanceHow to make scroll animation sites fast on mobileFrame budgets, preview and HD tiers, portrait frames, memory limits and canvas sizing: how to keep image-sequence scroll animation fast on phones.Read the guide