Creating & Handling Clips

A. Creating Clips

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 (Ex. A-1). 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 VapourSynth 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):

Create Clip with Trim

from vapoursynth import core
video = core.lsmas.LWLibavSource(r'video.mkv')
video = core.std.Trim(video,50,100)
video.set_output()

IMPORTANT: If you are creating clips of an interlaced source, make sure to remove the interlacing before clipping to avoid causing problems for interlace removal.

Alternatively, the slicing operation in Python can be used to create clips as well (Ex. A-2). Unlike the Trim function, this method does not include the end frame. This method also allows for easily reversing the clip as well (Ex. A-3). Here are some examples of using this method to create clips:

Example (A-2):

Create Clip with Slicing

from vapoursynth import core
video = core.lsmas.LWLibavSource(r'video.mkv')
video = video[50:100]
video.set_output()

Example (A-3):

Create Reverse Clip with Slicing

from vapoursynth import core
video = core.lsmas.LWLibavSource(r'video.mkv')
video = video[100:50:-1]
video.set_output()

B. Combining Different Sources

While combining different sources may seem straightforward, there are many video that you must take into consideration to avoid errors and other issues. The video resolution, frame rate, and color space must all match. 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.9760001 and is rounding off. The easiest way to avoid this without altering the number of frames is using the 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):

from vapoursynth import core
video1 = core.LWLibavSource(r'video1.mkv').std.AssumeFPS(fpsnum=2997, fpsden=125)
video2 = core.LWLibavSource(r'video2.mp4').std.AssumeFPS(fpsnum=2997, fpsden=125)
finalvideo = video1+video2
finalvideo.set_output()