Check out the Latest Articles:
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 is Avisynth? 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.

Update: A reader (Nisse) has added a little more in depth description of what I’m talking about. You can read it in the comments here.

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 720 pixels 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


  • Morris

    Thank you so much Adub, I have been waiting for this.
    Just a quick question and this is where I always get confused and is about the external filters and their scripts, how do i know what to write or what is the script that i need to use with each filter?
    Thanks again for all your help!

  • http://adubvideo.net Adub

    I think I understand your question. If not, correct me.

    Here is an example filter: Donald Graft’s “Decomb” filter.

    If you download the package from his website (just google it), in it you will see a file labeled “decomb.dll” At first, you may just think the filter is called “Decomb()”. But that is not actually the case. You have to read the documentation to find out which filters are available. For example, one function that is in the package is the “Telecide()” function. THAT one you can use in your scripts.

    In terms of WHEN to use the filters is entirely up to you. If the video looks fine, then there is no need to filter it. If it is interlaced, you may want to use something the in the decomb package. If it is noisy, you may want to use a denoiser like Fluxsmooth or anything from the Avisynth Wiki – Denoise section.

    Did that answer your question?

  • Morris

    Kind of Adub, first of all let me tell you that your guide answered a lot of questions i had and i thank you again for taking your time to do this, ok so let’s say i download the Fluxsmooth, how do i know what the script is that i need to use with that filter?

  • http://adubvideo.net Adub

    Hmm…okay, let me try it this way.

    Whenever you create an Avisynth file (a “.avs” file) and you have some text in the file (like any of my above examples) this is called a script.

    Now, you can call functions in one script from another script. For example, I have 2 scripts. One is called functions.avs and another is called myvideo.avs.

    I write up some lines in “myvideo.avs”. Like this:

    Directshowsource(“avideo.mp4″)
    Crop(1,1,-1,-1)

    But then I think, “Hey, I want to use a function that I created in my functions.avs file!”
    My functions.avs could contain this:

    function ThisDoesNothing(clip a, int “hello”, int “world”)
    {
    hello = world
    return(a)
    }

    So, when I want to use the function in function.avs, I simply open up myvideo.avs and change it to this:

    Import(“functions.avs”)
    Directshowsource(“avideo.mp4″)
    Crop(1,1,-1,-1)
    ThisDoesNothing(2,2)

    Does that make sense?

    Now, there are no filters that “need” any scripts in order to be used. When you are working on a script, you simply call the filter with your desired parameters/settings.

    Example (with fluxsmooth’s function – FluxsmoothST())

    Directshowsource(“avideo.mp4″)
    FluxSmoothST(7,7)

    I would then save this as to a .avs file (ex: MyDenoisedVideo.avs) and then load that into meGUI or VirtualDub or Media Player Classic for preview.

    Does that answer your question?

    Filters do not “need” scripts. Filters are used in scripts. Filters “need” parameters to be told what to do BY the scripts.

  • Morris

    OK i think i am avisynth impaired, hehe so let me ask you this
    I found this on a tutorial:

    “How to use AviSynth with the Convolution3D “video noise” filter”

    and it says use this code

    LoadPlugin(“Convolution3d.dll”)
    avisource(“D:\CAPTURE\capture.avi”)
    crop(8,4,-8,-4)
    SeparateFields()
    odd=SelectOdd.Convolution3D (0, 6, 10, 6, 8, 2.8, 0)
    evn=SelectEven.Convolution3D (0, 6, 10, 6, 8, 2.8, 0)
    Interleave(evn,odd)
    Weave()
    DoubleWeave.SelectOdd()
    AddBorders(8,4,8,4)
    LanczosResize(352,480)
    ConvertToRGB(interlaced=true)

    And save it with notepad with the extension AVS.

    SO this is my question if it wasn’t because that tutorial is telling me to use that code, how would i know or where else do i find or how in the world do i come up with that code? that is where i get confused the parameters, the commands where are they? how do i know what code to use? is that included on the filters or in the pluggins download?

    Thanks for your patience

  • http://adubvideo.net Adub

    Ah, I see!

    Well, somethings you just have to learn. Like the whole “SelectOdd” line is to select the odd fields in a video stream.

    But I think you are trying to dive before you can swim. There are some semi-advanced topics in that code that you have to understand before you will “get” what the script does.

    An excellent place to start is by pulling that script apart and reading the Avisynth documentation. You can look at that script one line at a time and then look up the filters documentation to understand what it does.

    Each filter comes with documentation describing its function and what its parameters mean, a long with suggested values (usually the defaults) and a whole host of other things.

  • Morris

    Aha that’s what i wanted to know, ADUB you are great man and i think you are right i might be trying to absorb all of this at once and i probably need to take it step by step but now i know where i can start and where i can get those parameters.
    You have been and excellent guide and i hope you are not frustrated with me i will continue encoding and learning and if i have any other question i know i can count on you.
    Thank you much!

  • Morris

    Hi Adub,
    Well I encoded my first movie with Megui and let me tell you that I couldn’t be happier with the result. I finally understood how to use filters and scripts, you showed me the way and I want to THANK you again for taking time to make this guide and all the other ones.

  • http://adubvideo.net Adub

    Morris, I very glad that you were able to get everything worked out. Isn’t it great?

  • Morris

    Yes it is great, Thanks Adub!

  • Nisse

    Great little article. Just wanted to feedback a bit.

    I think Avisynth is more accurately described as a frame server that supports various operations on video through scripting prior to serving the video, rather than merely being a scripting language.

    It might also help if you clearly specified that .avs files are simply text files ending in .avs instead of .txt which your video editing/encoding app can open and be “fooled” into thinking they’re real video files, because Avisynth is serving the individual frames.

    The main point of Avisynth and frame servers in general is that they enable folks to skip the intermediate huge files that often result during video editing.

    Media Player Classic and certain other players will open .avs files, so if you need to make any adjustments for a particular playback circumstance or you want to mess around, it’s real easy.

    A few other apps, such as AVSEdit, provide an easy way to edit scripts and see the results on the fly. MeGUI has the same capability, just edit the script during the setup phase and hit the preview button again and it’s instantly refreshed.

  • http://adubvideo.net Adub

    You are right Nisse, however, I originally wrote this article from a completely “noob” point of view. Basically, I didn’t want to use “big words” like “frame server” as this can dissuade readers. However, since you so eloquently described, I will annotate the guide.

  • Spongo

    This has been very useful and encouraged me to delve much deeper. Many thanks!

  • CaptivatedAudience

    Like most, I very rarely take the time to thank those who put in the hard work to educate us on these topics. But the breathtaking clarity, economy and precision of your explanation of AVISynth here simply compels me to do the needful.

    It took me quite a few hours of sifting through documentation from dozens of sources to accumulate a half-baked clinging-by-my-fingernails grasp of what you tied together seamlessly in a few minutes. I’m looking forward to further “aha!” experiences as I explore your other material.

    You’re about the best I’ve seen at this and, let me tell you, my sampling of the competition has been *very* extensive over many years.

    Which is why I could not let the opportunity go by to encourage you in
    your exceptional work! It is truly *appreciated* out here.

  • Richard

    “I’m looking forward to further “aha!” experiences as I explore your other material.”

    My thoughts exactly. For instance I find Dean’s tutorial of multiAVCHD all a little bewildering (no offence Dean, it’s a superb tool) but Adub make things much clearer.

  • soupdragon

    I use it purely as a frameserver (at which its very good) but I use other peoples scripts… it’s all a bit too technical for me.

    @Richard… I feel the same way about multiAVCHD too, lol.

  • Zalmanking

    Hi, thnaks for the guide. One question I have always had is, how different Avisynth is from VirtualDub (apart from the scripting nature)? I have used VirtualDub and some of its fiters. Why should I use Avisynth? Is it because Avisynth has more useful and sophisticated ‘filters’ than VirtualDub has? what i the real advantage?

  • http://adubvideo.net Adub

    “Apart from the scripting nature” <- This made me laugh.

    The whole point of AVISynth IS its scripting nature. It is THE most powerful scripting language available when dealing with video or audio media.

    Yes, both Avisynth and Virtualdub have plugin support. But Avisynth has a boatload more plugins, and an active plugin development community over on Doom9 (and Doom10).

    Virtualdub is a more of an editing/compression program. You can edit (in a sense) in AVISynth, but only by typing into text documents. Virtualdub uses AVISynth quite frequently. It has a lot of integrated features directly targeted at AVISynth usage.

    The reverse is not true, with one exception. AVISynth does have a plugin that lets you use Virtualdub plugins if you would like, but more often than not there is a native AVISynth plugin that can do the same thing as your desired VirtualDub plugin. And usually do it better.

    I'm not knocking VirtualDub. VirtualDub has its place and its uses, just as AVISynth does. They are not "one or the other". More often, they are both used in synergy.

    AVISynth is used more often for filtering, as its file can be loaded by a host of encoding/viewing programs. VirtualDub (usually) has to export to an AVI first before its effects can be fed to an encoding GUI like MeGUI or RipBot.

  • Zalmanking

    Great. Thanks for the clarificaion.

  • Spud71

    Great tutorial, many thanks