Ffmpeg VapourSynth
Context: $ARGUMENTS
VapourSynth (VS) is a Python-based frame server. A .vpy file is a real Python script that builds a filter graph by calling C++ plugins through vs.core. vspipe streams the resulting video as Y4M to stdout, which ffmpeg consumes as an input — or ffmpeg reads .vpy directly via its vapoursynth demuxer when built with --enable-vapoursynth.
Quick start
- Deinterlace with QTGMC: → Step 2 (write
.vpy) → Step 3 (pipe) - Denoise with KNLMeansCL / BM3DCUDA / dfttest: → Step 2 → Step 3
- 24 → 60 fps motion interpolation (SVPflow / MVTools): → Step 2 → Step 3
- Reuse an AviSynth+ script: Source with
avisourceinside a.vpy→ Step 3 - Direct ffmpeg input without vspipe: → Step 3 "demuxer" variant
When to use
- ffmpeg's built-in filters (
yadif,bwdif,nlmeans,hqdn3d) are not good enough — you need QTGMC deinterlacing, BM3D/KNLMeansCL denoising, or SVPflow motion interpolation. - You want a reproducible, file-based filter graph in Python rather than a one-liner
-vf. - You need to share a chain with AviSynth+ users via
avisource. - You want to decouple decode/filter (VS) from encode (ffmpeg) and keep encoding flags stable across projects.
Step 1 — Install VapourSynth and plugins
# macOS
brew install vapoursynth
# Debian/Ubuntu
sudo apt install vapoursynth vapoursynth-editor
# Python helper libraries (always useful)
pip install vsutil
Common plugins (install via package manager or build from source):
- Source:
ffms2,lsmas(L-SMASH),d2vsource,dgsource - Deinterlace:
nnedi3,EEDI3,mvtools(needed by QTGMC) - Denoise:
knlm(KNLMeansCL, OpenCL),bm3dcuda,dfttest,fft3dfilter - Interpolation:
mvtools,svpflow - Format:
fmtc(fmtconv), built-inresize
Python helper modules used by QTGMC and friends:
pip install havsfunc mvsfunc adjust
Verify install:
vspipe --version
python -c "import vapoursynth as vs; print(vs.core.version())"
Step 2 — Write a `.vpy` script
Minimal scaffold:
import vapoursynth as vs
core = vs.core
clip = core.ffms2.Source("in.mkv")
clip = core.std.Crop(clip, left=10, right=10)
clip.set_output()
QTGMC high-quality deinterlace (top-field-first source):
import vapoursynth as vs
import havsfunc as haf
core = vs.core
clip = core.ffms2.Source("interlaced.mkv")
clip = haf.QTGMC(clip, Preset="Slower", TFF=True)
clip.set_output()
KNLMeansCL (GPU / OpenCL) denoise:
clip = core.knlm.KNLMeansCL(clip, d=2, a=2, s=4, h=1.5)
BM3DCUDA denoise (NVIDIA):
clip = core.bm3dcuda.BM3D(clip, sigma=[1, 1, 1])
dfttest (FFT frequency-domain denoise):
clip = core.dfttest.DFTTest(clip, sigma=1.0)
SVPflow 24 → 60 fps interpolation (simplified — see references/vapoursynth.md for the full recipe):
import vapoursynth as vs
core = vs.core
clip = core.lsmas.LWLibavSource("movie24.mkv")
# Build motion vectors with mvtools, then Smooth / BlockFPS to 60 fps.
# Full SVPflow pipeline: analyse → smooth → interpolate.
clip.set_output()
Always end with clip.set_output(). For multiple outputs use clip.set_output(0), clip2.set_output(1) and select via vspipe -o N.
Step 3 — Pipe into ffmpeg
Standard pipe (works everywhere):
vspipe --y4m script.vpy - | ffmpeg -i - -c:v libx264 -crf 18 -preset slow out.mp4
--y4m is mandatory — the Y4M header carries width, height, fps, and pixel format, which ffmpeg needs to interpret the raw stream.
Direct demuxer (only when ffmpeg was built with --enable-vapoursynth):
ffmpeg -f vapoursynth -i script.vpy -c:v libx264 -crf 18 out.mp4
Most distro builds of ffmpeg do not ship this. If ffmpeg -demuxers | grep vapoursynth is empty, fall back to the vspipe | ffmpeg form.
Adding audio from the original source:
vspipe --y4m script.vpy - | \
ffmpeg -i - -i original.mkv -map 0:v -map 1:a \
-c:v libx264 -crf 18 -c:a copy out.mkv
Step 4 — Encode
Encoder choice is independent of VS. Typical targets:
- Archival:
libx264 -crf 16 -preset verysloworlibx265 -crf 18 -preset slow -tag:v hvc1 - High-bit-depth (10-bit) preserving: emit
vs.YUV420P10from VS, encode with-pix_fmt yuv420p10le - Lossless intermediate:
-c:v ffv1 -level 3 -g 1 -coder 1 -context 1
Keep bit depth consistent end-to-end: if VS outputs 10-bit, ffmpeg must accept 10-bit (-pix_fmt yuv420p10le). Y4M signals this automatically.
Available scripts
scripts/vspipe.py— wrapper aroundvspipe+ffmpegwith subcommands:check— detect VapourSynth, vspipe, and loaded plugins.run --vpy script.vpy --output out.mp4 [--codec libx264] [--crf 18]— pipe.vpythrough ffmpeg.qtgmc-deinterlace --input i.mkv --output o.mkv --tff [--preset Slower]— generate a QTGMC.vpyin a tempdir and encode.knl-denoise --input i.mkv --output o.mkv [--sigma 1.5]bm3d-denoise --input i.mkv --output o.mkv [--sigma 1.0]gen-vpy --source-plugin ffms2 --input i.mkv --output-vpy out.vpy— scaffold a minimal.vpy.- Flags:
--dry-run,--verbose. Stdlib only, non-interactive.
uv run ${CLAUDE_SKILL_DIR}/scripts/vspipe.py check
uv run ${CLAUDE_SKILL_DIR}/scripts/vspipe.py qtgmc-deinterlace \
--input interlaced.mkv --output clean.mkv --tff --preset Slower