AviSynth 101‎ > ‎

Importing Videos

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


A. Basic Video Importing
One way to import and process video through AviSynth is to dedicate the entire script to one video source by not specifying a variable name for it to be stored as (Ex. A-1). AviSynth works by processing the script starting at the top and working its way down so when using this method the video output from one function will be the source for the next.  For the sake of this guide I will refer to a video not stored in a user defined variable as a floating video.

NOTE: It is recommended that you create your script in the same directory as the video you intend to import into the script. If you wish to import a video from another directory you will need to specify the full path to the video file (ex. C:\videos\video.avi).

Example (A-1):
######################
AviSource("video.avi")
######################

Another method to handle video in AviSynth is to import a video clip and store it as a named variable, which will allow you to open multiple clips in one script. This way of handling video makes the script much more complex and is not always needed for handling basic video filtering. By handling video this way you must also specify which variable containing video data for functions to use and which variable the script will return (Ex. A-2).

Example (A-2):
##############################
video = AviSource("video.avi")
return video
##############################

B. Importing DVD/VOB Files
DVDs use MPEG-2 videos stored in VOB containers and the AviSynth function for importing the video data is mpeg2source.  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 AviSynth.

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):
##############################################
mpeg2source("video.d2v")
##############################################

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 LWLibavVideoSource. This function, which is part of LSMASHSource, 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):
################################
LWLibavVideoSource("video.m2ts")
################################


Example (C-2):
###############################
LWLibavVideoSource("video.mkv")
###############################


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 LWLibavVideoSource("video.mkv", format="YUV420P8", fpsnum=24000,fpsden=1001), this will force the video to be opened using 23.976 frames per second.

Example (C-3):
###############################
LWLibavVideoSource("video.mp4")
###############################


Alternatively, the most accurate way of handling M2TS, MKV, or MP4 containered videos from Blu-ray discs would be to use DGDecodeNV.  This particular software is not free and requires a compatible video card so that the videos can be hardware decoded.  This method is similar to how DVD VOB files are handled, please refer to the documentation for more information on how to use DGDecodeNV.

D. Importing High Bit-depth Video
When it comes to importing video stored in an MKV container you may also encounter 10-bit video. Most hardware and software you will use typically only supports 8-bit video, therefore it is 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 LWLibavVideoSource 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):
##################################################
LWLibavVideoSource("video.mkv", format="YUV420P8")
##################################################