AVSEdit Tutorial
AVSEdit Tutorial
AVSEdit is the official script editor for AviSynth. It provides an easy interface to write and preview scripts, making AviSynth more accessible to beginners and advanced users alike. If you've always wanted to use AviSynth, but have been intimidated by the lack of a GUI, or if you just want to make scripting a little easier, you should give AVSEdit a try. This guide was written by vurbal.
Installation
Start by installing AviSynth. If you decide to change the install location from the default (C:\Program Files\AviSynth 2.5) make a note of where it is. You'll need this information later to install plugins. Next install AVSEdit. The installer will check to see if your system has Microsoft's .NET 1.1 Framework installed. If it's not already installed you'll see a dialog prompting you to download and install it.
Plugins
Many people have written plugins that extend the functionality of AviSynth. Before you can use a plugin you need to download it to your computer and copy 1 or more files to the AviSynth plugins directory. If you installed AviSynth to the default location, that will be C:\Program Files\AviSynth\plugins. In the AviSynth program group on the Start menu there's a Download Plugins link that will open a web page with links to many of them, including the ones used in this guide. Each download is a zip archive which normally
includes a DLL file and either text or html files with instructions. Some plugins also come with source code or example scripts. The DLL files need to be copied to the AviSynth plugins directory so AviSynth can autoload them. Note: The download page has 2 columns for download links. The column to the left is for AviSynth 2.0 plugins and the one on the right is for AviSynth 2.5. Make sure you get the v2.5 plugins.
You'll want to arrange the Filters tab to make it easier to find what you're looking for. When you run the program the first time the filters are arranged in alphabetical order.
That's fine if you know the name for the filter you want, but not so good for a beginner trying to figure out which filter does what to use. Right click anywhere on the tab and you'll see a popup giving you options for how filters are organized. Select View by Category. The tab changes to a list of categories, each with a + next to it. Clicking + will expand the list of filters in a category. Clicking a second time hides the list. Setting the Filters tab to View by Plugin will group filters by plugin so you can tell which plugin is required for a particular filter before you select it. Filters from plugins are also displayed in all views with a lighter blue circle next to them than the one used for Core filters.
Previewing
The Preview Window allows you to test the output from your script. On the Extras menu click Preview. The output from the Version filter is information about the AviSynth version you're using. Pressing on your keyboard will play the script's output and pressing
a second time stops it. In this case you won't be able to tell it's playing because Version creates 240 duplicate frames so there's no motion. The Preview Window is also useful for troubleshooting scripts because AviSynth displays error messages the same way it displayed your Version script (a 240 frame video stream).
DVD2AVI project files (also known as D2V files), can be opened with AviSynth using a plugin called MPEG2Dec3. Follow the shortcut on the Start Menu in the AviSynth program group that says Download Plugins to open the web page, and scroll down the page to find the plugin. There are 2 different versions of it. Make sure to get the one that says Recommended Version in the description (decodefix100.zip). When you open the zip archive you'll see the MPEG2Dec3 plugin (MPEG2Dec3dg.dll) which you need to copy to the AviSynth plugins directory. Make sure you use the version of DVD2AVI (DVD2AVIdg) that's included in the archive to create the D2V projects. Once you have the DLL file copied to the plugins directory you're ready to open your project file. Expand the Source category and add the MPEG2Source filter. There are 2 filters listed with that name because there is more than 1 plugin that uses the same filter name, but they're not interchangeable. Add either one to your script and then highlight the line in the editor to find out what plugin it belongs to. The dropdown above the parameters should say MPEG2Dec3::MPEG2Source. If it lists a different plugin you need to click the arrow for the dropdown and select the correct one. The only parameter you need to set is the filename. Adding audio from a separate file
AviSynth can combine video and audio from separate files. If the audio file is in Wave format, the WavSource Core filter can be used to load the audio file. MPA files can also be loaded using the MPASource plugin. Start by adding the filters to load the video and audio files. Now you need to edit the script directly to add Video= to the beginning of the line that loads the video source and Audio= to the beginning of the line that loads the audio. This creates variables for AudioDub to use. After you have those lines edited you can add the AudioDub filter from the Processing category. Clicking the arrow button next to the video_clip and audio_clip parameters will show you a list of available variables. Select Video for video_clip and Audio for audio_clip.
Editing
AviSynth can edit out unwanted frames, allowing you to do simple editing like removing credits from a movie or more complex editing like removing commercials from TV captures. If you know what frames you want to keep, you can add the Trim filter from the Editing category and directly enter the beginning and end frame on the Parameters tab. You can also use the Preview window to interactively edit a clip. When you have the Preview window open you'll see a trackbar at the bottom with a yellow line indicating the location of the current frame. You can use the left and right arrow keys or the scroll wheel on your mouse to navigate to the first frame you want to keep. Pressing on your keyboard will set that frame as the first_frame for the Trim filter and the trackbar indicator will turn red. Move to the last frame you want to include in the Trim and press on your keyboard to set that frame as the last_frame. Now the trackbar has a blue line indicating the selection you just made. Repeat this process until all your edits have been made and then close the Preview window. AVSEdit will insert the Trim filter with the correct frame numbers entered for you. Note: If you have multiple trim points and the audio goes out of sync after the first section, try editing the Trim line, changing each + to ++
Colorspace conversion
AviSynth 2.5 works in YV12 colorspace by default, but most of the applications that open scripts will require the input to be YUY2. You can convert to
the correct colorspace by using the ConvertToYUY2 filter from the Processing category. Make sure to set the interlaced parameter to true if your video is interlaced.
Resizing filters (from the Resize category) change the resolution of the video. When using a Core filter that resizes by a variable amount (like BilinearResize, BicubicResize, or LanczosResize) the Parameters tab has an additional button at the bottom which opens the Resize Editor. In the Resize Editor you can select the width and height you want and see what the Mod number is. The total number of pixels and aspect ratio for the selected resolution are also displayed at the bottom. Note: If your final format is a standard format for TV display (ie DVD, SVCD, VCD, etc,...) the aspect ratio can be a misleading number. For example, 704x480 and 352x480 will display different aspect ratios, but when you play them in your DVD player the aspect ratios will be the same. For viewing on your TV make sure to use the correct resolution for the format you're encoding to.
} #Stop Copying Here Select Save As from the File menu and browse to the AviSynth plugins folder. Name the file 'Interlaced Functions.avsi (make sure you enter the .avsi extension). Close AVSEdit and then open it again and go to the Filters Tab. You have a new category called User. Expand that category and you'll see the 3 functions in the file you just saved - FoldFieldsVertical, SetParity, and UnfoldFieldsVertical. Now you can add these functions by double clicking them. When you have interlaced material that you want to denoise or resize, start by adding the UnfoldFieldsVertical function. If you highlight it in the editor, you'll see parameters listed. Ignore these parameters as they won't give you the correct syntax for the function. Instead, manually edit the line in the editor to read UnfoldFieldsVertical(true). When you are done filtering you need to weave the fields together again using FoldFieldsVertical(true). Note: Some filters, like Crop and AddBorders, should be used while the video is still interlaced.
Using profiles
There are times when you want to try using different filters or even the same filter with
different settings to find out which settings you prefer. By saving different versions as profiles, AVSEdit allows you to quickly switch between them without rewriting each time. To create a profile, go to the Profiles tab, enter a name in the field at the top, and click the save button. To load a profile, select the profile name from the list and click Load. If you want to compare scripts side by side you should use an external program for previewing (I use VirtualDubMod). Before you can do that you need to select Options from the Extras menu, click the External Preview button, and browse to the program you want to preview with. To compare different scripts, select External Preview from the Extras menu to view the output from the first script. Leave the external preview open, go back to AVSEdit, switch to another profile, and do another External Preview. Now you have both scripts open in different windows. Note: I use profiles for editing TV captures. I have one profile with sound and one without. I do an External Preview in VirtualDubMod to save the audio stream as a WAV file (edited to match my video) and then use the profile with no sound to encode the video.
nverse Telecine
If your video is 29.97fps and was originally shot on film, it's probably been telecined. Telecine is a process that changes 23.976fps (frames per second) progressive video to 29.97 frames per second interlaced (59.94 fields per second). Normally that means you can perform an IVTC (Inverse Telecine) operation on it to recover the original progressive frames. Not only will this give you back the original progressive content, it will also reduce the filesize by discarding 1 out of every 5 frames. Note: Since the IVTC process creates 23.976fps, depending on your final format, you may need to add pulldown information after encoding. There are some free utilities available for this, and some DVD authoring software will do it for you when you load 23.976fps video that hasn't already had pulldown flags added.
Note: If your source is a D2V file and you used Force Film when you created the project, you've already performed IVTC on it. If you want to use AviSynth to IVTC you should create a new DVD2AVI project with Field Operation set to None.
Telecide
The first step is to recreate the original progressive frames. Before you can do that, you need to determine whether your video is TFF (Top Field First) or BFF (Bottom Field First). This can be done using Core filters from the Interlaced category. Add AssumeTFF and SeparateFields to your script and preview it. Navigate through the preview until you find a section where something moves either left to right or right to left across the screen and step through several frames, one frame at a time. If the object moves backwards in every other frame, the field order is BFF. If the movement looks correct it's TFF.
Delete the AssumeTFF and SeparateFields lines and add the Telecide filter from the Interlaced category. Set the order parameter to 0 if your video is BFF or 1 if it's TFF. You must set the order because there is no default value. Preview your video again, find a section with motion, and step through it one frame at a time. You should see a repeating pattern of 3 unique frames followed by 2 identical frames. If you don't see this pattern, or you only see it some of the time, refer to the Decomb tutorial instead of this guide.
Decimate
Now that you've recovered the original film frames, you can use the Decimate filter from the Interlaced category to get rid of the duplicate frames. You don't need to set any parameters, as Decimate drops 1 in 5 frames by default. Make sure you preview your
video to see if there are any problems. Once again, if you end up with video that doesn't look right, refer to the Decomb tutorial for more help.
Deinterlacing
If you have an interlaced source, but want progressive output, and your source isn't telecined, you need to deinterlace. This section will describe 2 different ways to deinterlace, but there are many different ways to do it. Depending on the source material, the destination format, your viewing equipment, and your personal preferences you'll get better results from one or the other, or you may prefer a different approach altogether.
Discarding Fields
One option is to simply remove every other field. This will leave you with frames that are half the height of the original video, so you'll need to resize after discarding fields. This can be a useful approach if your final format will be half the height of your source like converting a 720x480 video into VCD (or a VCD resolution DVD), because AviSynth doesn't have to add information that's not in the original source. On the other hand, you may lose important details that were only in the fields you removed. Add the SeparateFields filter from the interlaced category and then either SelectEven or SelectOdd from the Editing category.
Bobbing
This will usually give you the best quality for deinterlaced video. Like the previous method, bobbing starts by separating fields, but then each field is changed to a full-size frame by filling in either the even or odd lines, depending on whether it was originally a top or bottom field. You can also use this method to create double framerate or slow motion video. Make sure you have the DGBob plugin for this operation. You'll also need to know the field order of your video. This can be done using Core filters from the Interlaced category. Add AssumeTFF and SeparateFields to your script and preview it. Navigate through the preview until you find a section where something moves either left to right or right to left across the screen and step through several frames, one frame at a time. If the object moves backwards in every other frame, the field order is BFF. If the movement looks correct it's TFF.
Add the DGBob filter from the ??? category. There are 2 parameters you need to set order and mode. Set the order parameter to 0 if your video is BFF or 1 if it's TFF. You must set the order because there is no default value. If you want video with a doubled framerate (59.94 fields per second becomes 59.94 frames per second) you don't need to change the mode. If you want to maintain a standard video framerate (59.94 fields per second becomes 29.97 frames per second by dropping every other frame) set the mode parameter to 0. If you want slow motion video (59.94 fields per second becomes 29.97 frames per second but no frames are dropped) set the mode to 2.
Getting help
Clicking Content on the Help menu or clicking the help icon on the toolbar will open the AviSynth Manual. It's a good idea to read as much of the manual as possible to understand how AviSynth works. There are sections about general AviSynth useage, Core Filters, and External Filters that give basic instructions for scripting. You can look at the AviSynth Editor section for AVSEdit specific help, and it's also a good idea to read through the FAQ for help loading your script in another application like an encoder. If you are looking for help with a specific filter, highlight the filter in your script and click the Help button at the bottom of the Parameters tab. That will open the help file for the selected filter.