Avisynth And Its Plugins

A question that people ask me on a pretty regular basis is "What the heck is Avisynth?" Well, I'll tell you. But be warned, this post can get a bit..."wordy".

A Little History...

Avisynth is a program that started as a small software project by Berkley student Ben Rudiak-Gould. Since it's creation, Avisynth has seen a explosion in development from the open source community and has been released in numerous versions (at the time of this writing, it is at version 2.5.8 stable, and 2.6.0 alpha 2).

Additional development has been contributed by authors Edwin van Eggelen, Klaus Post, Richard Berg, Ian Brabham, and many others. There have even been sub-versions created to add support for multithreading and fix several bugs (the current plan is to incorporate multithreading support into version 2.6.0).

But I digress. So what exactly isAvisynth? Avisynth is a scripting language of sorts. More specifically, it is a scripting language targeted at video post-production. When I say "video" I actually (kind of) mean "film" in the essence of both video and audio, as Avisynth can manipulate both video and audio streams.

Anyways, Avisynth is essentially a way to use a simple text file to decode and transform a video file.

Ex.

Avisource("C:\\A\\path\\to\\my\\video.avi")


The example above can be all that is necessary in some instances. For example, someone could create a file with the above contents and then load that ".avs" file into a program like MeGUI or VirtualDub and start encoding.

But frankly that is a little boring.

What you will see more often is something along the lines of the following:

Ex.

DirectshowSource("C:\\A\\path\\to\\my\\video.mp4")
Crop(4,0,-4,-0)
Spline36Resize(720,480)


Okay, so let's go over what I just did. First off, notice how I used DirectShowSource instead of Avisource? The difference is that Avisource should only be used to open AVI files (files that end with the ".avi" file extension) while DirectshowSource can be used to open pretty much anything (with some caveats). One caveat is opening DVD VOB files. When opening VOB files, you should use Donald Graft's DGDecode plugin, but we will get to that later.

Note: I wrote a tutorial a little while back about properly configuring your DirectShow settings. You can read it here.

Secondly, notice that Crop line? I'll give you one guess as to what it does. That's right! It crops the video! To be more specific, it crops 4 pixels from the left side of the video and 4 pixels from the right side of the video. The top and the bottom are left alone. This can be used to remove dirty edges from videos or to crop off black bars. For more information on the crop filter, refer to the Avisynth documentation or the Avisynth Crop wiki page.

Thirdly, look at the Spline36Resize line. I don't expect you to know right away what this does, but the hint is at the very end of the name. "Resize". That's right, this little function resizes my video to 720 pixels wide by 480 pixels high. Does that make sense?

To be clear, when working with Avisynth scripts everything you do will be through the use of functions calls. For those of you who are not programmers, a function call looks like this:

Ex.

FunctionName(parameter 1, parameter 2, parameter 3, etc...)


Not all functions have more than one parameter, or even any parameters. Often, you can call a function just like this:

Ex.

DirectShowSource("myvideo.mp4")
FunctionName()


Now, some functions do require parameters, like our Spline36Resize function. Remember how I wanted to resize to 720pixels by 480 pixels? Well, all I needed to do is enter those numbers into the parameters of the Spline36Resize function and viola!

Ex.

Spline36Resize(720,480)


This will now produce an video stream that is 720 pixels wide by 480 pixels high!

Internal Filters

All of the function calls that I have made in the above examples have been to Internal Filters. What this means is that these filters come with Avisynth when you install it. You can see all of the available filters in the documentation or on the Avisynth Wiki. Don't be overwhelmed because even I don't know all of the internal filters. Just get familiar with some of them and the rest will come naturally.

External Filters

This is where the power of Avisynth really starts to shine. An external filter is an Avisynth filter that you can download from the internet to expand Avisynth's functionality. All filters take the form of ".dll" files and are placed in Avisynth's "Plugins" folder, which can be found in the Avisynth install folder (usually in your Program Files folder in Windows).

In order to call a filter, all you have to do is make sure that the filter is in your Plugins directory, and then use the same function calling syntax that I detailed earlier.

Ex.

DirectshowSource("myvideo.mp4")
AnExternalFilter(param 1, param 2)


There is a whole host of external filters available. More and more are debuted on the Doom9 forums practically every day. No body actually knows how many external plugins exist, but this Avisynth Wiki page is a good place to start when looking for a new plugin.

External Scripts

One last section that I want to talk about is using External Scripts in your Avisynth files. The cool thing about external scripts is that they are just text files. They can be downloaded and placed in the Plugins folder just like external filters, but need a special file extension if you want them to load automatically. If you want a script to be automatically loaded by Avisynth every time you use it, give the script a ".avsi" extension, instead of the standard ".avs" Avisynth file extension. Now, you can use an external script just like a filter when you are ready to call it.

Ex.

DirectshowSource("myvideo.mp4")
MyExternalScript(param 1, param 2, param 3)


Conclusion

I hope that this little introduction into Avisynth has helped you in some way, and if it hasn't, let me know in the comments and I'll add on to this post to make it more clear in the future.

Again, this post is just an introduction into Avisynth to make it a little less scary. If you want to get into Avisynth, I suggest you start reading the documentation that is installed with Avisynth. In addition, the Doom9 forums and the Avisynth Wiki are fantastic resources.

All in all, I wish you good luck!

References

Anime Music Videos Guide - http://www.animemusicvideos.org/guides/avtech/amvappavisynth.html

Avisynth Wiki - http://avisynth.org/mediawiki/Main_Page

Doom9 Forums - http://forum.doom9.org/forumdisplay.php?f=69