Congratulations on setting up your encoding environment! Now it’s time to write and run your first VapourSynth script. This will involve loading a video source, applying basic filters, and preparing the file for encoding.
VapourSynth is a scripting-based video processing tool. It allows you to load, filter, and manipulate video files before encoding. VapourSynth uses Python for scripting, so familiarity with basic Python syntax will help.
.vpy
extension, such as first_script.vpy
.To load a video source, use one of VapourSynth’s core plugins, such as ffms2
or LSMASHSource
. Here’s a basic example:
import vapoursynth as vs
core = vs.core
# Load video source
clip = core.ffms2.Source("example.mkv")
# Output the video
clip.set_output()
Filters enhance the video by addressing artifacts or resizing the resolution. For example:
# Crop 10 pixels from each side and resize to 1280x720
clip = core.crop(clip, left=10, right=10, top=10, bottom=10)
clip = core.resize.Bilinear(clip, width=1280, height=720)
# Apply debanding to smooth gradients
clip = core.f3kdb.Deband(clip, range=15, y=64, cb=64, cr=64)
# Apply light denoising to remove noise
clip = core.knlm.KNLMeansCL(clip, d=1, a=2, h=1.2)
mpv
or by piping the script to ffplay
:
vspipe --y4m first_script.vpy - | ffplay -
Here’s a complete example of a basic VapourSynth script:
import vapoursynth as vs
core = vs.core
# Load the video
clip = core.ffms2.Source("example.mkv")
# Apply basic filters
clip = core.crop(clip, left=10, right=10, top=10, bottom=10) # Crop edges
clip = core.resize.Bilinear(clip, width=1280, height=720) # Resize
clip = core.f3kdb.Deband(clip, range=15, y=64, cb=64, cr=64) # Deband
# Output the video
clip.set_output()
vspipe --y4m first_script.vpy - | ffplay -
x264
or x265
:
vspipe first_script.vpy - | x264 --demuxer y4m --preset placebo --level 41 --crf 16.9 --me umh --rc-lookahead 250 --profile high --deblock -2:-1 --chroma-qp-offset -1 --qcomp 0.70 --aq-mode 3 --aq-strength 0.80 --psy-rd 1.00:0 -o output.h264 -
ffms2
are installed correctly.You’ve written and executed your first VapourSynth script! This foundational knowledge prepares you for more advanced filtering and encoding workflows. In the next section, we’ll explore filtering techniques in depth.