VapourSynth 101‎ > ‎

Importing Videos

A. Importing AVI Files
B. Importing DVD/VOB Files
C. Importing MKV, MP4, & M2TS Files
D Importing High Bit-depth Video


A. Importing AVI Files
AVI files, while less common in digital distribution, is still a common file type that may be encountered. The primary recommendation for importing AVI files is FFMS2 (Ex. A-1). AVISource (Ex. A-2) is one of the functions that may be used, however it requires that the proper decoders be installed to process the video.

Example (A-1):
#######################################
import vapoursynth as vs
core = vs.get_core()
video = core.ffms2.Source(r'video.avi')
video.set_output()
#######################################

Example (A-2):
##############################################
import vapoursynth as vs
core = vs.get_core()
video = core.avisource.AVISource(r'video.avi')
video.set_output()
##############################################

B. Importing DVD/VOB Files
DVDs use MPEG-2 videos stored in VOB containers and the VapourSynth function for importing the video data is d2v.Source.  To use this function an index of the VOB must be made using the software DGIndex.  To do this, open the VOB file(s) in DGIndex and create a D2V file by going to File > Save. Once you have created video.d2v you can then access the VOB video data inside of VapourSynth.

NOTE: It is important that you do not move the VOB files once you have created the D2V index file as it contains an exact path to the VOB files. The D2V file and your script are not required to be in the same directory as the VOB files.

Here is an example of what a script would look like using this function:

Example (B-1):
#####################################
import vapoursynth as vs
core = vs.get_core()
video = core.d2v.Source(r’video.d2v’)
video.set_output()
#####################################

C. Importing M2TS, MKV, & MP4 Files
When it comes to videos that are in M2TS, MKV, or MP4 containers, one of the best methods of importing the video data is to use the function LWLibavSource. This function, which is part of L-SMASH-Works, creates an index of the video data so that it can be handled with frame accuracy like an AVI.

IMPORTANT: The first time a script using these functions is opened up it must read the entire file and create an index file which will cause the software opening the script stop respond. It is important that you DO NOT close the program and allow 2-5 minutes for the index file to be created.

Here are a few examples of what a script would look like using this function:

Example (C-1):
###############################################
import vapoursynth as vs
core = vs.get_core()
video = core.lsmas.LWLibavSource(r'video.m2ts')
video.set_output()
###############################################


Example (C-2):
##############################################
import vapoursynth as vs
core = vs.get_core()
video = core.lsmas.LWLibavSource(r'video.mkv')
video.set_output()
##############################################


HELPFUL TIP: Some MKVs may contain variable framerates, if you have problems with the video appearing to be shorter or longer than it is supposed to be with varying speeds then try using LWLibavSource(r'video.mkv', format="YUV420P8", fpsnum=2997,fpsden=125), this will force the video to be opened using 23.976 frames per second.

Example (C-3):
##############################################
import vapoursynth as vs
core = vs.get_core()
video = core.lsmas.LWLibavSource(r'video.mp4')
video.set_output()
##############################################


D. Importing High Bit-depth Video
When it comes to importing video stored in an MKV container you may also encounter 10-bit video. While VapourSynth allows for processing and output of hight bit-depth videos, most hardware and software you will use typically only supports 8-bit video. This makes it important to understand how to convert 10-bit to 8-bit and the easiest way to do this is to allow the plugin importing the video to handle it. When using LWLibavSource you will need to specify using the "Format" option to make this conversion.

Here is an example of what a script would look like using this function:

Example (D-1):
#################################################################
import vapoursynth as vs
core = vs.get_core()
video = core.lsmas.LWLibavSource(r'video.mkv', format="YUV420P8")
video.set_output()
#################################################################