Advanced AVISynth Commands and IVTC
Advanced AVISynth Commands:
Now that we dealt with the simpler aspects of just loading our video, we will now see how to IVTC and further
process our video.
MJPEG Luma Range:
Luma (brightness) in MJPEG decoders is often decoded incorrectly to the YUV luma-range, a special plugin was
written specifically to fix this issue with MJPEG videos. I have not verified if this problem exists with
all MJPEG Video Codecs, but the two most popular codecs (PicVideo & Morgan) both suffer from this issue (only
when decoding to YUV, decoding to RGB in programs such as VirtualDub doesn't require this fix).
Here's a simple script that fixes this issue:
You can obtain the MJPEGCorrect plugin either
here or here.
IVTC (Inverse Telecine) and Field Matching:
As many of you that have experimented in IVTC in the past know, IVTCing a video is often a slow and problematic issue.
Especially when your source is erratic and possibly even noisy (such as Anime or TV Capture).
Up until late 2001, the only way to properly IVTC video was using TMPEG Encoder or AVIFile. Both these systems
were not perfect. They had issues with certain hardware and often broke down, not to mention the IVTC processing speed
left much to be desired.
Then Tom Barry, one of the authors involved in the dScaler project took it upon himself to convert his dScaler field matching plugin
to the AVISynth platform. The filter is GreedyHMA. The benefits of this filter is that it was CPU Optimized and was
A few months later, Donald A. Graft,
the Author of Telecide (A field matching filter for VirtualDub) converted his filter to the AVISynth platform and
modified the code to allow for dropping of duplicated frames (part of the IVTC process) and further optimized it
so that it too was quite a bit faster than the older VirtualDub version. His filter is called "Decomb".
Both these filters work well, but Decomb is currently more evolved and as such will be the plugin I will discuss in
this article. At this time, the latest version of Decomb is v3.6 and as such some of the parameters may change in
a future version. The latest version of Decomb can be found
here and possibly on
doom9.org as well.
The Decomb plugin is built from two sections:
Telecide accepts the following parameters:
- Telecide, which matches fields in order to reconstruct the original progressive image and filters out fields
that can't be matched).
- Decimate, which matches duplicate frames after the Telecide process and removes one of
these frames to restore the original 23.976 frame rate.
Telecide (Reverse Field Matching, Swap Fields, Blend First/Last Frames, DeInterlace Non-Matching Frames, Field Detection Threshold, Field DeInterlace Threshold, Blend instead of Interpolate, Use Chroma Search, Exclude Line Start, Exclude Line End)
Recommended Setting (these are also the defaults if no value is set):
Telecide (reverse=false, swap=false, firstlast=false, post=true, threshold=15, dthreshold=9, blend=true, chroma=false, y0=0, y1=0)
Some of these parameters may not be clear so I will explain them in detail:
Note that the field matching Aspect and adaptive deinterlace function makes Telecide perfect for Phase Shifted
or Field Blended PAL sources as well.
- Reverse: Reverse Field Matching (true/false, Default "False").
Some badly authored DVD content or sources captured using a Capture card may have
the prominent field reversed which may cause interlaced output even though the
video was originally progressive. This setting reverses the matching order and
may resolve these issues.
- Swap: Swap Fields (true/false, Default "False").
Swapping Fields is the process where every second line is swapped with the line above it. Some capture cards
capture the fields in the wrong order and using this setting you can fix the issue.
- FirstLast: Blend First/Last Frames (true/false, Default "False").
In a lot of cases, the first and last frames of a video will have a missing field, which would prevent field
matching. If you want to ensure that these frames are blended, enable this parameter. However, in most cases
due to editing the first/last frames of a video is usually black and won't require this setting.
- Post: DeInterlace Non-Matching Frames (true/false, Default "True").
In certain conditions it may be impossible to reconstruct a progressive frame (scene changes, bad editing on
the original source material). When this setting is enabled, it will compensate for this by either Blending
the fields to smooth the artifacts or by Interpolating the fields to estimate motion (according to the "blend
instead of interpolate" setting). Before enabling this setting, it's usually wise to load the clip with it
disabled so you can see if your field order is correct. Otherwise, you would get a blurry video. Once you
inspected that most of the frames match properly, re-enable this setting to make sure no interlaced frames
- Threshold: Field Detection Threshold (0-255, default "15").
This is the value that determines which area is considered interlaced and which is considered progressive. The
lower the value, the more the image is considered interlaced.
- dThreshold: Field DeInterlace Threshold (0-255, default "9").
When combing is detected after the field matching process, this setting determines the detection sensitivity of
the remaining interlacing that will later be blended or interpolated.
- Blend: Blend instead of Interpolate (true/false, default "True").
Blending gives a smoother image with better motion but with slight ghosting, an interpolated image may have a
sharper image but motion may be jumpy and the image may have additional noise. On a whole, Blending provides
a better image quality but is slightly slower (only when non-progressive frames are found).
- Chroma: Use Chroma Search (true/false, Default "false").
By default only the Luma (brightness) of an image is used to check for interlaced data. However, in certain types
of content (mostly in animation) it may also be wise to look at the Chroma (Color). Unless you're using Animated
content, I recommend leaving this disabled.
- Y0: Exclude Line Start (0-4095, Default "0").
In some cases where you may have an on-screen logo, or perhaps subtitles, this overlayed data (that isn't part
of the original show) may confuse the field matching code. In order to exclude this area of the screen from
being checked for matching fields, you use the Y0 and Y1 parameters. The Y0 parameter defines which starting
line should be excluded.
- Y1: Exclude Line End (0-4095, Default "0").
The Y1 Parameter defines which ending line should be excluded. Any lines in between Y0 and Y1 are ignored.
If Y0 and Y1 have the same value, the excluding setting is disabled. Since by default their values are both
"0", the entire image is checked for field matches.
Decimate accepts the following parameters:
Decimate (Cycle in [n] Frames, Decimate Mode, Hybrid Threshold)
Recommended Setting (these are also the defaults if no value is set):
Decimate (cycle=5, mode=0, threshold=0)
- Cycle: Cycle 1 in [n] Frames (2-25).
Basically you tell Decimate to remove one frame every [n] number of frames. For use with IVTC you would like
to remove 1 duplicate frame from every 5 frame sequence, so the value would be "5".
- Mode: Decimate Mode (0-1).
In mode "0", 1 every [n] frames will be removed from the video. In mode "1", instead of removing the frame,
the duplicate frame is blended with the previous frame and thus motion becomes smoother while remaining at the
same frame rate. This is useful if your source video is a hybrid of 24fps and 30fps content and you don't want
to make the 30fps content jerky by discarding one of it's frames. This is the case in quite a few series that
incorporate live-action with computer generated images (such as Andromeda and Babylon 5).
- Threshold: Hybrid Threshold (0-99).
When using mode "1" to blend duplicate frames on hybrid 24fps/30fps content, you don't want blended frames on
the 30fps content. To prevent that from happening, you define a threshold which determines the difference
between frames for decomb to deduct which frames should be blended. A value of 25-50 should be ok for DVD content.
You may want to experiment to see what works best for you.
The idea behind Cropping is, you set how many pixels to cut on the left and top sides, and then you set the
new width and height so that the bottom and right sides will also get cropped.