LVPE: Capturing & Deinterlacing DV Footage
(this post is part of the Linux Video Production Experience series, which chronicles my experiences with creating a high-quality home movie almost entirely in open source software.)
OK, just so I’m not wasting a bunch of time explaining something that someone else has already explained much better, go to 100fps.com and learn about the evils of interlacing, and why it’s such a pain to work with under most circumstances. I’ll just say straight up that I much prefer working with progressive frames while editing, so that’s what I’m going to use in this production. I used mencoder to generate AVI files for Cinelerra. The most recent version in the Ubuntu repositories will be just fine (if you use Ubuntu, of course).
I captured all of my DV footage using Kino. Kino splits your DV files by timestamp. Capture all of your DV files to a directory just for DV files (let’s call it “DV”). Kino is pretty self-explanatory, but you may have some permissions issues with the FireWire device in /dev. I always do, and they’re easy to fix with a sudo chmod (and permanently with some udev settings, but I’m lazy).
Just so you know, I’ve tried doing the editing of interlaced footage in Cinelerra, both with and without Cinelerra’s deinterlacer enabled, and it works, but it can get weird, especially when you accidentally move a camera or projector on a timeline with interlaced footage. I also like the deinterlacer in mencoder much better.
Create a directory alongside (not within) the DV directory and call it “Deinterlaced”. Now, open a shell window and cd to the directory that contains the “DV” and “Deinterlaced” directories.
We’re going to be reading the DV files and deinterlacing them using the very nice and very fast Yet Another DeInterlace Filter which was originally built for mencoder. We’re then going to save each deinterlaced file out as an AVI file with WAV audio and almost-lossless MJPEG video frames. Cinelerra reads these files quite well. This small bash script will do the trick:
#!/bin/bash
for i in DV/*; do
echo $i
file=$(expr "$i" : '.*/\([^/]*\).dv')
rm Deinterlaced/divx2pass.log
for pass in 1 2; do
mencoder -oac pcm \
-ovc lavc \
-af resample=48000:channels=2 \
-lavcopts vcodec=mjpeg:nr=200:vbitrate=15000:aspect=16/9:vpass=$pass:mbd=2 \
-vf yadif \
-ofps 30000/1001 \
-o "Deinterlaced/$file.avi" \
"$i"
done
done
You can also download this script instead of copying and pasting it from the site: dv_deinterlace.sh.
If you’re shooting with a consumer level camera and the lighting’s bad, the footage will be noisy. The nr option in -lavcopts controls the strength of the noise reduction. 200 is pretty low, but it worked well enough for this production. Go too high and the footage gets blocky.
Note that this script assumes you’ve shot 29.97 FPS NTSC video that was interlaced by your camera, which most NTSC consumer level cameras will do (indicated by the -ofps 30000/1001 option). If you’re already shooting 24p footage (23.97 FPS progressive), then you don’t need to do this, you lucky Panasonic DVX100 owner. You can still use mencoder to denoise your footage, though. Remove the -vf yadif line, replace 30000/1001 with 24000/1001, and change the nr value as necessary.
This script also assumes you’re shooting with a 16:9 aspect ratio (widescreen). If you’re shooting 4:3, change the aspect option in the -lavcopts line from 16/9 to 4/3.
Now, this produces some very nice looking output when compared to the original frame (DV first, yadif second):
And a short video to illustrate the deinterlacer in action: Tasha deinterlaced (h.264 MP4, no audio, 1.5 MB)
If you really need to pump up the quality, and don’t mind burning a ton of extra CPU time to do so, replace the -vf yadif line in the above script with this:
-vf yadif=3:0,mcdeint=1:0:10,framestep=2
This turns on both yadif and the motion compensation deinterlacer. This deinterlacer combo is of extremely high quality, probably as good as the hardware deinterlacers that are out there (I’m guessing). However, it will slow your processing time down to a crawl. For the footage I shot, I compared the results of just yadif to yadif+mcdeint, and the quality difference wasn’t worth having my computer run at 100% for days. It only took a few hours for yadif alone to deinterlace an hour and forty minutes of footage. If it really matters, though, you know how to turn it on.

August 17th, 2008 at 9:42 am
Hi, just wanted to point out that the script you used to deinterlace is not displayed correctly. maybe link it? to get it working I had to escape the parentheses for the substring matching part in the regular expression. without it the script would 0 as filename thus overwriting files in the target directory if there were more than one file in the source directory.
August 17th, 2008 at 9:57 am
Thanks for pointing that out. WordPress 2.5 seems to have fixed the issues I had with writing out the initial script. How does this look?
August 17th, 2008 at 11:47 am
looks better, I think there is still an issue with the single end quote around the regular expression, but I haven’t tried it.
I guess I should have said so earlier but thanks for your tutorial. I’ll be trying to follow along as I cut a video of my own. I’ve tried Kino for such stuff but that was simply too limited. I’m pretty much new to video cutting in General but from what I’ve read your tutorial will give me the needed pointers.
September 20th, 2008 at 9:17 am
As Conrad mentions, the single quote at the end of the file= line is still wrong, in the source for the page it is shown as ’ (ampersand hash 8217 semicolon) rather than just plain single quote. The 2 filenames on the last 2 lines before the done should probably have dounle quotes round them, to allow spaces in filenames, i.e.
-o “Deinterlaced/$file.avi” \
“$i”
Thanks for the script, it’s been most useful!
October 1st, 2008 at 8:38 pm
Curse you, WordPress!
Thanks for your input, @Toby and @Conrad. I decided to package the script up as a single file. Give it a shot and let me know if it works for you:
http://www.coswellproductions.com/dv_deinterlace.sh