Introduction to Using AVISynth

AVISynth was a clever image processor which plugged into the video framework of Windows up until Windows 7 (with tweaking). It doesn't work on newer Windows versions or other platforms. I used to be very involved with it. I'm leaving this page in here for reference, but AVISynth is no-longer current software.

I love AVISynth. I've made a plugin for it, and written about using it for some advanced processing, but what is it?

Some of the official docs aren't bad (try here, here, and here for an introduction), but I find myself explaining the same things to people fairly often, in terms of getting started, and in terms of some of the basic features, so I'll put them here on my own site.

Is AVISynth The Best Tool To Use?

I'd better explain early: AVISynth isn't always the best, but it is the most flexible, technical tool.

  • If you only want to trim the ends of a video or add two videos together, AVISynth can do that but there are simpler programs out there.

  • If you want to add special effects, you can do a lot with AVISynth but there are definitely more advanced tools and more creative tools. AVISynth is a toolkit, not a paintbrush.

What Do I Need To Get Started?

You need:

  • AVISynth

  • At least one of:

    • AVSP for working on your scripts. It's an editor for AVISynth with syntax highlighting and a preview window, and the website has some previews and tutorials which can help you get started

    • VirtualDubMod for saving the fruits of your labours to file, also has a script editor.

I strongly recommend:

  • Both AVSP and VirtualDubMod, as above.

  • ffdshow (current version is Beta 7), to get around all future codec issues. Once you have ffdshow installed, you are unlikely to have any troubles opening almost any file in any media player, or in AVISynth. There are some issues in Windows 7 though, see here.

  • The XVid codec because it comes with a YV12 codec which solves some issues that you might hit with VirtualDubMod and potentially other toolls.

How Do I Use AVISynth?

YOU DON'T! Not directly. There is no user-interface, it's not a "program" that you start.

AVISynth is more like a codec, for files of type "text". Once AVISynth is installed on your machine, any text file ending in ".avs" will be treated as if it was a video file by a media player. I recommend AVSP for editing your scripts, and VirtualDubMod for saving the videos, links as above.

Starting Examples

Let's say that you have an AVI file that you want to edit. Make a text file, write AVISource("myfile.avi") in it, then open that file in AVSP or VirtualDubMod or VirtualDub or MediaPlayerClassic...(anything which opens video files, since that's what you now have) and you're done! You are now using AVISynth!

So what next?

I'll get to that in a moment, let's recap with a screenshot of what this would look like in AVSP:

So What Next?

Well, you can use Trim() to cut the video down to just the bits that you want, you can use Crop() to cut down the frame size, there are various resizers (note: for best quality, use BilinearResize() when making videos bigger, Lanczos4Resize() when making them smaller. These introduce the fewest artefacts), you can use Subtitle() to add text. To put a more concrete example on it, here, let's do some of everything:

That is, keeping frames 810 to 980, cropping 300 pixels off the left and right and 200 off the top, shrinking what's left down to 320x240, and adding some text.

Combining multiple files

For assembling a video though, one of the most useful things to do is combine multiple videos. To put two videos back to back, just assign them to variables, and use a "+". Like this:

The first 70 frames of the above are the first video, the last 500 are from the second video.

If you don't want the videos back to back, you can put them next to each other (notice that I'm using variables a lot in this example, making one set of changes at a time. This is just for readability):

Other Things that AVISynth Can Do

AVISynth installs with very good documentation. A differently-sorted list of the same functionality is here, there is a shared wiki page of example custom functions here, and there are a great many plugins for AVISynth available to do even more! Lists here, and here.

If you want to apply the same processing to different videos, you can put it in a function and import it or copy/paste it into many scripts.

There's so much more! A list of some of the other possibilities to get you thinking (see the documentation for more and for how to use these functions):

  • You're not just limited to AVI inputs. You can open any video format with DirectShowSource(), and import images with ImageSource().

  • You can also import different types of audio, extracted from video or with WAVSource(), using AudioDub() and MixAudio() to replace and mix audio tracks.

  • FadeIO() to fade to/from black silence, Dissolve() to cross-fade

  • BlankClip() for empty sections that you can add text or other effects to (eg: for titles or end credits)

  • Just so you know that they exist: Greyscale(), GeneralConvolution() to add your own filters, Invert() to reverse colours, AddBorders(), PointResize() to get that blocky square-pixel effect, Loop() to freeze a frame, Reverse() to do something backwards, Blur().

  • Merge(), Overlay() for blending, Subtract() and Overlay(mode="Subtract") for differences. There are several functions designed for dealing with the an alpha channel, including ColorKeyMask() to do Chroma-keying / Blue-Screening

  • ColorYUV() and Tweak() for photo-like contrast and brightness messing-around

  • There isn't an "if" statement or a loop, but there is a conditional statement, and you can loop effects using recursive functions.

  • There's Animate() to let you change the parameters of any other function over time, examples: Fading to greyscale, overlaying text at different locations to make it scroll, or inventing your own video transitions.

  • There are heaps of interlacing support functions including general Interleave() and SelectEvery() (the general version of SelectEven() and SelectOdd())

  • For really tricky stuff, use ConditionalFilter(), ConditionalReader() etc. If you get into this territory for artistic effects, you should probably be using a more professional tool. If you get here for some scientific visualisation reasons or to do something really specific, good luck! Double-check your video reading functions though because DirectShowSource() isn't always frame-accurate so you can run into grief trying to get it to work correctly!

Because AVISynth is a scripting language, you can combine any and all of the above. Because there's a huge community of plugin developers, you can always do more!

Saving Your Video

Of course, having the script is not enough, you want to share your video with others, upload to YouTube, etc. If your script gets complex enough, it won't play in real time either so you'll want to save the output even if you don't want to share it. How do you do that?

The best tool when dealing with AVI Files is VirtualDubMod (it's not the best tool generally, just for AVI Files) and for AVISynth scripts, it's easiest to make an AVI File.

Open your script in VirtualDubMod, and then choose "save"...

There, you'll be given a choice of what to do. You want to process the video, but without any compression your video will be **huge** - so big that it will be a problem, besides AVI files have issues above 2GB. You don't want to deal with that, you want to change the codec:

Generally speaking, if you don't know what you want, or usually even if you do, use XVid (which you installed from the link at the top of this page, right?).

The first time you use it, you'll also want to configure it:

Try the following:

  • Set a profile level if you are playing the video on hardware, otherwise leave it at "unrestricted"

  • "Single Pass"

  • Use "Target Quantiser" instead of bitrate unless you know what you are doing

    • Try a quality around 2.0. That's pretty high quality. If you'd like a smaller file, use bigger numbers, you'll generally notice the quality start to drop around 3.5.

Done! Press "Okay" and "Save" until you get the message that your video is being saved to an AVI file, and when it's done, you have that video.

Important Note - Audio

This whole process only compresses the video. If you have audio and you want to compress that too. I won't cover that here, but the way to deal with it in VirtualDubMod is:

  • Save a WAV of the audio

    • Compress the audio, (I strongly recommend to MP3) with your choice of audio tool

  • Then Disable the uncompressed audio stream, and

    • Add in the MP3. If you get a popup message about rewriting the header, the answer is no.

If you do this before the saving steps above, you'll get a file with compressed audio, but you can also do it later by opening the saved AVI file, performing the steps above to extract and compress the audio, and then saving with the "Video Mode" from the first screen set to "Direct Stream Copy" instead of "Full Processing Mode".