AfterDawn.com

Basic Editing



In addition to advanced video editing capabilities, AviSynth includes basic filters to cut and join clips. When cutting or joining video you can use VirtualDub, or a similar tool to identify the frame ranges for clips. Another solution is to use a script editor that can either interface with VirtualDub or provide you with a preview of its own. AVSEdit and AvsP are two such editors. They both even have special interfaces for both cutting and joining clips from one or more sources.
There are two general approaches to cutting and joining. The first is to think in terms of what's being removed. Although AviSynth can be used this way it's a little more complex so we'll be staying away from it for now. For purposes of this guide you'll need to explicitly tell AviSynth what frames to keep. You can select multiple ranges of frames (to remove commercials for example) and join them together.

Shorthand

Since these are such basic editing operations AviSynth includes some special notation that allows you to join clips with a minimal amount of text, and in an easier to read format. An explanation of this, along with some examples, is at the end of this section. If you're in a hurry you can skip to the end and skip the detailed explanations.




Trim


Trim (clip, int first_frame, int last_frame [, bool pad_audio])


ArgumentTypeDefaultReqDescription
clipcliplastThe clip to select frames from.
first_frameint*First frame of selection (new clip).
last_frameint*Last frame of selection if positive. Last frame of clip if 0. Number of frames to include if Negative -
pad_audioBooleanTruePad audio to match any delay in the original

Trim creates a new clip containing the range of frames you enter. Since there are situations where the number of frames in a file is unknown by the script author, Trim allows you to use 0 for the last_frame argument to specify the last frame of the file. You can also use a negative number like -100 for last_frame to select the number of frames instead of the ending frame number.

In most cases you won't want to change pad_audio from True because many commercial sources have audio that's shorter than the video. Since beginning frames don't usually have audio, the audio stream from a DVD or similar source is typically delayed well under a second, but enough to cause problems if not kept in sync.

Example Code

Create a clip with frames 500 - 10000:
Trim(500, 1000)

Create a clip with the first 1000 frames:
Trim(0, 999)

or

Trim(0, -1000)

Create multiple clips from the same source clip:
clipOne = Trim(0, -1000)
clipTwo = Trim(1500, 3000)

When To Use It

When you don't want all the frames from a clip you can use Trim to select the frames you want. You can remove commercials from video by selecting only the frames for a television show. You'll need to splice them together later if you want to produce a single clip from clips created by multiple uses of Trim.

Related Software

In order to use Trim it's usually necessary to visually inspect your video. You can use a program like VirtualDub to open the AVS file, or you can use a script editor with built in preview, or even automated Trim capability. For MPEG-2 files you could also get frame numbers from DGIndex when creating a D2V project file.




AlignedSplice


AlignedSplice (clip1, clip2 [, ...])

ArgumentTypeDefaultReqDescription
clip1clip*First clip to join
clip2clip*Second clip to join
clipNclipAdditional (optional) clips after the second


AlignedSplice joins two clips, keeping the audio in each clip in sync with its respective clip. In other words, if the audio in the second clip starts 30milliseconds after the video, it will remain synchronized with the video after the splice as well. More than two clips can be spliced from a single instance of this filter. See below for an example of this. There's also a shorthand method of using AlignedSplice that's covered at the bottom of this section.

Example Code

Join two clips assigned to variables:
clipOne = Trim(0, -1000)
clipTwo = Trim(1500, 3000)
AlignedSplice(clipOne, clipTwo)

Select and join 2 clips from one source:
AlignedSplice(Trim(0, -1000), Trim(1500, 3000)

Join more than 2 clips:
clipOne = Trim(0, -1000)
clipTwo = Trim(1500, 3000)
clipThree = Trim(4000, 5999)
clipFour = Trim(7500, 0)
AlignedSplice(clipOne, clipTwo, clipThree, clipFour)

When To Use It

Nearly every application for joining multiple clips together calls for AlignedSplice in order to maintain audio sync.




UnAlignedSplice


UnAlignedSplice (clip1, clip2 [, ...])

ArgumentTypeDefaultReqDescription
clip1clip*First clip to join
clip2clip*Second clip to join
clipNclipAdditional (optional) clips after the second


UnAlignedSplice joins two or more clips without respecting audio delay. This should only be used in cases when the clips are contiguous (ie one file is a continuation of the other) and there are different delays (incorrectly) applied to the second clip. The audio in the second clip will simply be appended directly to the end of the audio in clip1 with no additional delay. This doesn't affect any delay in the first clip.

Example Code

Join two clips assigned to variables:
clipOne = Trim(0, -1000)
clipTwo = Trim(1500, 3000)
UnAlignedSplice(clipOne, clipTwo)

Select and join 2 clips from one source:
UnAlignedSplice(Trim(0, -1000), Trim(1500, 3000)

Join more than 2 clips:
clipOne = Trim(0, -1000)
clipTwo = Trim(1500, 3000)
clipThree = Trim(4000, 5999)
clipFour = Trim(7500, 0)
UnAlignedSplice(clipOne, clipTwo, clipThree, clipFour)

When To Use It

Use UnAlignedSplice only when the audio in one clip is a continuous stream from the clip preceding it. This normally only occurs when muxed video and audio are saved in segmented files, where one file just stops and the streams are continued in a new file. When in doubt, try AlignedSplice first because it's usually the right choice.




Shorthand Splicing


Since some editing jobs require joining a lot of clips together, it makes for scripts that are easier to decipher if there's an alternative way to use the AlignedSplice and UnAlignedSplice filters. Fortunately AviSynth's developers agree with that, and the alternate notation of ++ for AlignedSplice and + for UnAlignedSplice are available. Instead of using
AlignedSplice(Trim(0, -1000), Trim(1500, 3000)

You can use
Trim(0, -1000) ++ Trim(1500, 3000)


You can also use this notation for more than two clips
Trim(0, -1000) ++ Trim(1500, 3000) ++ Trim(4000, 5999) ++ Trim(7500, 0)


And of course you can also use variables if you want
clipOne = Trim(0, -1000)
clipTwo = Trim(1500, 3000)
clipThree = Trim(4000, 5999)
clipFour = Trim(7500, 0)
clipOne + clipTwo + clipThree + clipFour


Remember to use ++ for AlignedSplice and + for UnAlignedSplice.
Written by: Rich Fiscus