Script examples

From Avisynth

Jump to: navigation, search

Here are some examples of AviSynth scripts, grouped in categories of increasing complexity.

Contents

[edit] Simple examples

[edit] Example 1: Cutting out sections

# This is a comment.  All lines starting with a '#' symbol are comments
# and are ignored by AviSynth.

# load the file "somevideo.avi" from the same directory as the script
AVISource("somevideo.avi")

# Trim specifies what frames to KEEP.  The following line keeps frames
# [0, 12000], [20000, 32000], [44000, end] and then splices them
# together, effectively removing frames [12001, 19999] and
# [32001, 43999]
#
# NOTE: the interval notation [a, b] means all frames from a through b,
#       inclusive.
#
Trim(0, 12000) ++ Trim(20000, 32000) ++ Trim(44000, 0)

[edit] Example 2: Resizing

AVISource("somevideo.avi")

# resize the dimensions of the video frame to 320x240
LanczosResize(320, 240)

[edit] Example 3: Dubbing audio

video = AVISource("somevideo.avi")

# we can load WAV files too
audio = WAVSource("music.wav")

# mux the video and audio tracks together
AudioDub(video, audio)

[edit] Example 4: Adjusting brightness, removing noise, fading

AVISource("somevideo.avi")

# TemporalSoften is one of many noise-reducing filters
TemporalSoften(4, 4, 8, scenechange=15, mode=2)

# increase the gamma (relative brightness) of the video
Levels(0, 1.2, 255, 0, 255)

# fade-in the first 15 frames from black
FadeIn(15)

# fade-out the last 15 frames to black
FadeOut(15)

[edit] More complex examples

[edit] Example 5: poptones' Layer example

LoadPlugin("MPEG2DEC.dll") 
clip1 = Mpeg2Source("combine.d2v").Crop(16, 0, 688, 576).ConvertToRGB32
noise = AviSource("noise.avs").ConvertToRGB32
clip1 = clip1.Layer(noise, "add", 8, 0, 0, use_chroma=true)

clip2 = clip1.Trim(125766, 0)
clip = clip1.Layer(clip2, "add", 128, 0, 0, use_chroma=true).Trim(9180, \
    86780).AssumeFrameBased.ComplementParity.Bob

# build de-logo mask
logosrc = AviSource("nologo.avi").Weave.ConvertToRGB32.BilinearResize(59, 13)
masklogo = AviSource("whitelogo.avi").ConvertToRGB32
logo = logosrc.Mask(masklogo).BilinearResize(60, 27)

# now cover up that ugly white logo...
clip = clip.Layer(logo, "add", 255, 582, 36, use_chroma=true)

blur = clip.GeneralConvolution(0,
                 "10 10 10 10 10 
                 10 10 10 10 10
                 10 10 16 10 10
                 10 10 10 10 10
                 10 10 10 10 10")
# sobel edge detection... the power of the matrix!
hor = clip.GeneralConvolution(0,
                 "-1  0  1
                  -2  0  2
                  -1  0  1")
vert = clip.GeneralConvolution(0,
                 "-1  -2  -1
                  0  0  0
                  1  2  1")
edgemask = hor.Layer(vert,"lighten",255,0,0,1)

# now sharpen up just the edges of the blurred image...
clip = clip.Mask(edgemask)
clip = blur.Layer(clip, "add", 128, 0, 0)

return clip

[edit] See Also:

  • See shared functions (and external plugins) written and contributed by the AviSynth community
Personal tools