Ffmpeg Stabilize
Context: $ARGUMENTS
Quick start
- Stabilize shaky handheld (best quality): 2-pass vid.stab → Steps 1–4
- Quick fix, don't care about quality: single-pass
deshake→ Examples - GPU single-pass:
deshake_opencl→ Examples - Locked-off tripod look from handheld:
tripod=N→references/vidstab.md
When to use
- Handheld phone/camera footage with visible shake
- GoPro / action-cam clips (mounted but still jittery)
- Drone clips with buffeting wobble
- Making interview-style footage look "locked off" without an actual tripod
- Pre-stabilizing before VFX, speed ramps, or any grading that amplifies jitter
Step 1 — Check build supports vid.stab
ffmpeg -filters 2>/dev/null | grep -i vidstab
Must show both vidstabdetect and vidstabtransform. If missing, either install a Homebrew build (brew install ffmpeg — includes --enable-libvidstab since late 2019), or fall back to deshake (builtin, always available).
scripts/stabilize.py check-build does this check programmatically.
Step 2 — Pass 1: detect motion → transforms.trf
ffmpeg -i in.mp4 \
-vf vidstabdetect=shakiness=5:accuracy=15:result=transforms.trf \
-f null -
- Produces
transforms.trf(plain-text, one line per frame with dx/dy/rot/zoom). -f null -discards the video output — we only want the sidecar file.shakiness: 1 (mild) to 10 (extreme), default 5.accuracy: 1 (fast) to 15 (max), default 15. Keep at 15 unless iterating.
Step 3 — Pass 2: transform + sharpen + optional zoom
ffmpeg -i in.mp4 \
-vf "vidstabtransform=input=transforms.trf:zoom=0:smoothing=30:crop=black,unsharp=5:5:0.8:3:3:0.4" \
-c:v libx264 -crf 18 -preset slow \
-c:a copy out.mp4
smoothing=30≈ 1 second at 30 fps — good default.crop=blackleaves black borders where frame was pushed;crop=keeprepeats prior edge pixels.unsharp=5:5:0.8:3:3:0.4restores sharpness lost to bilinear interpolation.-c:a copypasses audio through; re-encode is required for video.
Hide black borders
Option A — fixed zoom (percent):
vidstabtransform=input=transforms.trf:zoom=5:smoothing=30:crop=black
Option B — automatic optimal zoom (recommended for heavy shake):
vidstabtransform=input=transforms.trf:optzoom=1:smoothing=30:crop=black
Option C — adaptive optzoom with zoom speed cap:
vidstabtransform=input=transforms.trf:optzoom=2:zoomspeed=0.25:smoothing=30:crop=black
Step 4 — Verify
ffplay out.mp4 # visual check
ffprobe -v error -show_entries stream=codec_name,width,height,r_frame_rate out.mp4
For A/B compare:
ffmpeg -i in.mp4 -i out.mp4 -filter_complex hstack -c:v libx264 -crf 20 compare.mp4
Available scripts
scripts/stabilize.py stabilize— runs both passes end-to-end, managestransforms.trfin a tempdir.scripts/stabilize.py deshake— single-pass fallback.scripts/stabilize.py check-build— reports vid.stab availability.
uv run ${CLAUDE_SKILL_DIR}/scripts/stabilize.py stabilize --input in.mp4 --output out.mp4 --sharpen --zoom auto
uv run ${CLAUDE_SKILL_DIR}/scripts/stabilize.py deshake --input in.mp4 --output out.mp4
uv run ${CLAUDE_SKILL_DIR}/scripts/stabilize.py check-build