Go Back    Forum > Digital Video > Video Project Help > Restore, Filter, Improve Quality

LinkBack Thread Tools
12-10-2019, 11:06 PM
homefire homefire is offline
Free Member
Join Date: Apr 2019
Posts: 26
Thanked 9 Times in 4 Posts
I've found so much information on this forum from people that are far more proficient at this than me but I wanted to combine and organize it in a bit of a quick-start guide. All the info that follows is based off the legends that take the time to help us out so I wanted to pay it forward. A special thanks to Lordsmurf and Sanlyn for all of their wisdom!!

When I first read about AviSynth, I thought "A script based video editor?? How do I preview my changes??That sounds pointless!!" but in reality it is the opposite of pointless, just mildly intimidating. This is not going to be a technical guide where I get into the nitty-gritty. This will be a guide to get familiar with the practicality of functions and plugins.

Installing AviSynth(+)

To start off AviSynth has a main site http://avisynth.nl/index.php/Main_Page where it has several links to syntax guides, plugin documentation and downloads. AviSynth is not the typical windows program, it is portable, meaning no installation necessary. Download the AviSynth archive, extract anywhere and run. Be aware, if the directory labels exceed the character limit, AviSynth will not be able to run. In other words, AviSynth will not run if the directory is named "D:\ThisIsAReallyLongDirectoryName\WithMany\Subdir ectories\That\Does\Not\Allow\AviSynth\ToRun"

Download AviSynth v2.6.0 from SourceForge or be a little adventurous and download AviSynth+ from their homepage. Note: AviSynth+ does use an installer so just be aware of the installation directory that is choosen.

If using AviSynth, I would place the program folder in the "C:\Program Files (x86)" directory and create a shortcut on the desktop, which can be dragged to the start menu.

All scripts and plugins I mention here I have successfully used with AviSynth+ on a Windows 10 64bit PC but I have only used 32-bit plugins.

After installing AviSynth (or before) make sure the Huffyuv codec is installed. If not check this page out: VirtualDub with Filters Pre-loaded + HuffYUV which also has instructions on installing Huffyuv on a 64bit PC. This post also has a download for Virtualdub and useful filters, which I won't get into in this post but will be a large part of the project.

Installing AvsPmod

Next step would be to install (download and unpack) AvsPmod, which is a graphical AviSynth script editor. It was priceless in learning the basics of AviSynth. This was probably the hardest part of the install process for me. Download the program and place the folder in "C:\Program Files (x86)" directory or where ever is ideal. I also make a shortcut on my desktop and drag it to my start menu.

I had a problem with AvsPmod where I would open it and it would immediately close, just a brief flash on the screen. After many hours of tearing my hair out, I realized the way to fix this: Run as Administrator. Right click on "AvsPmod.exe", click "Run As Administrator", then "Apply"

Installing Filters

Once AviSynth and AvsPmod are up and running, it's time to install the filters. This means downloading the files and placing them in the plugins directory of AviSynth or plugins+ of AviSynth+. Some plugins are dll files that can be placed in the directory and others may be a script found on a forum, which can be copied and pasted into an "avsi" file. Both "*.avsi" and "*.dll" filters in the plugins directory are automatically loaded when AviSynth starts.

Sanlyn recommends keeping this folder organized and backed up due to the fact that most of these filters are scattered around the internet and can be difficult to find. Also, some plugins require specific versions of other plugins and some plugins are for newer or older processors so this can be a haphazard step of trial and error.

RemoveDirtMC is a very useful plugin, will be explained later, which needs two dll's to be placed in the system directory since they are no longer included in windows. More information on this can be found in this great post by Sanlyn http://www.digitalfaq.com/forum/vide...s-running.html.

QTGMC is probably the best deinterlacing filter available, at least for most situations I've encountered. This can be a hassle to install due to the dependencies. I followed this guide here: https://macilatthefront.blogspot.com...pdate-and.html. It has the process to install both 32bit and 64bit versions of QTGMC and ffmpeg but I just followed the 32 bit instructions.

I attached my plugins folder, where I ignored Sanlyn's excellent advice of organization but I was already too far in to turn back. I'm fairly certain all of the plugins are the latest version, or the correct version if I found some that are incompatible with certain versions of dependencies. Please correct me if I am wrong. Feel free to drop directly in, unless there are plugins are already installed.

My first script

Now we are ready to go! I assume the video is already captured using Sanlyn's Capturing with VirtualDub [Settings Guide] which is priceless. If ripping off of a DVD, then copy the DVD files to a folder on the hard drive and use this guide to create a "d2v" file that can be loaded into AviSynth. If this is a protected DVD, I do not have much experience but this might help this guide.

The media file then needs to be imported. The full list of compatible formats and the appropriate import function can be found http://avisynth.nl/index.php/Importing_media. Both video and audio can be imported and combined but there isn't much flexibility with restoring audio.
#For AVI files

#For MPEG2 or D2V

#For importing audio and video separately
return last
Quick AviSynth Syntax
AviSynth uses scripting with the basic syntax:
#The "#" symbol indicates comment - line is ignored
# The "\" is a line continuation character
#Functions are follow by "()"
#Arguments are put in the "()" after a function 
Functions are applied to the "last" video segment output by the previous statement. Functions can be daisy chained. The function is applied to the output of the previous function: Last-> Function1 -> Function2 -> Function3
Avisynth scripts can use variables to store values, numbers or clips. This allows parts of a clip to be cut into segments and stored for later use. Last is a special keyword that tells avisynth to use the output of the previous command. This gives the flexibility to operate on specific parts of a clip and store other parts for later usage.

The "Trim(clip,int first_frame,int last_frame,bool pad)" function allows a specific part of a clip to be selected to pass to a function or store.
whole_clip = last
first_part = Trim(0,100) #set first_part variable by trimming clip from frame 0 -> 100
second_part = Trim(101,framecount) #FrameCount is an internal variable for total number of frames in clip

#Perform Function1() on whole clip
whole_clip_function = last

#Perform Function2() on first part of clip
first_part_function = last

#Perform Function3() on whole clip
second_part_function = last

#Add processed first and second part with ++
first_part_function ++ second_part_function

#Processed original clip can referenced if needed

#"++" or AlignedSplice() which ensures video and audio stay synchronized
#"+" or UnAlignedSplice() adds audio and video without regard for synchronization
A note on the syntax of Function documentation. If you noticed when I included the full syntax for the "Trim(clip,int first_frame,int last_frame,bool pad)" function, it shows 4 arguments (clip, first_frame, last_frame, pad) but I only included 2 in my script. The very first argument is the clip that is being passed into the function. It is implied that that the "last" output is passed into the function without having to explicitly declare it. However, you can pass a specific clip that you stored in a variable. For example, at the end of the previous script you can add the following:

#Extract another part of the entire clip
another_clip = Trim(whole_clip, 15, 50)
The fourth argument, "pad", has a default value that does not require it to be set when calling a function. That's why the same functions (filters) posted in the sample scripts can be set with or without arguments.

This is by no way exhaustive or comprehensive, just enough to be able to interpret and tweak the scripts that are posted throughout the forum. Read this for more information.

To be continued....

Attached Files
File Type: zip plugins.zip (29.49 MB, 61 downloads)
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Ads / Sponsors
Join Date: ∞
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
12-12-2019, 12:25 AM
lordsmurf's Avatar
lordsmurf lordsmurf is online now
Site Staff | Video
Join Date: Dec 2002
Posts: 12,874
Thanked 2,347 Times in 2,001 Posts
The image doesn't seem to be attached. Try again, new post, I'll merge.
I've not yet read the post, hope to soon.

- Did my advice help you? Then become a Premium Member and support this site.
- For sale in the marketplace: TBCs, workflows, capture cards, VCRs
Reply With Quote
12-12-2019, 06:29 PM
homefire homefire is offline
Free Member
Join Date: Apr 2019
Posts: 26
Thanked 9 Times in 4 Posts
Very weird, the image that was supposed to be attached above to fix AvsPmod on Windows 10:

I am working on the next section, should be posted shortly

Attached Images
File Type: jpg runasadmin.JPG (41.0 KB, 249 downloads)
Reply With Quote
12-12-2019, 09:43 PM
homefire homefire is offline
Free Member
Join Date: Apr 2019
Posts: 26
Thanked 9 Times in 4 Posts
AvsPmod Graphical Interface

I'm not sure if I clearly conveyed this above but AvsPmod is completely optional, it just helps with tweaking the filter and plugin arguments. Each plugin and function in the script has a graphical interface that allows arguments to be adjusted and previewed in real time:

The preview video can be updated by just left clicking on it after making changes to the script. AvsPmod also has a call tips which show as you open the "(" in a function. They can also be shown by right clicking with the cursor on the function -> "AviSynth Function" -> "Show calltip"

Clicking "Filter Help File" in the "AviSynth Function" menu does a google search for avisynth and the function name. This can be useful to view the documentation on the functions you are using. The "Show Function Definition" button opens the function definitions window where it shows the arguments and default values of that function. The window below that is "add or override AviSynth functions in the database" where it shows:
Core Filters Internal AviSynth Functions
Plugins Filters located in the plugins(+) folder with dll extension
User Functions Filters in plugins(+) folder wit avsi extension
Script Functions Utility functions to perform operations in scripts
Clip Properties Built-in variables that are available, i.e. framecount

Let's look at the BlankClip function defition:
[clip "clip"],
int "length"=240,
int "width"=640,
int "height"=480,
string "pixel_type"="RGB32" ("RGB32"/ "RGB24"/ "YUY2"/ "YV24"/ "YV16"/ "YV12"/ "YV411"/ "Y8"),
float "fps"=24,
int "fps_denominator"=1,
int "audio_rate"=44100,
[bool "stereo"=False],
[bool "sixteen_bit"=True],
int "channels"=1,
string "sample_type"="16bit" ("8bit"/ "16bit"/ "24bit"/ "32bit"/ "float"),
int "color"=$000000,
[int "color_yuv"]
The word before each argument is the type of value that can be passed to the argument. "int" refers to integer but can also be hex. Suprisingly "string" expects a string to be passed. The string must be in double quotation marks. "bool" or boolean can be True or False. Float can be a whole number or decimal. The square brackets around the argument mean that it is implicitly set, such as in clip. If the argument has a value defined, "length"=240, that is the default value if you do not set the argument when calling the function. There can also be a list of expected values, "sample_type"="16bit" ("8bit"/ "16bit"/ "24bit"/ "32bit"/ "float") where you can only pass those values in parenthesis to that argument.

If for some reason AvsPmod is not working correctly, VirtualDub can preview changes almost as easily. After you save your script as an "avs" file open with VirtualDub. After each change is saved to the script, File-> Reopen Video will load the changes while keeping filters and settings in VirtualDub intact.

Color Spaces - YUV, RGB, WTF?

There are extensive resources on the net and posts in this forum that dive into the details of color spaces but I will give a 10,000 foot overview. Color spaces are the format in which color and brightness is encoded in the video. The format or compression codec (mpeg, mp4, avi, etc.) does not indicate the color space of the file. Hopefully, you know what color space the video is in since you captured it but just in case you can use MediaInfo. MediaInfo is a great tool that shows the color space, format, resolution and many other properties of a video. For now we will focus on just color space.

Color spaces are important because each color space allows different adjustments to be made to your video. Also, converting between color spaces is not ideal because the math involved causes rounding errors, eliminating some color information and degrading the quality. This is not a major issue but just something you should be aware of when working with your video. The function or software used to convert color spaces also impacts the quality degradation due to decimal precision. Avisynth is the preferred methods of converting between YUV and RGB.

RGB - Red, Green, Blue

RGB (Red, Green, Blue) is the most commonly known color space. It defines the color of the video by adding together amounts of red, green and blue light. Controlling the intensity of each color, controls the output color. For example, zero intensity is the darkest of each color making black and the highest intensity of all three colors making white.

Adjusting the R, G, B levels provide millions of different hue, saturation and lightness shades. The bit depth of an RGB video defines the amount of different combinations of red, green and blue. A 24bit RGB video provide 8bits per channel which allow values of 0-255 for each channel. RGB32 is a 32bit RGB video that has an extra alpha or greyscale layer of you guessed it 8bits, that provides additional shading control. RGB32 is most commonly used when working with video on a PC because processors can more efficiently handle it, even if the alpha layer contains no data (which is definitely the case if converting from YUV).

The primary ideas to remember when it comes to RGB is it results in a much larger file size than YUV but allows you to target specific colors more easily. As a result, conversion to RGB is typically an intermediate step used for VirtualDub filters and color correction.


YUV or YCbCr is the most common color space of broadcast television due to the human perception of color. The color information is broken up into one luma channel (brightness) and two chrominance (color) channels. Adjusting the "Y" or luma, can change the brightness levels of the video without altering the color data. Targeting specific colors is more difficult but shifting from green to red and yellow to blue can be done with ease by targeting the V and U channels, respectively.

Chroma Subsampling

The UV channels of the YUV color space contain the color information. The efficiency of YUV over RGB is the ability to discard some of the chroma or color information without impacting the human perception of the video. You may see YUV 4:4:4, YUV 4:2:2 and YUV 4:2:0. Going from YUV 4:4:4 to YUV 4:2:2 cuts the chroma data in half, resulting in a video with one third of the bandwidth but no perceptional difference while viewing the video. To complicate things further, each YUV color space can be arranged differently as in packed or planar formats.

There's no need to get too deep into the math behind this, just to be aware of the way different color spaces hold data. Most captures should be in YUY2, which is just a specific way of encoding YUV 4:2:2. There's no need to move up to 4:4:4 because most VHS players output 4:2:2 or 4:2:0, so to the additional chroma data would just be interpolated and there would be no added benefit for the larger file size.

Another consideration between YV12 and YUY2 is the speed of AviSynth filters. As I mentioned before some filters can use YV12, YUY2 or both. Typically when a filter can use both, YV12 will be faster if speed becomes an issue.

Another common format is YV12 which is a way of storing YUV 4:2:0. YV12 is used by many video formats such as MPEG-4 (x264, XviD, DivX, etc.), MPEG-2 for DVD's and MPEG-1.

What does it all mean?

The main point's to consider with color spaces are file size, speed (of filters), quality and purpose. If you have an old video that you need to perform heavy restoration and color correction on, YUY2 is usually the recommended capture format to maximize the availability of color data. However, after capture you must also consider what you need to "do" to the videos.

Certain AviSynth filters only work in YUY2 or YV12 formats, so there should be a strategy to avoid unnecessary conversions. Capturing in RGB is usually not recommended due to the large file size and the likely conversion you'll have to make to work in AviSynth. The larger file size does not mean improved quality either, television or VHS output is in YUV. If someone know's a reason to capture with RGB, please post a comment.

However, if you are not making many corrections or changes and plan to burn to a DVD, YV12 might be sufficient to capture in. For more information on color spaces read AviSynth's Color Spaces Wiki Page and good ol' google

A workflow might be Capture YUY2 -> Process in AviSynth YUY2 & YV12
For further color correction convert to RGB32 in AviSynth -> VirtualDub or NLE
If burning to DVD, you can leave in YV12 and use a DVD encoding tool to convert to MPEG. This is discussed ad nauseum by Lordsmurf in many of his guides such as this one Introduction to Video Encoding/Converting, Part 1.

An important thing to remember is the software doing the conversion has a noticeable impact on quality. It's better to convert between YUY2, YV12 and RGB in AviSynth due to the high precision of the math being done behind the scenes. I've read that VirtualDub does not handle the conversion to RGB that well so converting to RGB in AviSynth will be better than allowing virtualdub or another editor to do it.

Another note on VirtualDUb is that it is an RGB video processor, meaning any filters being used will automatically convert the video to RGB and then to whatever format your output is. That is unless you have direct stream copy selected, which will output in the format that's input.

More to come.....

If I got anything wrong or there's any incorrect information, please correct me :
Reply With Quote
The following users thank homefire for this useful post: WestRGB (10-03-2020)

Similar Threads
Thread Thread Starter Forum Replies Last Post
AviSynth Scripts/Guide dnppro Restore, Filter, Improve Quality 6 10-24-2020 07:19 PM
How to Recover Video from Unfinalized DVDs [QUICK GUIDE] admin Blank Media 0 12-16-2010 03:43 PM
How to Recover Video from Unfinalized DVDs [QUICK GUIDE] lordsmurf Capture, Record, Transfer 1 12-08-2009 05:20 AM
Create Motion Menus with Adobe Premiere [QUICK GUIDE] lordsmurf Author, Make Menus, Slideshows, Burn 4 04-01-2009 07:45 AM
Where to Find DVD Menu Artwork? [QUICK GUIDE] lordsmurf Author, Make Menus, Slideshows, Burn 3 02-21-2008 03:06 AM

Thread Tools

All times are GMT -5. The time now is 01:18 PM