Outputting to a High-Definition TV

The initial cut of this section is the collaboration of a posting to the mythtv-users list by Ian Forde and personal experience setting up the connection to my own High-Definition TV. I knew pretty much zilch about HDTVs coming into this, outside of the fact I had one (a 47" Panasonic, can't recall the model number), it supported 1080i and had two component video inputs. I probably spent a good ten hours or so reading over numerous pages at AVSForum, Digital Connection, Brandon Beattie's Linux HTPC HOWTO, and a few other places I can't recall before making any purchase.

I started out thinking that I'd use a DVI-to-component video adapter, and found such a cable at a local shop, Pacific Custom Cable, for about $25. I took it home, tossed one of my GeForce 4 Ti cards with a DVI output into my MythTV box, and fired it up. Oops. Wrong cable type. A simple DVI to component video cable converts DVI to RGB component video. My HDTV takes YPbPr component video. You get really hideous colors on the screen (if/when you get any at all), because the signaling and color channels are swapped around a bit (think painful-on-the-eyes flourescent yellow-green). Unfortunately, this meant I had to take the cable back and get a VGA to YPbPr component video transcoder, which has a bit heftier price tag (about $110). Pacific Custom Cable just so happened to carry the Audio Authority 9A60, so that's what I got. Other popular products that provide the same functionality are the Key Digital KD-VCTA3 and RCA VHDC300. However, if you've got either DVI or VGA inputs on your HDTV, you'll probably be better off using those (especially if the set will send DDC info).

Given how very little I knew on the subject, I went home thinking "I'll hook it up, and it'll just work" (using one of the 1920x1080i modelines I'd already found), since my X-Box "just works" with its HD kit. WRONG!!! I spent several hours over the next few days beating my head against the wall, talking on the phone with some very helpful folks at Audio Authority, and cruising the AVSForum discussion boards. It was actually a modeline I'd never come across before that someone on AVSForum posted after hearing what TV I was using that got me close enough to what I needed that I finally started making some real headway.

Said mode was a 540p mode, which will make those of you only casually familiar with High-Defintion go "Huh? I thought the standard were 1080i, 720p and 480p." Well, this is true, but 540p and 1080i are electronically equivalent. A 1080i signal uses interlacing (thus the i), meaning only 540 lines are drawn in frame x, while the other 540 are drawn in frame x+1. A 540p mode simply draws all 540 lines every frame, and thus the TV has no idea of the difference. It just knows its getting 540 lines every frame to spit out to the display.

There are several ways to go about attempting to find just the right modeline for your HDTV. For someone without a great deal of understanding about what all the elements of an Xorg modeline are and a set (like mine) that won't send any display data channel (DDC) information back to the computer, you might be best off temporarily running Windows on your system, so you can take advantage of the excellent PowerStrip software, from EnTech. Chances are, you'll also want a monitor available to use along with PowerStrip, because you can't tweak it if you can't see it (you'll set a mode on the monitor, then hook up the TV to examine it, back to the monitor if you can't see anything, rinse and repeat). This should be a fairly new monitor, capable of displaying a wide variety of resolutions, since you may be having to hook it up to your system while you're pushing non-standard resolutions (an older monitor may fry or simply display garbled junk, if anything at all). An excellent reference for using PowerStrip can be found here: http://www.ramelectronics.net/html/powerstrip.html.

Before we get any further into this, you can find an example, fully working configuration I created for my HDTV, using a GeForce 4 MX for output (should work with any GF4 or FX card, I'm actually using an FX 5200 Ultra right now), right here: http://wilsonet.com/mythtv/xorg.conf-HD.txt

The PowerStrip route

The steps for going the PowerStrip route are essentially (extrapolated from Ian's posting):

  1. Shut down my computer and disconnect your Linux/MythTV hard drive(s).
  2. Connected a different hard drive upon which you will install Windows.
  3. Apply any relevant patches (if you have the time and bandwidth, just get it as up to date as possible with everything Windows Update wants to throw at it).
  4. Install the drivers for your card (nVidia's ForceWare, formerly Detonator, in this case) and configure them for a single display, type CRT (if necessary).
  5. Install PowerStrip, available from EnTech
  6. Figure out what modes your TV support (1080i and 480p according to my manual, but also 540p for the reasons detailed above).
  7. Use PowerStrip, following (carefully) the instructions on AVSForm and/or Digital Connection. The directions found by following both these links are relatively old. The only significant differences are that you may have to reboot your computer after creating a custom resolution before you can safely use it and the mention of 1080i modes for nVidia cards, which won't work under Linux (apparently, a driver support issue, which *might* be remedied in the future...).
  8. Once Windows is displaying at an optimal resolution, without too much over- or under-scan, click on the "Copy to clipboard" button on one of the screens.
  9. Fire up your favorite Windows text editor (please don't say Microsoft Word ;-), then paste that clipboard copy into your text file. The last time I (Jarod) personally used PowerStrip (several months ago), it only spit out PowerStrip timing paramters and generic timings. I just looked at the latest version (3.49 as of this writing), and it actually spits out Linux modeline parameters as well. COOL! (The conversion isn't that hard, but hey, one less thing to worry about).
  10. Save that text snippet to another location so you can get it onto you Linux/MythTV setup.
  11. Shut down your system, disconnect the Windows drive, reconnect your Linux/MythTV drive(s), disconnect from the HDTV and connect back to your monitor, then start the computer back up.
  12. Now get that text file onto your Linux/MythTV machine.
  13. Make a copy of your xorg.conf file:
    $ cp /etc/X11/xorg.conf ~/xorg.conf.HD
  14. Open the modeline file from PowerStrip and the xorg.conf.HD file in the text editor of your choice (if you're using KDE, kwrite will do just fine, gedit if you're in GNOME). In Section "Monitor", you need to set HorizSync to 31.5 - 37.9, VertRefresh to 59.9 - 60.1, immediately followed by a new line prefixed by "ModeLine", right after which you should paste in the modeline from PowerStrip. Take note of the field after ModeLine in quotes, as this is the name of the mode you'll specify as your primary later in your xorg.conf file. This name is arbitrary, and I recommend making it something distinctive. Below is an example "Monitor" section:
    Section "Monitor"
    Identifier "Monitor0"
    VendorName "Some Vendor"
    ModelName "HDTV"
    HorizSync 31.5 - 37.9
    VertRefresh 59.9 - 60.1
    ModeLine "960x540p" 37.26 960 976 1008 1104 540 542 548 563 +hsync +vsync
    EndSection
  15. In Section "Screen", under SubSection "Display", find the Modes section for your DefaultDepth (should be 24). Specify that mode name (the field after ModeLine) as the first one in the list (it can also be the only one). Here is an example "Screen" section, corresponding to the above "Monitor" section:
    Section "Screen"
    Identifier "Screen0"
    Device "Videocard0"
    Monitor "Monitor0"
    DefaultDepth 24
    SubSection "Display"
    Depth 24
    Modes "960x540p"
    EndSubSection
    EndSection
  16. Now backup your current running xorg.conf and drop the one you've been editing into place:
    # cp /etc/X11/xorg.conf /etc/X11/xorg.conf.noHD
    # cp /path/to/xorg.conf.HD /etc/X11/xorg.conf
  17. Restart X (ctrl-alt-backspace or just log out if you're in X already, init 5 or startx from the command line) and see if it doesn't puke. If you get a picture, now disconnect the monitor and hook up your TV. In theory, since this mode worked fine on the Windows side, it should work here as well (with a small caveat, as some Windows drivers support interlaced modes where their Linux driver counterparts may not, such as in the case of nVidia). If you get nothing useful on screen, back to the drawing board. Look in /var/log/Xorg.0.log for clues on what might have gone wrong. It ought to work if you've done everything correctly though.
  18. Now fire up MythTV and configure it to adjust the GUI as necessary for everything to fit appropriately on screen. You can either be happy at this point, and leave well enough alone, or you can tweak further... I tweaked further! (See below for further tweaking).

The quick-and-dirty, might save you lots of time route

Simply copy the xorg.conf file I'm using into place on your system. Quite a few people have reported to me that it worked for them without modification. The abridged version of how to do that is (on your Linux/MythTV box, as root):

# wget http://wilsonet.com/mythtv/xorg.conf-HD.txt
# cp /etc/X11/xorg.conf /etc/X11/xorg.conf.noHD
# cp xorg.conf-HD.txt /etc/X11/xorg.conf
# init 3 && init 5

You could also try something similar with any of the modelines posted on Brandon Beattie's Linux HTPC HOWTO site, though not a single one of those modes worked for me (and I tried ALL of them, several times...). You can always ssh into your Linux/MythTV box if you want to copy and paste in different modes without having to keep switching over to a monitor (which is actually what I did for the bulk of my walk down this path).

Further tweaking your picture

If you've got all the timing parameters correct, it is entirely possible to run an arbitrary resolution within those timings. What I'm actually running on my HDTV right now is an 880x480 mode inside 540p timings, which means the desktop fits my screen just about perfectly. I also made some minor adjustments to some of the timings to shift the picture down and over to the left a little bit, though this is a bit more involved (see Eric S. Raymond's XFree86 Video Timings HOWTO for details -- applies equally to the X.org X server). Just about any change you make to any of the parameters of a modeline should be by a factor of 8, so keep that in mind if you decide to tweak. Below is the actual modeline I'm currently running for my MythTV GUI, based off the initial 960x540p mode above:

ModeLine "in540p" 37.26 880 944 1048 1104 480 506 520 563 +hsync +vsync

Now that MythTV has support for the X server xrandr (X resize and rotate) extension, and the latest nVidia Linux drivers support interlaced modelines, I've also got a custom 1080i mode, which I switch to when viewing High Definition Content. My in1080i mode is:

ModeLine "in1080i" 74.52 1760 1888 2096 2208 960 1012 1028 1126 -hsync -vsync interlace

This mode was essentially derived by doubling all the values from my in540p mode. Can't recall why the flip in polarity of the hsync and vsync parameters, but the interlace flag is pretty obvious. :-)

Another route that may be worth investigating, if you know the horizontal sync and vertical refresh capabilities of your television, is the gtf program, which is distributed with most X servers these days. What gtf stands for is Generalized Timing Formula, and what you can do with it is feed it a resolution and vertical refresh rate. With those values, gtf will calculate a modeline, that in theory, should work for your set. If it produces hsync values outside the range your set says are acceptable, try adjusting the vertical refresh value you feed gtf up and down. For example, you might start with this:

$ gtf 1280 720 60
# 1280x720 @ 60.00 Hz (GTF) hsync: 44.76 kHz; pclk: 74.48 MHz
Modeline "1280x720_60.00" 74.48 1280 1336 1472 1664 720 721 724 746 -HSync +Vsync

In theory, the vertical refresh value you're feeding ought to always be around 59.94Hz for 720p modes and 29.97Hz for 1080i modes, but that unfortunately doesn't always seem to hold true. :\

HDTV capture cards

There are now about a dozen HDTV capture cards supported under Linux. Check out the HDTV part of the capture card section of the main HOWTO document for details on setting them up. Some day, I'll actually complete 'em... :)