Filtering

Introduction

iMovie is accessible: cheap and simple. My first DV camera was also cheap and simple. That's a bad combination because the original material quality is low when conditions are difficult and it stays low after processing due to the lack of filters in iMovie. There are excellent filters available from the mencoder command line, why not try to produce an encode with higher quality than its original?

This section should really be given just as much attention as the video codec section. That's because its role in the final encode quality is just as high, in my opinion. But, while I spent months trying to earn imperceptible gains in quality by tweaking the codec parameters, I will be able to subjectively evaluate most filters in real-time. It is so easy, in fact, that one can simply choose and tune the filters before each encode. For this reason I will simply "explore" the possiblities without going into much testing.

Interlaced video

DV video is interlaced, while most codecs and filters seams to expect progressive material. This issue must be sorted out first because it affects the way codecs and filters can be used. I find interlaced video to be a complex subject, but the mplayer doc covers that quite well and I will only discuss PAL video, which is simpler (and it's what I have to experiment with).

De-interlacing

The most common way to deal with interlaced material seams to be to render it progressive during the encode. This certainly ease-up scaling and improve motion search performance, for example. There are many options available, here is a few I've found worth trying on PAL video:

Just don't use l5 or fd. And md has a tendency to reduce the video resolution. lb blurs the movie and li has a bad aliasing in high contrast area. I like ci best in the postprocessing subfilter section but li is good too. kerndeint left too much interlace artifact in red/black areas.

Deinterlacing filters are temporal filters that need to see every frames, so they must be placed before a softskip statement. Here is an example: mencoder clip.dv -oac pcm -ovc xvid -xvidencopts bitrate=800:vhq=4 -vf pp=ci,softskip,scale=512:384 -o clip.avi. The scale filter is placed after softskip since it is CPU intensive.

Keeping it interlaced

If you care about preserving as much as possible of the original quality, you should keep the video interlaced. That's what the doc says and, I guess, it is especially true if you may need to convert the encoded video in the future to MPEG2 or back to DV. Encoding and filtering an interlaced video is significantly more complicated because they usually expect progressive content. Here are two examples:

With xvid you need to specify the "interlacing" parameter and with lavc you need to specify the two parameters "ilme:ildct". For the scale filter you need a third parameter (":1" after width and eight) which makes the scaler interlace-aware. An interlaced scaling is a complicated operation and, in the case of archiving DV, it doesn't make much sense to use it.

I also introduced a denoise filter in the example: it is a 3D filter which doesn't work on interlaced content. The trick is to first deinterlace the 2 fields into one progressive frame where the upper part contains the first field packed and the lower part contains the second field packed in the same fashion. It's the role of "il=d". After aplying the filters to this progressive picture, you must restaure the interlaced fields using "il=i".

Both codecs and filters perform worse on interlaced content, so the bitrate must be increased accordingly. lavc is performing better than xvid, but only without B-frames. When allowing B-frames in lavc, mencoder fails in bitrate.c, complaining about an unmatching count of frames. If you don't plan to convert your encodes back to MPEG2 or DV, it is best to deinterlace them.

Bobbing

I've read people using this term for a technique also called double-rate deinterlacing, I think. The idea is to make a full frame out of each fields, resulting in a progressive movie with twice the number of frames. The movie can be re-interlaced later during playback: the full resolution is preserved and the encoder/filters work on progressive content. Here is an example: mencoder clip.dv -oac pcm -ovc lavc -lavcopts vbitrate=800:mbd=2:v4mv -vf tfields=4:1,softskip,hqdn3d=0:0:6 -ofps 50 -fps 50 -o clip.avi.

More?

Here is yet another way, similar to bobbing. You can group all the lines of a field at the upper half of the frame, then group all the lines of the next field at the lower half of the same frame: odd lines up and even lines down. That gives you a progressive frame at a normal rate which contains 2 concecutive frames of the original movie. Like bobbing, the movie can be re-interlaced later during playback: the full resolution is preserved and the encoder/filters work on progressive content.

But like bobbing, it doubles the job of the encoder, requiering higher bitrates. And the spacio-temporal filters like hqdn3d can't operate correctly when half the frames are missing for the given space. Finally, when the frames are re-interlaced for playback, the unmatched artifacts of the 2 fields look really bad.

Noisy video

The best way to reduce noise seems to be the hqdn3d filter. As shown before, you can get good result with hqdn3d=0:0:4 on progressive content and hqdn3d=0:0:6 on interlaced content. This will allow you to reduce encoding complexity to obtain better quality when you are planning to use high bitrate. The noise will not disapear, but you will also preserve the movie "grain" and the small details. If you aim at lower bitrates, or if you really want to get rid of the noise, the default values are fine and you can simply use hqdn3d without parameters.

Under-exposed video

As a last resort, if you have troubles with under-exposed sequences, you can try the postprocessing directive pp=al or autolevels.

MPEG2 artifacts

If your video camera records directly on DVD, your source is not DV but MPEG2. The encoding artifacts will be especially obvious during fast moving camera movements or with fast moving objects. It's important to reduce them before re-encoding to DIVX with the postprocessing directive pp=ac. This can also help a bit on DV sources where the tape was dirty or damaged.

Conclusion

This should bring you a bit further than iMovie. hqdn3d is an excellent filter that surely improves the final result. Don't hesitate to de-interlace, there's just no other way! And, on MPEG2 sources, get a small improvement with pp=ac.