Skip to content
Back to Blog
2026-11-16Testing

How to Generate Test Videos with ffmpeg: Resolution, Duration, and Audio Combos

Downloading random video clips to test a player, uploader, or transcoder is a losing habit: the files have unpredictable durations, mystery codecs, and licenses you did not read. ffmpeg generates exactly the file you need — precise duration, exact resolution, known audio layout — in seconds, with no legal ambiguity. This is the combo list I keep coming back to.

The One Command That Does 90% of the Work

ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 \
       -f lavfi -i sine=frequency=440:duration=10 \
       -c:v libx264 -pix_fmt yuv420p -c:a aac -shortest test.mp4

Three moving parts: testsrc synthesizes video (a color pattern with a running counter, so you can visually confirm playback rate), sine synthesizes a 440 Hz tone, and -pix_fmt yuv420p keeps H.264 decodable everywhere — leave it out and some players show green artifacts, because testsrc outputs a pixel format most hardware decoders reject.

Prefer the newer pattern source? Swap testsrc for testsrc2 (faster to encode, higher frame-rate ceiling) or smptehdbars for reference color bars.

Resolution and Duration Combos

Every combination is just parameters — no hunting for "a small 4K clip" ever again:

GoalCommand fragment
1080p, 30 fps, 30 stestsrc=duration=30:size=1920x1080:rate=30
4K stress testtestsrc2=duration=10:size=3840x2160:rate=60
Tiny player testtestsrc=duration=5:size=320x240:rate=12
Vertical (Shorts/Reels)testsrc=duration=15:size=1080x1920:rate=30
Odd, non-standard sizetestsrc=duration=5:size=854x480:rate=25

The odd sizes matter more than the round ones: an 854x480 or 1097x713 file catches aspect-ratio math and layout bugs that 1280x720 never will. Duration is worth testing at the edges too — a 0.5 s clip and a 90 min clip (duration=5400) exercise buffering and seek bars differently.

Audio Track Combos

Audio is where pipelines quietly break, because "no audio", "silent audio", and "tone audio" are three different files:

FixtureSource fragmentWhat it catches
Mono, 8 kHz (telephony)`sine=frequency=440:sample_rate=8000,pan=monoc0=c0`
Stereo, 48 kHzsine=frequency=1000:sample_rate=48000The video-production default
Silent but present trackanullsrc=r=44100:cl=stereoPlayers that crash on absent audio
No audio at all(omit the second -i)UI mute icons, autoplay policies
Two different tones L/R`aevalsrc=0.1sin(4402PIt)0.1sin(8802PIt)`

The anullsrc row is underrated: a file with a silent stereo track is a different test case from a video-only file, and half of audio-handling bugs only appear on one of them. Keep both fixtures.

Container and Codec Matrix

Same synthetic content, four containers — this is the quickest way to find out your player only ever tested MP4:

# MP4 / H.264 / AAC — the compatibility baseline
ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 \
       -f lavfi -i sine=frequency=440:duration=10 \
       -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
       -c:a aac -shortest -movflags +faststart compat.mp4

# AVI / MPEG-4 Part 2 — legacy and industrial gear
ffmpeg -f lavfi -i testsrc=duration=10:size=640x480:rate=25 \
       -c:v mpeg4 -q:v 5 -an legacy.avi

# WebM / VP9 + Opus — the browser-native combo
ffmpeg -f lavfi -i testsrc2=duration=10:size=1280x720:rate=30 \
       -f lavfi -i sine=frequency=440:duration=10 \
       -c:v libvpx-vp9 -row-mt 1 -b:v 0 -crf 35 \
       -c:a libopus -shortest modern.webm

# MKV — remux the MP4 stream without re-encoding
ffmpeg -i compat.mp4 -c copy same.mkv

Notes: -movflags +faststart moves the MP4 index to the front so the file can start playing mid-download — skip it and your streaming tests will lie to you. The baseline H.264 profile is the floor for old Android WebView versions. The MKV remux costs nothing (no re-encode) and gives you a same-codec-different-container pair, which isolates container-level bugs from codec-level ones.

Grab a ready-made sample MP4 or an AVI test file when you want a fixture produced outside your own toolchain — comparing your generated file against an independently produced one is a good sanity check that your ffmpeg flags mean what you think they mean.

Verify What You Actually Produced

Never trust the command; trust the file:

ffprobe -v error -show_entries format=duration,size:stream=codec_name,codec_type,width,height,r_frame_rate,sample_rate,channels -of default=noprint_wrappers=1 test.mp4

Assert on the output in CI: duration within a tolerance (MP4 containers often report 10.01 s for a requested 10), the stream count, and the channel layout. A generated-file suite that ffprobes its own fixtures catches flag typos before they become mystery test failures.

Edge Cases Worth Generating Once

  • Faststart off vs on — same bytes reordered; only one streams progressively.
  • 10-bit color: -c:v libx265 -pix_fmt yuv420p10le -tag:v hvc1 produces an HEVC file that some decoders render washed-out — a real compatibility fixture.
  • 1-frame video: testsrc=duration=0.04:rate=25 — the minimum playable file; great for thumbnail and seek-bar edge cases.
  • Rotated metadata: -metadata:s:v rotate=90 — players must respect or ignore it consistently.

When Generation Is Still Overkill

For smoke tests you will re-run constantly, commit small prebuilt fixtures: a short WebM sample and an MKV test file in the repo beat regenerating them on every CI run. Generate on demand when you need specific parameters; commit when you need stable ones.

Build the matrix — {mp4, avi, webm, mkv} x {no audio, silent, tone} x {short, long} — once, script it, and every future video bug report comes with a reproducing file already attached.

#ffmpeg#video-testing#test-files#mp4#qa