Editing Interlaced Video

Colorspace conversions and rescaling operations are more difficult for interlaced video than progressive. This document describes how to edit interlaced video using Cinelerra.

The editing techniques described here are compatible with workflows that preserve quality by avoiding intermediate editing formats. Examples of these types of workflows are described in DV Video Workflow in Linux, HD Video Workflow in Linux and H264 HD Video Workflow in Linux.

If you are editing DV source using Cinelerra please check the page on Upsampling DV Chroma by Inpainting for improved resampling of the 4:1:1 colorspace.

Needed Software

Interlaced Chroma Errors

Cinelerra uses a 4:4:4 colorspace for editing; however, current versions of Cinelerra do not properly convert interlaced 4:2:0 source to 4:4:4. The upsampling of interlaced chroma fields is done using a progressive algorithm, even when the interlaced option is set in the video format section. Similarly, subsampling from 4:4:4 to 4:2:0 is always done using the progessive algorithm.

The following patches allow Cinelerra to perform colorspace conversions correctly:

It should be pointed out that the conversion Cinelerra uses to get from 4:2:0 to 4:4:4 followed by the conversion from 4:4:4 to 4:2:0 results in the original frame. Therefore the interlaced chroma error only effects projects that use video effects or start with a DV source and render it to mpeg2. In particular, the video quality of a project consisting of HDV source spliced together with transitions and rendered through a yuv4mpeg stream to x264 will not be affected.

Validation of the Patches

Consider an interlaced video created from the image itst.png given by

When interpreted as two fields of interlaced video this frame consists of a blue square moving to cover part of a red square. When this frame is replicated and placed in a video stream the visual effect is that the center rectangle flashes red and blue.

Encode this image to interlaced 4:1:1 DV using the commands

$ dd if=/dev/zero bs=4 count=960960 |
    sox -t raw -s -w -c2 -r48000 /dev/stdin test.wav
$ pngtopnm itst.png |
    ppmtoy4m -F 30000:1001 -A 8:9 -n 600 -r -Ip -S 444 |
    y4mscaler -O chromass=411 |
    ffmpeg -f yuv4mpegpipe -i /dev/stdin -i test.wav \
       -interlace 1 -top 0 -flags +ildct+ilme \
       -vcodec dvvideo -acodec pcm_s16le -y test.avi
and to interlaced 4:2:0 mpeg2 using the commands
$ toolame -b224 -s48 test.wav test.m2a
$ lav2yuv test.avi |
    yuvcorrect -T INTERLACED_BOTTOM_FIRST |
    mpeg2enc -M0 -nn -a2 -f8 -G18 -b7000 -V230 -q5 -o test.m2v
$ mplex -f8 test.m2v test.m2a -o test-mjt.mpg
Other methods for encoding DV to mpeg2 can be found in DVD compliant mpeg2 on Linux.

The video clips test.avi and test-mjt.mpg should look the same in Cinelerra if the chroma upsampling routines are working correctly. To check how close they are, load both into Cinelerra and subtract one from the other to obtain the error. The following screen grab shows both tracks on the Cinelerra timeline with one subtracted one from the other.

I performed this test on both patched and unpatched versions of Cinelerra. Where the video tracks are black the images match; where there is color the images differ.

The progressive upsampling algorithm in the unpatched version of Cinelerra doubles the width of the red and blue lines in the interlaced part of the frame. This results in obvious error. The patched version of Cinelerra does not have this error.

Note that getting the chroma fields correct is particularly important in obtaining quality chroma key results from HDV video.

Video Effects With Cinelerra

Video effects that don't depend on the spatial relationship of one pixel to another work fine with no modifications on interlaced video. These include brightness, contrast, color balance, chroma key, difference key, gamma, hue, saturation and YUV. For best results it is still important that the interlaced chroma patches mentioned above be installed.

The effects that need additional attention are blur, freeze frame, linear blur, radial blur, reverse video, scale, sharpen, title, translate, unsharp, wave and whirl. To use a one of these effects place frames to fields before it and fields to frames after it. Make sure to specify the field interlacing order in both fields to frames and frames to fields. Suppose you want to zoom in on part of a top field first interlaced video. This can be done with the translate and scale effects as shown by

Using the Compositor

For scale and translate you may prefer to use the compositor. The compositor needs progressive frames to work. Therefore, in order to use the compositor, double the frame rate and use frames to fields on every track. Reinterlace the video during rendering using the yuv4mpeg script
#!/bin/sh
yuvfps -s 30000:1001 -r 30000:1001 |
yuvcorrect -T PROGRESSIVE 2>/dev/null |
yuvfps -s 60000:1001 -r 60000:1001 |
y4minterlace -it |
yuvfps -s 30000:1001 -r 30000:1001 |
mpeg2enc -M0 -nn -a3 -f8 -G18 -b7000 -V230 -q9 -o $1

Reinterlacing during rendering is necessary because it is not possible to insert fields to frames after the compositor. Screen grabs showing the settings in Cinelerra are

Conclusions

The patches to fix the chroma errors in Cinelerra for interlaced 4:2:0 video source are simple. These patches are not necessary when editing DV video and rendering it back to DV or when editing HDV without any video effects and rendering it back to HDV. The patches become useful when rendering DV directly to mpeg2 through a yuv4mpeg stream and when using video effects on HDV video. They are necessary to obtain good chroma key results from HDV source.

Almost every video effect in Cinelerra can be used on interlaced video by inserting frames to fields before the effect and fields to frames after the effect. The compositor requires doubling the frame rate and moving the reinterlacing step to the rendering.


Last Updated: Sun Mar 27 22:26:18 PDT 2011