This page is documenting a work in progress feature do not assume it is available on the mainline branch.


interlacing is the 80's way of motion compensation

Interlacing is a technological cruft left from ancient video systems. Besides compatibility, the reason that it is kept alive these days is that there is a lot of FUD around it: for example some say that it provides higher resolution (false, studies proved that a 720p50 is better than 1080i25) or that not using it would require doubling the bitrate (false, people who say this don't know how video encoding works).

In any case interlacing is painful to deal with, so our software should try to handle that in the most painless and elegant way, at least at high level.

Codec Level

Current state

AVFrame always contain full frames and has no concept of fields. Decoders and encoders always set a flag to know whether they are handling progressive or interlaced material, and if so, which one of two fields is the first (top or bottom).

This information is stored in AVFrame using two integer values, interlaced_frame and top_field_first. This poses several limitations as it assumes that a frame can only be either progressive or interlaced, and leaves the latter flag in an inconsistent state until the application makes sure that the former is true.

New state

A new enumeration is proposed to keep track of the current state, to fix a few corner cases of the current implementation and allows for future expansion. In order to preserve backward compatibility for application two new functions are provided so that deprecated fields will be kept in sync with the enumeration.

The proposed enum follows: the main values (interlaced/progressive) are bitmask compatible with the other member (of the same group) so it is possible to check them directly with a comparison or with a bitmask operation as well.

enum AVFieldState {
    AV_FRAME_UNKNOWN         = 0x02,  //< unknown frame field information
    AV_FRAME_INTERLACED      = 0x01,  //< interlaced frame, unknown field mode
    AV_FRAME_INTERLACED_TFF  = 0x03,  //< interlaced frame, top field first
    AV_FRAME_INTERLACED_BFF  = 0x05,  //< interlaced frame, bottom field field
    AV_FRAME_PROGRESSIVE     = 0x04,  //< progressive frame
    AV_FRAME_PROGRESSIVE_PSF = 0x0C,  //< progressive frame carried in interlaced fields

The new functions will internally convert values from AVFieldState to the old interlaced_frame and top_field_first.

enum AVFieldState ff_avframe_get_field_state(AVFrame *frame);

void ff_avframe_set_field_state(AVFrame *frame, enum AVFieldState state);

Container Level


Interlaced encoding

Please consider encoding videos progressively and do not perpetuate this historical artifact any longer.

If you cannot do anything to avoid interlacing, then you should be cautious. When encoding an interlaced material all will go smooth, but problem will arise if your content is progressive. This is because encoders are designed to blindly encode blocks of video and then apply interlacing (if requested): if video was not interlaced they will apply interlaced tools on a progressive frame and the result will be horrible at best.

So the solution is pretty simple you need to apply a filter on your video that will visually interlace the video and then tell the encoders to use the interlacing tools. This is done with this command:

# avconv -i INPUT -vf interlace -flags +ildct+ilme OUTPUT

CategoryBlueprint CategoryWIP CategoryBlueprintActive