AfterDawn.com

Using AviSynth

While AviSynth is widely respected as a professional level video tool available at no charge, many people shy away from it because it requires you to write a script. However, with very little instruction and a good front end like AVSEdit or AvsP you should be able to write the simple scripts generally used for IVTC. Although the basics of AviSynth aren't covered here, there will be links to relevant guide pages to find information on specific filters or operations. Before you start repairing the video though, you'll want to examine it more thoroughly than you can with DGIndex. If you're not familiar with AviSynth's basic interlaced video filters you can find information on them in our AviSynth Filter Reference. Specifically you'll need to be able set field order to ensure proper frame reconstruction.

Field Order

Before you start worrying about IVTC you need to make sure the field order is correct. Although most of the time an MPEG-2 source will have the correct order by default, it only takes a few moments to preview your script with only the source statement in it. You should already have a D2V project created by DGIndex. Use the Mpeg2Source filter from the DGDecode plugin (DGDecode.dll) to open the D2V file and set info equal to 1 to see some information DGIndex saved about the MPEG-2 source:
Mpeg2Source("D:\Video\IVTC\Example.d2v", info=1)

Preview your script and you'll see text over your video that passes on information gathered by DGIndex. One Among the information should be a framerate of 29.970030fps and a field order of either Bottom Field First or Top Field First. Use this value to determine the next filter in your script, either AssumeTFF() or AssumeBFF(). Make sure to preview your script again and verify that motion areas aren't jerky. If the field order appears to be wrong, which is indicated by jerky motion in some areas, change the field order in your script. If your working from a DGIndex project and you trust the field order it reports you can simply rely on this instead.

TIVTC

With the correct field order set it's time to start thinking about what filters we'll be using to perform our IVTC. More than one IVTC filter (or set of filters) has been written. Currently a plugin called TIVTC is generally considered the best, although there is no perfect solution. You can find a description of the TFM and TDecimate filters we'll be using here in our AviSynth Filter Reference. Make sure you either copy TIVTC.dll to your AviSynth plugins directory (C:\Program Files\AviSynth 2.5\plugins) or use the LoadPlugin filter to load the TIVTC filter package:
LoadPlugin("D:\AviSynth Plugins\TIVTC.dll")


Field Matching

Now that we have the filters we need it's time to start looking at the IVTC steps outlined previously. The first is field matching. Before AviSynth can put the original frames back together it needs to determine what fields "look" the most like they make up a single frame. Since interlaced encoding will tend to produce differences between fields, even if they start out as a single frame, this isn't always as simple as it sounds. It can also be complicated by improperly processed video that sometimes has unusual or irregular pulldown, resulting in unpredictable duplicate fields.

We'll be using the TFM filter to field match. For most sources you shouldn't need to use any extra options for it to produce very good matches. However, if you're starting with a D2V project it's best to use it:

Mpeg2Source("D:\VideoFolder\Source.d2v")
TFM(d2v = "D:\VideoFolder\Source.d2v")


Cleaning Up Artifacts

If your results don't look good, particularly if there are a lot of combed frames left, you should take out the TFM statement to visually verify the telecine pattern to be removed. Then you can add it back using a PP of 1. This will show you what the frames look like with no post processing. If this looks the same as with PP set to a higher number (2 - 7) you may need to change the value of "cthresh" to something lower than the default 9. Normal range is generally considered to be 9 - 12, although for some clips you may need a lower value.

Decimation

With each framed now paired with its best match we can decimate to remove extras. The extra frames will be duplicates of others, which you can verify by previewing the script before adding the TDecimate filter. You'll see that there are 3 unique frames followed by 1 that appears twice. You should use TDecimate slightly differently for live action or animated sources because there are fundamental differences in the frames found in each. Standard decimation for live action sources can normally done with no arguments:
Mpeg2Source("D:\VideoFolder\TelecinedVideo.d2v")
TFM(d2v="D:\VideoFolder\TelecinedVideo.d2v")
TDecimate()

You could also put TFM and TDecimate to a single line:

Mpeg2Source("D:\VideoFolder\TelecinedVideo.d2v")
TFM(d2v="D:\VideoFolder\TelecinedVideo.d2v")
TDecimate(mode = 1)

Typically animation has at least short areas where entire frames are duplicated in the original film source. In order to ensure AvySynth takes this into account you should use Mode 1 in TDecimate:

Mpeg2Source("D:\VideoFolder\TelecinedVideo.d2v")
TFM(d2v="D:\VideoFolder\TelecinedVideo.d2v").TDecimate()



Using Your Script

So now that you can create a script to IVTC, what's it good for? In most cases you can use it as input for a video encoder or even media player. It should play as though it were an AVI file. The only major stumbling block to playing a script directly is that it may not be able to deliver frames in real time. Depending on the exact filter chain in your script it may only be suitable for encoding or editing in another program. If the program you require IVTCed video for doesn't accept AVS files you will either have to use a lossless encoder to create a real AVI file, or use a tool like MakeAVIS to create yet another fake AVI - one that can fool programs that don't use Windows' built in code to read AVI files.


Version History

v1.0 2007.11.30 First publication by Rich "vurbal" Fiscus
v1.1 2007.12.02 Formatting edits by Rich "vurbal" Fiscus
v1.2 2007.12.03 TIVTC reference moved to AviSynth Filter Reference by Rich "vurbal" Fiscus

Table of Contents

  1. 1. Introduction
  2. 2. Frame Types
  3. 3. IVTC
  4. 4. Identifying Telecined Film
  5. 5. Analysis With DGIndex
  6. 6. IVTC With AviSynth
Written by: Rich Fiscus