Video with Linux

When and How to Deinterlace

Interlacing is an engineering technique that doubles the field rate of a video while at the same time decreasing the vertical resolution by a factor of about 30 percent. It does this without changing the bandwidth required to transmit the uncompressed or analog video signal. Note that this decrease in resolution is necessary to avoid aliasing that would otherwise cause the interlaced image to flicker. More information on interlaced video can be found in Fields and Frames by Adam Wilt.

Note that telecined video is not the same as interlaced video. A source of telecined video may be obtained from the 1080p24 shooting mode of a high definition camcorder. Telecined video results from disguising 24 frames per second progressive video as 60 fields per second interlaced video. Do not deinterlace telecined video using the method described here. Instead remove perform an inverse telecine following the method described in PF24 Pulldown Removal with Linux.

Video for Display on Computers

You may have noticed that interlaced video looks awful on a computer monitor and wondered if it isn't just better to deinterlace before doing anything else. If you intend to watch the video only on a computer then this makes sense. In this case the right way mathematically to deinterlace would be to double the frame rate and decrease the spatial resolution by 30 percent. Therefore 704x480 NTSC widescreen video should be deinterlaced to obtain 704x336 progressive video with a pixel aspect ratio of 28:33 at 59.95 frames per second.

Given that square pixels are also a good idea on a computer, it might be better to deinterlace NTSC widescreen video to 704x400 or even 592x336 progressive video with a pixel aspect ratio of 1:1. Strangely, I have not seen any video content for computers with a 59.96 frame rate. It seems that people aren't interested in watching full motion video on their computers.

Suppose source.avi is 720x480 DV file that will be converted to an h264 encoded 592x336 progressive video Matroska file with a 59.96 frame rate. To do this one must deinterlace, scale, encode and then multiplex. Since DV video is interlaced bottom field first this can be done with the following sequence of commands:

$ ffmpeg -i source.avi -ab 128k -ar 48000 -acodec libfaac -y source.aac
$ ffmpeg -i source.avi -f yuv4mpegpipe -pix_fmt yuv420p \
        -y /dev/stdout |
    yuvcorrect -T INTERLACED_BOTTOM_FIRST 2>/dev/null |
    yuvdeinterlace -d |
    yuvcorrect -T PROGRESSIVE 2>/dev/null |
    yuvfps -s 30000:1001 -r 30000:1001 |
    y4mscaler -v 0 -O size=592x336 |
    yuvfps -s 60000:1001 -r 60000:1001 |
    y4mtoyuv |
    x264 --fps 60000/1001 --sar 1:1 --pass 1 --bitrate 1200 \
        --stats source.stats --level 4.1 --keyint 14 --min-keyint 2 \
        --ref 2 --mixed-refs --bframes 2 --weightb --direct auto \
        --deblock -1:-1 --subme 5 \
        --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct \
        --ipratio 1.1 --pbratio 1.1 \
        --vbv-bufsize 14475 --vbv-maxrate 17500 --qcomp 0.5 \
        --merange 12 --threads auto --progress --no-psnr \
        --no-ssim --output source.264 /dev/stdin 592x336 \
        --mvrange 511 --aud --nal-hrd
$ mkvmerge --default-duration 0:59.94005994005994005994fps source.264 \
        --default-durration 0:59.94005994005994005994fps source.aac \
        -o base.mkv
To encode 720x480 NTSC source that is interlaced top field first replace INTERLACED_BOTTOM_FIRST in the above set of commands by INTERLACED_TOP_FIRST. To create deinterlaced 704x400 widescreen video simply replace 592x336 everywhere above by 704x400.

Video for Display on Televisions

If the video will be displayed on a television, keep the interlacing. There is no need to muck up a video signal just because you are editing it on a computer. Interlaced video looks great on a traditional television and progressive scan televisions have advanced deinterlacing circuitry built in.

If there are bitrate constraints on the size of the final video stream that you will be writing to a DVD, then you may want to consider deinterlacing as a way of reducing the information content of the video source. In this case deinterlace to obtain 704x480 progressive video at 29.97 frames per second. This throws away half of the motion information and makes it easier to compress the resulting video at low bitrates. The resulting video stream will be in a DVD compliant format.

If you have lots of motion in your video source you may want to consider another method of reducing the bitrate. In this case cut the horizontal resolution by two. This yields a 352x480 resolution interlaced video stream that can be encoded at low bitrates. Again, the resulting video stream will be in a DVD compliant format.

High Definition Video

Progressive 1280x720 video with a 59.96 frame rate is an extermely versatile high-definition video format that works well on computers, HD-DVD disks and Blu-ray disks. If you have an 1080i HDV video source you may want to convert it to this format, called 720p60, before editing. The conversion loses a few lines of the theoretically available 756 lines of vertical resolution and more of the horizontal resolution. However it retains the full motion information of the interlaced source and has a 1:1 pixel aspect ratio. It is, therefore, reasonably high quality and easy to work with.

To convert the 1080i HDV file source.mpg to 720p60 the commands are

$ ffmpeg -i source.mpg -f wav -y source.wav
$ mp2enc -r48000 -b224 <source.wav -o source.m2a
$ ffmpeg -i source.mpg -f yuv4mpegpipe -pix_fmt yuv420p \
        -y /dev/stdout |
    yuvcorrect -T INTERLACED_TOP_FIRST |
    yuvdeinterlace -d |
    yuvcorrect -T PROGRESSIVE |
    yuvfps -s 30000:1001 -r 30000:1001 |
    y4mscaler -O size=1280x720 |
    yuvfps -s 60000:1001 -r 60000:1001 |
    mpeg2enc --no-constraints -f3 -nn -a3 -Ktmpgenc \
        -lh -b18000 -V488 -r32 -G18 -q3 -s -o source-720p.m2v
$ mplex -f8 -b488 -r20000 source-720p.m2v source.m2a -o source-720p.mpg
The resulting file source-720p.mpg is nearly as good as if it came from a progressive scan camcorder. Note, however, that if the highest quality HD-DVD and Blu-ray disks are your goal, it is best to keep the interlacing. See H264 HD Video Workflow for more information on creating 3xDVD and BD5 disks from 1080i HDV video source.

Conclusions

Deinterlacing is useful for computer video and for saving space on a DVD. However, if you want to create the highest quality DVD, HD-DVD or Blu-ray from interlaced source, do not deinterlace.
Page written and maintained by Eric Olson
Last Updated: Sat Jul 18 23:20:00 PDT 2009