Interlaced and Field-based video

Currently (v2.5x and older versions), AviSynth has no interlaced flag which can be used for interlaced video. There is a field-based flag, but contrary to what you might expect, this flag is not related to interlaced video. In fact, all video (progressive or interlaced) is frame-based, unless you use AviSynth filters to change that. There are two filter who turn frame-based video into field-based video: SeparateFields and AssumeFieldBased.

Color conversions and interlaced / field-based video

Let's assume you have interlaced video, you want to work in field-based mode (to apply some filtering for example) and you also need to do some color conversion. Do you need to do the conversion on the frame-based clip or can you do it on the field-based clip? Well, that depends on the color conversion you want to apply:

* YUY2<->RGB conversions can be done on either of them. (Note, that in this case, the setting interlaced=true/false doesn't do anything. It's simply ignored.)
* YV12<->YUY2/RGB conversions should be done on the frame-based clip (with the interlaced=true setting). Doing them on the field-based clip will yield incorrect results. The exact reason of this is outside the scope of this page, but it is a consequence of how the color format YV12 is defined. The main issue is that chroma is shared between pixels on two different lines in a frame. More information can be found here Sampling.

The more experienced users should consider the following. In general, interlaced video has parts where there is no or little movement. Thus, you won't hardly see any interlacing effects (also called combing) in these parts. They can be considered progressive, and when doing a YV12<->YUY2/RGB conversion on a progressive video you should use the interlaced=false setting to get better results. It is possible to the YV12<->YUY2/RGB conversion on frame basis while switching between interlaced=true and interlaced=false. Here's how to do it (you will need to have decomb installed in order to be able to use the function IsCombed)

function ConvertHybridToYUY2(clip a, int "threshold", bool "debug")
{
debug = default(debug, false)
global threshold = default(threshold, 20)

b = ConvertToYUY2(a, interlaced=false)
c = ConvertToYUY2(a, interlaced=true)
ConditionalFilter(a, b, c, "IsCombed(threshold)", "equals", "true", show=debug)
}

function ConvertHybridToRGB(clip a, int "threshold", bool "debug")
{
debug = default(debug, false)
global threshold = default(threshold, 20)

b = ConvertToYUY2(a, interlaced=false)
c = ConvertToYUY2(a, interlaced=true)
ConditionalFilter(a, b, c, "IsCombed(threshold)", "equals", "true", show=debug)
}

AviSource("D:\captures\interlaced-clip.avi") # interlaced YV12
#ConvertHybridToYUY2(debug=true)
ConvertHybridToYUY2()

However, the downside of this is that it may lead to [chroma shimmering] in the combed-progressive frame transitions. So, it's not a perfect solution.

Color conversions, interlaced / field-based video and the interlaced flag of dvd2avi

For the more experienced users. Dvd2avi keeps track of whether a frame is interlaced or progressive (by using the interlaced flag). In principle, dvd2avi can be modified to store this in a text-file and AviSynth can read and use it on frame-basis. However, it's useless. The problem is that sometimes progressive video is encoded as interlaced, and thus is detected as interlaced by dvd2avi. In the previous section, it is explained, that in that case you should use interlaced=false during the YV12<->YUY2/RGB conversion (since there's no movement) to get more accurate results. So, it's the presence of combing which is important for the YV12<->YUY2/RGB conversion, and not whether a frame is interlaced.

Changing the order of the fields of a clip

There is a filter which swaps the even/odd fields SwapFields, and a plugin which reverses the field dominance [ReverseFieldDominance]. The former changes the spatial order and the latter the temporal order.

Swapping fields:

before using SwapFields:

lineframe 0
0t0
1b1
2t2
3b3
4t4
5b5

field order (top field first then bottom field):

linefield 0field 1
0t0 
1 b1
2t2 
3 b3
4t4 
5 b5

after using SwapFields:

lineframe 0
0b1
1t0
2b3
3t2
4b5
5t4

field order (top field first then bottom field):

linefield 0field 1
0 b1
1t0 
2 b3
3t2 
4 b5
5t4 

Note that the even and odd lines are swapped, so you can call the Top Field as Bottom Field, and vice versa.

Reversing field dominance:

before reversing the field dominance:

lineframe 0
0t0
1b1
2t2
3b3
4t4
5b5

field order (top field first then bottom field):

linefield 0field 1
0t0 
1 b1
2t2 
3 b3
4t4 
5 b5

after reversing the field dominance (assuming the lines will be shifted up, and the last one will be duplicated):

lineframe 0
0b1
1t2
2b3
3t4
4b5
5b5

field order (bottom field first then top field):

linefield 0field 1
0b1 
1 t2
2b3 
3 t4
4b5 
5 b5

Note that the top and bottom fields are swapped, but the even and odd lines are not swapped.

The parity (= order) of the fields in AviSynth

If a clip is field-based AviSynth keeps track of the parity of each field (that is, whether it's the top or the bottom field of a frame). If the clip is frame-based it keeps track of the dominant field in each frame (that is, which field in the frame comes first when they're separated).

However, this information isn't necessarily correct, because field information usually isn't stored in video files and AviSynth's source filters just normally default to assuming bottom field first (with the exception of the MPEG2Source plugin which gets it right!).

About DV / DVD in relation to field dominance

The field dominance is not the same for every source. DV (with interlaced content) has bottom field first, while DVD (or CVD/SVCD) has top field first. Thus when convert between those two, you need to change the field dominance. This can be done in AviSynth (see above), but also in the encoder itself (for bff material like DV footage, you need to set the Upper field first flag). Some comments on other [methods].

References

[DV / DVD and field dominance]
About [field dominance].
[Doom thread] about swapped fields and field dominance.
[ReverseFieldDominance plugin]

$Date: 2006/12/15 19:29:25 $