Picture-perfect MythTV: how to improve video quality

by Rudd-O published 2007/07/16 06:05:12 GMT+0, last modified 2013-06-26T03:24:19+00:00

Envious of how good TVTime looks compared to MythTV? Envy no more.

Excellent picture quality is important if you use MythTV a lot. Unfortunately, if you're using a standard Brooktree (bt848 or bt878) video capture card, the default settings of your card work against you. You might have noticed light colors washed out, color ringing on sharp vertical lines, brightly lit areas of the video flashing rapidly, and a general picture darkness that doesn't make MythTV justice when comparing it to a TV set or TVTime.

We're about to fix that for ya.

Step 1: install the adjust filter on each channel

First, we fix recording. Brooktree-based cards have a bug that causes it not to capture colors correctly. Using a MythTV filter, we can beat the color space delivered by the card into the standard.

Use the MySQL client to execute this command on the MythTV database (usually named mythconverg):

update channel set videofilters='adjust=0:255:1.0:2:253:1.0';

That adjust filter will map the incorrectly captured colors to the standard TV color space. Now recorded videos will contain the right color balance and brightness/darkness mix.

Note that, if you add any new channels, you will need to re-run this command.

Step 2: adjust gamma correction on your monitor and enable deinterlacing

Now it's time to adjust the gamma correction and interlacing adjustments.

What gamma correction does is lighten or darken the picture up. Think of gamma as a way to make the picture brighter or darker in average, without making the light parts lighter or the dark parts darker. Brightness controls are inferior to gamma, because gamma, unlike brightness, doesn't make light colors look "burnt".

Unfortunately, the standard X Window System gamma control usually has no effect on video (Xv) windows (though NVIDIA card users can use the nvidia-settings gamma correction control which will work properly). Fortunately, the same adjust filter has a gamma correction argument, and we'll leverage it. This time around, the adjust filter won't change the color map.

Now open MythTV and go to the Playback options screen:

  • Enable kernel deinterlacing (unfortunately, there isn't a better deinterlacing algorithm in MythTV -- TVTime still beats the competition in this department).
  • If you could not alter the gamma of Xv video windows, do this: just below that option, set this playback filter on the playback: adjust=16:235:0.7:16:240:1.0. Change the 0.7 in there to suit your tastes: the lower the number, the "brighter" the picture will look. I use that number because my monitor is fairly old -- in theory the ideal number would get your monitor from the standard PC gamma of 1.5 to the TV gamma of 2.2, but I have no idea what the right number is -- I just set it up so my old monitor looks good.

The second step will cause loss of some color information on playback. However, the recorded video preserves the full color range.

Step 3: eliminate dot crawl (color ringing around sharp lines)

A frequent problem with Brooktree-based cards is dot crawl: vertical and diagonal lines on the picture display rapidly alternating patterns of colors in a vertical or staircase fashion. Besides being unnerving, it costs you picture quality, because the video encoder will spend many bits to encode these rapidly changing artifacts instead of spending them on the detailed portions in the real picture.

Install these commands on a file named /usr/local/bin/fixbttv. These commands will enable certain types of processing in your video capture card that will eliminate dot crawl:

#!/bin/bash

v4lctl -c /dev/video0 setattr 'combfilter' on
v4lctl -c /dev/video0 setattr 'agc crush' off
v4lctl -c /dev/video0 setattr 'whitecrush upper' 255
v4lctl -c /dev/video0 setattr 'whitecrush lower' 0
v4lctl -c /dev/video0 setattr 'full luma range' on

Full luma range ensures that your capture card captures the entire color range.

Oh, forgot to mention it: the AGC crush control we're turning off here basically stabilizes the picture produced by my card. If you see a light "blinking" of the picture, this will help.

Don't forget to make it executable with chmod +x /usr/local/bin/fixbttv.

Then create the file /etc/modprobe.d/bttvwith these contents:

install bttv modprobe --ignore-install bttv && /usr/local/bin/fixbttv

Finally add the command /usr/local/bin/fixbttv to the file /etc/rc.local.

Step 4: restart your machine

That's it. I hope the good six hours I spent figuring this out helps you pimp your MythTV in ten minutes. Just to be sure, take a "before" and an "after" videoclip so you can compare the results.

Now, for a question: why on Earth does xvattr -a XV_GAMMA -v 1300 work for only a hundredth of a second, then stops working? I'm using an ATI Mobility Radeon if it's relevant.