Script examples

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(Undo revision 7033 by 125.161.21.148 (Talk))
 
m (1 revision)

Revision as of 16:01, 9 May 2013

Here are some examples of AviSynth scripts, grouped in categories of increasing complexity. First download and install AviSynth, then save these scripts with the file extension ".avs" and load them in your favorite video player or editor.

Contents

Simple examples

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)

Example 2: Resizing

AVISource("somevideo.avi")

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

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)

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)

More complex examples

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


Example 6: Write pictures with flash to images from full video

params.avs

filename="somefile.avi"
logfile="output.txt" 
path="P:\ath\To\Files\" 
lumathresh=80 
imageprefix="prefix_" 

FindFlash.avs

Import("Params.avs")
AviSource(path+filename).ConvertToYV12 
WriteFileIf(path+logfile, "(AverageLuma>lumathresh) && (YDifferenceToNext() > 0)", "current_frame","space", "current_frame")

SaveFlash.avs

Import("Params.avs")
AviSource(path+filename) 
ScriptClip(""" ImageWriter(path+imageprefix,myvar, myvar, "bmp",false) """)
ConditionalReader(path+logfile, "myvar", false) 

See Also:

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