Creating & Handling Clips
A. Creating Clips using Trim
Often you may find yourself with a long video that you do not need to export in its entirety, this is where the function Trim is useful. This function will allow you to isolate a small segment of a video, and is very handy for filtering small sections or just combining short clips from multiple videos. To make a clip you need to identify the a starting and ending frame numbers so AviSynth will know exactly where your new clip will begin and end. To find these numbers it is easiest to open the entire video in VirtualDub and look at the bottom information bar (next to the control buttons) where it shows the number of the current frame being displayed. Here is an example of how to export a shortened video using the Trim function:
Example (A-1):
AviSource("video.avi")
Trim(0,85)
IMPORTANT: If you are using the Trim function on interlaced source, make sure to remove the interlacing before clipping to avoid causing problems for interlace removal.
Alternatively you could use this function to combine several clips and export them as one video. You can use this to combine several clips from the same video or clips from different videos. Here is an example of how you can take small clips from the same video and combine them:
Example (A-2):
Video = AviSource("video1.avi")
FinalVideo = Video.Trim(0,55)+Video.Trim(80,150)+Video.Trim(56,100)
return FinalVideo
It is possible to combine clips and then dub in another audio source afterwards. This actually makes it possible to create entire anime music videos using only AviSynth. Here is an example of how to combine multiple clips and then dub in audio:
Example (A-3):
Video = AviSource("video1.avi")
FinalVideo = Video.Trim(0,55)+Video.Trim(80,150)+Video.Trim(56,100)
Audio = WavSource("Audio.wav")
return AudioDub(FinalVideo,Audio)
B. Combining Different Sources
While combining different sources may seem straightforward, there are many video and audio details that you must take into consideration to avoid errors and other issues. When combining videos the video and audio specs must match exactly or AviSynth will give you an error message. The video resolution, frame rate, and color space must all match. All videos must either have no audio or have audio that matches in frequency, sampling rate and number of audio channels.
One confusing yet common problem you may run into is frame rates not matching. Even if two clips report a 23.976 frame rate, there is the possibility that one of them could actually be 23.976001 and is rounding off. The easiest way to avoid this without altering the number of frames is by using AssumeFPS when importing each clip to ensure that the frame rates match. Here is an example of importing and combining two clips and specifying the frame rate:
Example (B-1):
Video1 = AviSource("video1.avi").AssumeFPS(23.976)
Video2 = AviSource("video2.avi").AssumeFPS(23.976)
FinalVideo = Video1+Video2
return FinalVideo
Alternatively you can pull the exact frame rate from the first clip and pass it along to the next by using the FrameRate function. Here is an example of how that would be used:
Example (B-2):
Video1 = AviSource("video1.avi")
Video2 = AviSource("video2.avi").AssumeFPS(FrameRate(Video1))
FinalVideo = Video1+Video2
return FinalVideo
When importing videos it is important to not only make sure the video frame rate matches, but also to make sure the audio bit depth, sampling rate, and number of audio channels match up as well.
IMPORTANT: When you are joining videos together, if the audio length is shorter or longer than the length of the video of a particular source, then the audio of any clip added afterward will be shifted to compensate. This will affect the audio sync for all clips added after the audio shift occurs. It is recommend that you use ++ to combine clips with audio because it will trim off any excess or add in additional blank audio to insure it is the same length as the video.