Ffmpeg Detect
Context: $ARGUMENTS
Detect-and-act filters in ffmpeg are read-only analysis passes. They write findings to stderr (and/or frame metadata under lavfi.*), never modify the file, and are designed to be parsed by a script that then issues a second ffmpeg call with real parameters.
Quick start
- Autocrop black bars: → Step 1 (
cropdetect) → Step 3 (applycrop=W:H:X:Y) - Trim silences: → Step 1 (
silencedetect) → Step 3 (cut with-ss/-topairs) - Find black frames / scene cuts: → Step 1 (
blackdetect/scdet) → Step 3 (split with concat demuxer) - Check if interlaced: → Step 1 (
idet) → Step 3 (decide onyadif/bwdif) - Broadcast QC: → Step 1 (
signalstats) → Step 3 (flag out-of-range YMIN/YMAX/SATMAX) - Read embedded captions / timecode: →
readeia608,readvitc - Pre-loudnorm audio stats: →
volumedetect,astats(useloudnormfrom ffmpeg-audio-filter for true LUFS)
When to use
- You need to compute parameters (crop rect, cut list, LUT threshold) from a media file before doing a real encode.
- You're doing QC on broadcast or archival content and need per-frame statistics.
- You're auto-splitting a long capture on scene changes or silences.
- You're deciding whether to deinterlace before a delivery encode.
Use ffmpeg-quality for reference-vs-distorted measurement (VMAF/PSNR/SSIM). Use ffmpeg-probe for container/codec structure — detect filters are for content analysis.
Step 1 — Pick the detector
| Goal | Filter | Typical command tail |
|---|---|---|
| Autocrop | cropdetect | -vf cropdetect=limit=24:round=2 -f null - |
| Silences in audio | silencedetect | -af silencedetect=noise=-30dB:d=0.5 -f null - |
| Black segments | blackdetect | -vf blackdetect=d=1:pix_th=0.1 -f null - |
| Freeze frames | freezedetect | -vf freezedetect=n=0.001:d=0.5 -f null - |
| Blur QC | blurdetect | -vf blurdetect -f null - |
| Blocking QC | blockdetect | -vf blockdetect -f null - |
| Scene cuts | scdet | -vf "scdet=s=1:t=10" -f null - |
| Interlace | idet | -vf idet -f null - |
| Broadcast QC | signalstats | -vf signalstats -f null - |
| CEA-608 captions | readeia608 | -vf readeia608 -f null - |
| VITC timecode | readvitc | -vf readvitc -f null - |
| Volume (peak/mean dB) | volumedetect | -af volumedetect -f null - |
All of these pair with -f null - (video) or route to -f null - (audio) so no file is written. The filter's output lives in stderr. Add -hide_banner to reduce noise. Seek first (-ss) and limit (-t) for fast sampling on long files.
Step 2 — Run and parse stderr / metadata
ffmpeg writes detector lines to stderr. Standard pattern:
ffmpeg -hide_banner -i IN -vf FILTER -f null - 2>&1 | grep PATTERN
Per-detector regexes (see references/detectors.md for full catalog):
cropdetect→crop=\d+:\d+:\d+:\d+(take last match — stabilizes over time).silencedetect→silence_start: ([\d.]+)andsilence_end: ([\d.]+) \| silence_duration: ([\d.]+)— pair consecutive start/end lines.blackdetect→black_start:([\d.]+) black_end:([\d.]+) black_duration:([\d.]+)(all on one line).freezedetect→freeze_start: ([\d.]+),freeze_duration: ([\d.]+),freeze_end: ([\d.]+).scdet→lavfi.scd.score/lavfi.scd.timein metadata (with-f null -andscdet=s=1prints to stderr).idet→ three summary lines at end:Single frame detection,Multi frame detection,Repeated Fields. Use Multi frame for decision.signalstats→ per-frame metadata keyslavfi.signalstats.{YAVG,YMIN,YMAX,UMIN,UMAX,VMIN,VMAX,SATMIN,SATMAX,HUEMED,HUEAVG,YDIF,UDIF,VDIF,SATDIF,TOUT,VREP}. Extract with-show_frameson a second ffprobe pass, or withmetadata=mode=print.readeia608→lavfi.readeia608.X.ccbytes — pipe to-f srtor parse manually for proper caption extraction.readvitc→lavfi.readvitc.tc_str=HH:MM:SS:FFper frame.volumedetect→mean_volume: X dB,max_volume: Y dBat end of run.
For metadata keys, the idiomatic pattern is:
ffmpeg -i IN -vf "signalstats,metadata=mode=print:file=-" -f null - 2>/dev/null
Step 3 — Turn parsed output into actionable parameters
Autocrop (two commands):
# Sample from 10s in, 120s long — skip opening credits / fades
ffmpeg -hide_banner -ss 10 -i in.mp4 -t 120 -vf cropdetect=limit=24:round=2 \
-f null - 2>&1 | grep -o 'crop=[0-9:]*' | tail -1
# → crop=1920:816:0:132
ffmpeg -i in.mp4 -vf crop=1920:816:0:132 -c:a copy out.mp4
Silence trim: parse silencedetect lines, invert to "keep" segments, pass to concat demuxer or -ss/-to pairs. See scripts/detect.py silences for JSON output.
Scene-split chapters: feed scdet timestamps to ffmpeg-cut-concat skill to segment on cuts.
Interlace decision: if Multi frame detection shows TFF > 100 && progressive < 10 → -vf yadif=1:0 (TFF). If BFF > progressive → -vf yadif=1:1 (BFF). If progressive dominates → skip deinterlace.
Broadcast QC: flag any frame where YMIN < 16 or YMAX > 235 (limited-range violation), SATMAX > 118.2 (NTSC 75% bars), or TOUT > 0.005 (temporal outlier / dropout).
Available scripts
scripts/detect.py— argparse dispatcher with subcommandscrop,silences,blacks,freezes,scenes,interlace,stats,volume. All return JSON (or a ready-to-use crop string forcrop). Stdlib only, non-interactive.
Workflow
# Autocrop
uv run ${CLAUDE_SKILL_DIR}/scripts/detect.py crop --input in.mp4
# Silences → JSON
uv run ${CLAUDE_SKILL_DIR}/scripts/detect.py silences --input in.mp3 --noise-db -30 --min-duration 0.5
# Scene cuts
uv run ${CLAUDE_SKILL_DIR}/scripts/detect.py scenes --input in.mp4 --threshold 10
# Interlace decision
uv run ${CLAUDE_SKILL_DIR}/scripts/detect.py interlace --input broadcast.ts