Removing blended film frames on vcds

From Avisynth wiki
Jump to: navigation, search

For anyone who owns films on NTSC VCD's and has done a frame by frame playback, it can be easily seen that two consecutive frames out of every five frames are blended with adjacent frames. This is done to match the speed of film to NTSC video. Film plays at 24 frames per second, while video plays at 30 frames per second. To match the speeds, one new film frame must be added to every four existing frames. The process is similar, although simpler, than telecine, so if you want to understand how the blending procedure is undertaken, search for 'telecine'. The difference is instead of interlaced frames, you have blended frames. If you want to recover the original frames, problems arise, because one doesn't exist.

Here is an example: the VCD film frames will be listed as numbers, and the corresponding 'film' frames will be listed as letters. Where letters are doubled up, that means the frame is complete.

VCD Frames     1    2    3    4    5
Film Frames    aa   bb   bc   cd   dd

Frames a, b and d are kept in their entirety. But frame c is not. It is blended into 2 different frames, but there is no independent copy. So it must be recovered digitally.

This is how it's done. Frame 3 consists of an even blend of frames b and c. Since we have a complete version of frame b, we can 'subtract' that image from the blended frame, leaving behind frame c. Frame b has to be reduced to 50% effectiveness in the subtraction, because only 50% of frame 3 is frame b, the other 50% is frame c. Likewise, frame 4, consisting of frames c and d, can subtract frame d (which is complete in frame 5) to leave behind a second version of frame c.

This redundancy is not entirely necessary, however it is recommended because video compression noise affects the restored frames' appearance. By combining the two restorations, the majority of video noise is hidden.

So here is the code:

Function DeBlend (clip Last) {
    First = SelectEvery (5, 0)
    Second = SelectEvery (5, 1)     # Frames a, b and d get passed through untouched.
    Fourth = SelectEvery (5, 4)
    Third1 = Subtract (SelectEvery (5, 2), 
      \ Second.Levels (0, 1, 255, 128, 255)).Levels (0, 1, 127, 0, 255)
    Third2 = Subtract (SelectEvery (5, 3), 
      \ Fourth.Levels (0, 1, 255, 128, 255)).Levels (0, 1, 127, 0, 255)

# Recovering frame c from the blends by subtraction. Note that the first Levels' 
# halfs the range of frames b and d.
# The second Levels' boosts each restoration of frame c from 50% value to 100%.

    # Blend the two versions of frame c together to get the most accurate restoration
    Third = Overlay (Third1, Third2, mode = "blend", opacity = 0.5)    
    # Re-integrate the restored frame into the other frames.
    Interleave (First, Second, Third, Fourth)   
}

This code is effective, but not perfect. It does not perform noise reduction - other than the simplistic and not very effective blending of the different versions of the frames - nor can it detect which frames are blended. It assumes the 3rd and 4th frames out of every 5 are blended, but many poorly mastered VCDs break this pattern, in which case, this function is useless.

For broken cadences, use one of the frameblending removal filters that is specifically designed for this type of film -> NTSC -> blend recovery (i.e. ExBlend, Srestore with a string for omode).

Personal tools