Video: Interlacing Headaches
Well, this morning I had my wisdom teeth out, and my jaw hurts. So far, I haven't resorted to the oxy I was prescribed, because the ibuprofin seems to be doing the job. I'm really hungry though.
As a result, I've spent some time today doing some recreational video encoding. As previous posts may have lead you to believe, I'm fascinated by figuring out how to utilize my fair use rights to convert video from one form to another. Lately, I've received an unlikely, and perhaps unwitting, ally in the fight from Sony, who in a strange turn, have released a spiffy portable device capable of playing user-created kick-ass video.
One outcome of this is that there's a lot of interest in the blogosphere in how to convert video from DVDs into more portable forms. As I've mentioned before, this is possible, but there are practical and legal impediments. With a will, I set myself to the task of converting our new Incredibles dvd to a portable form. (Disney is notoriously stingy when it comes to video releases, so the prospects for an offical portable release seem dim.)
What I'd like to say is that if you're on a Mac, there's a great tool for starting this process called Handbrake. The old version (0.6.2) was great, the new beta (0.7.0-beta 2) looks even better. It comes very close to the ideal of inserting DVD, pressing go, and getting a useful video file that you can play on your computer, burn to CD, stream over your intranet, or put on a portable device. If you have to convert some DVDs to computer form, it's a great tool.
People who aren't interested in annoying technical nitty-gritty can go download it and stop reading here.
For the rest of you, I was perusing the Handbrake forums and came across this interesting tidbit.
I've noticed that while the individual deinterlaced frames look good, when you play them, it'll skip every two seconds or so (really noticeable in long pans). It looks really out of place. I've tried it in both XviD and FFmpeg (both at 1280 kbs) and still the same thing. Just wondering if there's any way to fix this. If you don't know what I mean I can upload a sample. I just really want to know what's going on here. Thanks.
To which I offered the following response, which I think gives some interesting insight in to just what kind of a hassle it is to deal with digital video from analogue sources behind the scenes.
The reason that this is happening is possibly because the original source material (pre-interlace) was at 24fps. When someone converts 24fps film into 29.97fps interlaced video (often referred to as 60 fields henceforth) they have a few options, but the one that is typically used is to spread the 24 fps video frames out over alternate groups of 3 or 2 frames by using the interlacing.
So, what often happens is that:
Source frame 1 is field 1,2,3
Source frame 2 is field 4,5
Source frame 3 is field 6,7,8
Source frame 4 is field 9,10
Source frame 5 is field 11,12,13
Source frame 6 is field 14,15
6 frames at 24 fps = 1/4 second.
15 fields at 60field/sec = 1/4 second.
This is pretty groovy, and looks pretty smooth, but (wait for it) here comes your problem. deinterlacing is pretty tricky stuff. I don't know anything about the guts of handbrake, but however it's converting 60 field/second video into 30 frame/second video, the result is going to look like this: (assuming the odd frames are dominant).
output frame 1 comes from field 1 and thus source frame 1
output frame 2 comes from field 3 and thus source frame 1
output frame 3 comes from field 5 and thus source frame 2
output frame 4 comes from field 7 and thus source frame 3
output frame 5 comes from field 9 and thus source frame 4
output frame 6 comes from field 11 and thus source frame 5
output frame 7 comes from field 13 and thus source frame 5
output frame 8 comes from field 15 and thus source frame 6.
Note that this introduces a duplicated frame every 5 frames. This is not too troubling normally, but it tends to make pans and smooth movement look a little jerky. It _might_ be possible to use a smart deinterlacing mechanism (called a 3:2 pulldown) to turn the video back into its original 24fps frames, but in my experience this is an approach fraught with perils, and to be avoided if possible.
Finally, because 29.97 frames per second is the reality instead of the cleaner 30fps, we'll have an extra hiccup every once in a unless the source clip was at 23.985 instead of 24fps.
Short answer: Try to get a copy of your source material that isn't interlaced in the first place, interlacing is the bane of rational, easy-to-understand, computer video manipulation.
Neat, huh?