Media Scenedetect
Context: $ARGUMENTS
PySceneDetect is the go-to tool for reliable scene-change detection. It is superior to ffmpeg's built-in scdet filter, especially on anime, stylized, and low-contrast content. The scenedetect CLI chains a detector (detect-content, detect-adaptive, detect-threshold) with one or more commands (list-scenes, save-images, split-video, export-html) in a single invocation.
Quick start
- Detect scenes + dump a CSV: → Step 3 (
scenedetect -i in.mp4 detect-content list-scenes) - Split video at every cut: → Step 4a (
split-video -mfor stream-copy via mkvmerge) - Generate thumbnails per scene: → Step 4b (
save-images -n 3 -o thumbs) - Auto-chapter a long file: → Step 4c (use helper script
chapterssubcommand)
When to use
- You want reliable shot boundaries for cut sheets, editorial, or auto-chapters.
- ffmpeg
scdetis returning noisy / missed cuts on stylized, anime, or dark content. - You need thumbnails per scene for a dashboard, chapter art, or video summary.
- You're building a pipeline that re-muxes segments into concat lists.
Step 1 — Install
pip install scenedetect[opencv] # recommended (bundled OpenCV wheel)
pip install scenedetect[opencv-headless] # headless servers, no GUI deps
pip install scenedetect # core only — OpenCV already present
Verify: scenedetect version. Splitting requires ffmpeg (default) or mkvmerge on PATH.
Step 2 — Pick detector + threshold
Detectors are mutually exclusive positional commands:
| Detector | When | Typical threshold |
|---|---|---|
| detect-content | Default. Content-aware via HSV deltas. Best general choice. | -t 27 (default). Range 15–40. |
| detect-adaptive | Mixed pacing, slow fades, camera motion. Rolling average of content metric. | -t 3.0 (default adaptive ratio). |
| detect-threshold | Fade-to-black detection or hard-cut-only content. | -t 12 (default, 0–255 luma). |
| detect-hash | Perceptual hash; good for detecting duplicate/near-duplicate frames. | -t 0.395. |
Threshold intuition: higher threshold ⇒ fewer scenes (more tolerant of change). Lower for dark or low-contrast content; raise for noisy / shaky handheld.
Minimum scene length: pass -m 2.0 (seconds) to the detector to drop micro-cuts under 2s.
Luma-only fast mode: detect-content -l skips HSV, uses only luma — cheap on CPU.
Step 3 — Run
Single-detector + list:
scenedetect -i in.mp4 detect-content list-scenes -o scenes.csv
Chain multiple outputs in one pass (detector runs once):
scenedetect -i in.mp4 \
detect-content -t 27 -m 2.0 \
list-scenes -o scenes.csv \
save-images -n 3 -o thumbs \
split-video -o parts -m
Global options worth knowing:
-o DIR— global output directory (applies to all commands unless overridden).-s STATS.csv— write per-frame metric CSV (very useful for threshold tuning).--downscale N— process every Nth pixel (N=4 for 4K); massive speed-up.--start T,--end T,--duration T— limit analysis range (skip intros).-v quiet|error|warning|info|debug— verbosity.
Step 4 — Use the scenes
4a. Split the video
# Re-encode via ffmpeg — exact cuts, slow
scenedetect -i in.mp4 detect-content split-video -o parts
# Stream-copy via mkvmerge — fast, cuts only at keyframes (not frame-exact)
scenedetect -i in.mp4 detect-content split-video -m -o parts
split-video requires ffmpeg unless -m is passed (then needs mkvmerge). Output filenames default to $VIDEO_NAME-Scene-001.mp4 etc.
4b. Thumbnails per scene
scenedetect -i in.mp4 detect-content save-images -n 3 -o thumbs
-n N = images per scene (default 3: first / middle / last). JPG by default; add --jpeg-quality 95 or switch with --png. Useful for chapter art or contact sheet.
4c. Chapters
No first-class chapter exporter — convert list-scenes CSV to ffmetadata format (the helper script's chapters subcommand does this). Then:
ffmpeg -i in.mp4 -i chapters.txt -map_metadata 1 -codec copy out.mp4
4d. HTML report
scenedetect -i in.mp4 detect-content list-scenes save-images export-html -o report.html
Self-contained HTML with thumbnails + timecodes. Great for editorial review.
Available scripts
scripts/scenedetect.py— stdlib wrapper withcheck,detect,split,thumbnails,html-report,chapterssubcommands. All support--dry-runand--verbose.
Workflow
# Verify install
uv run ${CLAUDE_SKILL_DIR}/scripts/scenedetect.py check
# Detect, get scene list as JSON
uv run ${CLAUDE_SKILL_DIR}/scripts/scenedetect.py detect \
--input in.mp4 --method content --threshold 27 --min-duration 2.0
# Split with stream-copy
uv run ${CLAUDE_SKILL_DIR}/scripts/scenedetect.py split \
--input in.mp4 --outdir parts --stream-copy
# Per-scene thumbnails
uv run ${CLAUDE_SKILL_DIR}/scripts/scenedetect.py thumbnails \
--input in.mp4 --outdir thumbs --per-scene 3
# HTML report
uv run ${CLAUDE_SKILL_DIR}/scripts/scenedetect.py html-report \
--input in.mp4 --output report.html
# Build ffmetadata chapter file
uv run ${CLAUDE_SKILL_DIR}/scripts/scenedetect.py chapters \
--input in.mp4 --output chapters.txt