Introduction
Determining your needs
Basic Hardware
Audio
Video
Video Card Configuration
LIRC
Input Devices
TV/HDTV Tuner Cards
Installing Linux
HTPC Software
HTPC Tips and Tricks
Conclusion

Linux HTPC How-to

Video Card Configuration

Disclaimer reminder

An incorrect modeline can cause damage to any display device. If you haven't read my disclaim on the introduction page, do so. You can try things I recommend as you'd like, but you must do so at your own risk. I can not and will not make any guarantees.

The role of Refresh Rate in Video

If you are connecting your HTPC to some type of non-computer monitor you will have to deal with refresh issues. Refresh rates are basically the number of times the screen is drawn per second. Standard U.S. TV refresh rates are 59.94 screens/cycles per second (Hz). Each time a frame is drawn on a TV, everyother line gets drawn each refresh, so TV refresh is also refered to as 29.97 interlaced. If you know about Progressive video, it means a full frame (non-interlaced) is sent per refresh. Film (In movie theaters) is 24 Hz (Progressive). DVD's can be 23.976, 25, and 29.97Hz. HDTV standards include 24, 25, 29.97, 30, 50, 59.94, and 60 Hz. The reason for so many different refresh rates is because of ugly backwards compatibility issues.

All old TV's only display 59.94 Hz. Why 59.94 was picked I don't know for sure but it's rumored to be what worked. So modern equipment has to support what worked even though this it is a pain. With modern technology like DVD players, they take a refresh rate that is not 59.94 Hz and make it 59.94 Hz. Sometimes in this conversion video frames are shown duplicate times. What is shown is not correct and that is why you see jitter if you watch stock tickers on a TV. There are some algorithms and professional ways of keeping the video as smooth as possible.

Pulldown is one technology. There is 3:2 pulldown and 2:2 pulldown. An example of pulldown for 3:2 is a DVD player will display frame #1 twice, frame #2 three times, frame #3 twice and then repeat this pattern. If you take a DVD with a 23.97 Hz movie you can use this algorithm to make a 59.94Hz video. You rarely would ever notice this being done with a low quality NTSC TV image but most everyone has seen it in a movie that has a more detailed image. The point is this happens, it's ugly, and people are doing things to help improve it. tvtime is the Linux version of D-Scaler. tvtime will deinterlace, remove jitter, and overall improve the quality of the video. We can also apply these techniques internally to programs such as MythTV.

If you are very concerned about this issue you should read up on it and then you can tweak the settings of your video card and media players to make things work better. At this time I'll leave it up for others to learn on their own as it's far to involved for this howto currently, but now you should realize the importance of this. A good place to look further into this is at vektor's deinterlacing page.

Selecting the refresh rate for your HTPC

Now that you know how big of a role refresh rates play in video, lets move on to how you can make this work correctly in your HTPC.

First you need to find out what refresh rates your display device supports. If you are using a display device that takes VGA or DVI, your HDTV, Projector, etc.'s manual it should have a list of supported refresh rates and resolutions. Our optimal choice is to pick the highest progressive (your other option is interlaced) resolution with a refresh rate of 120 Hz. The reason I suggest 120 Hz is 120/24=5 and 120/30=4 which means that without doing pulldown, most video should look great with little or no extra work.

HDTV

If you own a HDTV, you probably won't be able to use 120 Hz. You will have to decide if you want a better image watching DVD's or TV. Pick a refresh that is a multiple of 23.97 for DVD and multiple of 59.94 for TV. One small advantage of choosing TV is that it is easier to cause your DVD software player to do internal 3:2 pulldown for you so you can get the best of both worlds.

Projectors and Plasma screens

If you have a projector you can pick any refresh from 24-300 on some models. Find out what your projector supports and pick 120 Hz if possible. I run mine at 120 Hz. One area I'm still trying to research is what a true native refresh rate is of a DLP projector. The mirrors can go anywhere from 24 to 300 that I have found. However, DLP uses a color wheel which I believe runs at the same speed. That means there is a set refresh that is optimal. For each speed your DLP projector is on the color wheel it is 60 Hz. A 3x color wheel is 180 Hz and therefor I may be messing up my refresh rates by sending a 120 Hz signal to a 180 Hz display, but I haven't noticed jitter so I am hoping I am wrong. There also isn't a good reason to use 240 Hz even though it's a multiple of 30 and 24.

Picking your resolution

This is very simple (if you have a native HDTV resolution). Find out what your Native resolution is on your display device and use that. If you do not have a native HDTV display then read on otherwise skip to the next step.

If you are using a projector that does not have a native HDTV resolution (Such as mine that is 1024x768) there are two things you can do. Most projectors can take signals such as 1024x576, even if your manual doesn't say it is supported. You can find out what a HDTV ratio resolution by doing the following.
  • Find out the native horizontal resolution (This is usually the first number, such as 1024 in my case).
  • Calculate 9/16*horizontal_resolution
In my case 9/16*1024=576 and so my HDTV ratio resolution is 1024x576. If you get a non integer number (maybe 697.234) just round down to 697.

You may have to try some different vertical resolutions (The 576 number) if the proper one does not work correctly when you try it. This is where a trial and error process can come into place when trying the custom modelines below.

So you know, my projector thinks the signal I am sending it is a 1024x600 signal (When it isn't). I have verified it is 1024x576 by checking for irregularities when viewing a pixel pattern on the screen. (Start X with xinit and do not use a window manager. This will give you a pixel pattern that looks like this.
XOOO
OXOO
OOOX
OOXO
Check around the entire screen and see if you have any pixels that are not at diagonals. If you do then that resolution is not working correctly. If it looks correct then ignore any incorrect readings on your display device.

The other thing you can do is run your HTPC in a non HDTV resolution. Application such as MythTV can be told to start at a certain location on the desktop and be a certain size. This isn't the best option but can be used as a last resort. Other applications can be set via desktop/window manger settings on a per application basis.

What to do once you know what resolution and refresh rate to use

Hopefully you have a refresh rate that will work. The next step is getting the X server to use that refresh rate. This is done by giving XFree 86 (The most common X server Linux) a custom modeline to use. Although new XFree86 config files do not have modules anymore, they still accept them.

Creating a custom modeline

There are several tools to help create custom modelines. The easiest program to use for creating custom modelines is videogen. To use videogen, download and install then. Then create a file in your home directory called .videogen . (ie: /home/mythtv/.videogen) In that file you need to modify the max_dotclk, max_hfreq, and desired_vfeq to the values that are in your display device manual. The file also should contain lines with different resolution modes. An example of a .videogen is as follows:
max_dotclk=300                  # the maximum pixel/dot clock supported by my projector
max_hfreq=130; max_vfreq=160    # the max horizontal and vertical frequency
desired_vfreq=120               # the frequency you decided to use
                                                                                
mode 1024x576                   # the resolution your HTPC will be running at
When you run videogen it will read this file and then give you an output of the modeline:
Modeline "1024x576" 93.08 1024 1056 1200 1280 576 578 581 606  # 93 MHz, 72.7 kHz, 120.0 Hz
So there is your custom modeline. There are other applications from web applets to powerstrip (for windows) that will give you Modelines.

Using your custom Modeline

Edit your /etc/X11/XF86Config-4 file and find the section labeled Section "Monitor". Add the modeline into that section of the config file (I put mine just above the EndSection line).

Now find the section labeled Section "Device". Find the line:
Option "MetaModes"                "1280x1024,1280x1024; 1024x768,1024x768"
Change this line to the resolution you are using for your HTPC:
Option          "MetaModes"                  "1024x576"

Figuring out why it doesn't work

So you followed my steps and it didn't work. This is where it may be difficult and you have to spend a bit of time debugging. If you really want to and don't care, just forget all this video optimization and use whatever worked before. (I hope you read this how-to first and know to backup any files you change.)

If X fails to start with invalid mode lines, try disabling the
Option          "DPMS"
line in your XF86Config-4 file. This causes X to not probe and find a compatible resolution (I had to do this). Also start putting your X error messages into a search engine and see if you can find an answer.

If you are getting a correct image, but it's not correctly positioned, (or even if you think it is) run xvidtune and try moving the display around and see if that helps center the image. Xvidtune really only needs to be used if you are using a non HDTV display like myself. If you have a true native HDTV display you don't need to do this.

Modelines ready-to-go for native HDTV displays

If you have a native HDTV display, here are the modelines for you, without you having to build your own. (These modelines were taken from a post at avsforum.com by Jason Pearce.)

Analog-RegularModes
ModeLine "NTSCspec-59.94i" 14.318 768 784 848 910 483 484 492 525 Interlace
ModeLine "NTSCspec-59.94p" 28.636 768 784 848 910 483 484 492 525
ModeLine "Laserdisk-59.94i" 567 583 647 684 483 484 492 525 Interlace
ModeLine "Laserdisk-59.94p" 567 583 647 684 483 484 492 525
ModeLine "Broadcast-59.94i" 483 484 492 525 Interlace
ModeLine "Broadcast-59.94p" 483 484 492 525
ModeLine "VHS-59.94i" 483 484 492 525 Interlace
ModeLine "VHS-59.94p" 483 484 492 525

DVD-NativeModes
ModeLine "NTSC-DVD-59.94i" 13.5 720 736 800 858 480 484 492 525 Interlace
ModeLine "NTSC-DVD-60i" 13.514 720 736 800 858 480 484 492 525 Interlace
ModeLine "NTSC-DVD-59.94p" 27.0 720 736 800 858 480 484 492 525
ModeLine "NTSC-DVD-60p" 27.027 720 736 800 858 480 484 492 525
ModeLine "NTSC-DVD-71.93p" 32.4 720 736 800 858 480 484 492 525
ModeLine "NTSC-DVD-72p" 32.432 720 736 800 858 480 484 492 525
ModeLine "NTSC-DVD-119.88p" 54.0 720 736 800 858 480 484 492 525
ModeLine "NTSC-DVD-120p" 54.054 720 736 800 858 480 484 492 525

DILA-Projector-NativeModes
ModeLine "DILA-47.95p" 91.493 1360 1464 1608 1800 1024 1026 1028 1060
ModeLine "DILA-48p" 91.584 1360 1464 1608 1800 1024 1026 1028 1060
ModeLine "DILA-50p" 95.4 1360 1464 1608 1800 1024 1026 1028 1060
ModeLine "DILA-59.94p" 114.366 1360 1464 1608 1800 1024 1026 1028 1060
ModeLine "DILA-60p" 114.48 1360 1464 1608 1800 1024 1026 1028 1060
ModeLine "DILA-71.93p" 137.239 1360 1464 1608 1800 1024 1026 1028 1060
ModeLine "DILA-72p" 137.376 1360 1464 1608 1800 1024 1026 1028 1060
ModeLine "DILA-MarkR-71.997" 139.202 1360 1464 1608 1824 1024 1026 1028 1060

DTV-StandardModes
ModeLine "ATSC-480-59.94i" 11.958 640 664 736 760 480 484 492 525 Interlace
ModeLine "ATSC-480-60i" 11.97 640 664 736 760 480 484 492 525 Interlace
ModeLine "ATSC-480-59.94p" 23.916 640 664 736 760 480 484 492 525
ModeLine "ATSC-480-60p" 23.94 640 664 736 760 480 484 492 525
ModeLine "ATSC-480a-59.94i" 11.958 640 664 736 760 480 484 492 525 Interlace
ModeLine "ATSC-480a-60i" 11.97 640 664 736 760 480 484 492 525 Interlace
ModeLine "ATSC-480a-59.94p" 23.916 640 664 736 760 480 484 492 525
ModeLine "ATSC-480a-60p" 23.94 640 664 736 760 480 484 492 525
ModeLine "ATSC-720-59.94p" 74.176 1280 1320 1376 1650 720 722 728 750
ModeLine "ATSC-720-60p" 74.25 1280 1320 1376 1650 720 722 728 750
ModeLine "ATSC-1080-59.94i" 74.176 1920 1960 2016 2200 1080 1082 1088 1125 Interlace
ModeLine "ATSC-1080-60i" 74.25 1920 1960 2016 2200 1080 1082 1088 1125 Interlace
ModeLine "ATSC-1080-59.94p" 148.352 1920 1960 2016 2200 1080 1082 1088 1125
ModeLine "ATSC-1080-60p" 148.5 1920 1960 2016 2200 1080 1082 1088 1125

DTV-MovieModes
ModeLine "ATSC-480-71.93p" 28.699 640 664 736 760 480 484 492 525
ModeLine "ATSC-480-72p" 28.728 640 664 736 760 480 484 492 525
ModeLine "ATSC-480-119.88p" 47.832 640 664 736 760 480 484 492 525
ModeLine "ATSC-480-120p" 47.88 640 664 736 760 480 484 492 525
ModeLine "ATSC-720-71.93p" 89.011 1280 1296 1360 1650 720 722 728 750
ModeLine "ATSC-720-72p" 89.1 1280 1296 1360 1650 720 722 728 750
ModeLine "ATSC-720-119.88p" 148.351 1280 1296 1360 1650 720 722 728 750
ModeLine "ATSC-720-120p" 148.5 1280 1296 1360 1650 720 722 728 750
ModeLine "ATSC-1080-71.93i" 1920 1960 2016 2200 1080 1082 1088 1125 Interlace
ModeLine "ATSC-1080-72i" 1920 1960 2016 2200 1080 1082 1088 1125 Interlace
ModeLine "ATSC-1080-71.93p" 178.022 1920 1960 2016 2200 1080 1082 1088 1125
ModeLine "ATSC-1080-72p" 178.2 1920 1960 2016 2200 1080 1082 1088 1125

DTV-PCTweakedModes
ModeLine "NTSC-59.94i" 14.35 768 808 864 912 483 485 491 525 Interlace
ModeLine "NTSC-59.94p" 28.699 768 808 864 912 483 485 491 525
ModeLine "NTSC-DVD-59.94i" 13.469 720 760 816 856 480 482 488 525 Interlace
ModeLine "NTSC-DVD-60i" 13.482 720 760 816 856 480 482 488 525 Interlace
ModeLine "NTSC-DVD-59.94p" 26.937 720 760 816 856 480 482 488 525
ModeLine "NTSC-DVD-60p" 26.964 720 760 816 856 480 482 488 525
ModeLine "NTSC-DVD-71.93p" 32.324 720 760 816 856 480 482 488 525
ModeLine "NTSC-DVD-72p" 32.357 720 760 816 856 480 482 488 525
ModeLine "ATSC-480-59.94p" 23.916 640 664 736 760 480 482 488 525
ModeLine "ATSC-480-60p" 23.94 640 664 736 760 480 482 488 525
ModeLine "ATSC-480-71.93p" 28.699 640 664 736 760 480 482 488 525
ModeLine "ATSC-480-72p" 28.728 640 664 736 760 480 482 488 525
ModeLine "ATSC-720-59.94p" 74.086 1280 1320 1376 1648 720 722 728 750
ModeLine "ATSC-720-60p" 74.16 1280 1320 1376 1648 720 722 728 750
ModeLine "ATSC-720-71.93p" 88.903 1280 1320 1376 1648 720 722 728 750
ModeLine "ATSC-720-72p" 88.992 1280 1320 1376 1648 720 722 728 750
ModeLine "ATSC-1080-59.94i" 74.176 1920 1960 2016 2200 1080 1082 1088 1125 Interlace
ModeLine "ATSC-1080-60i" 74.25 1920 1960 2016 2200 1080 1082 1088 1125 Interlace
ModeLine "ATSC-1080-59.94p" 148.352 1920 1960 2016 2200 1080 1082 1088 1125
ModeLine "ATSC-1080-60p" 148.5 1920 1960 2016 2200 1080 1082 1088 1125
ModeLine "ATSC-1080-71.93p" 178.022 1920 1960 2016 2200 1080 1082 1088 1125
ModeLine "ATSC-1080-72p" 178.2 1920 1960 2016 2200 1080 1082 1088 1125

Others people have sent me
ModeLine "Pioneer 503/PDA5002 1280x768" 81 1280 1304 1440 1688 768 769 777 802
People will probably mostly want the DTV-PCTweakedModes, DTV-StandardModes, and DTV-MovieModes modelines. If you can get the DTV-MovieModes with 120 Hz refresh working then you're in very good shape for video quality. Also, you should use a p modeline and should never use an i modeline if you can help it.

Help for NVIDIA video card users

I have received many requests for a number of things dealing with NVIDIA cards. Most are dealing with tearing/overlay. You can only have one screen using overlay if you are running dual head. It's not that easy to get overlay working on the second aaptor, which is the dvi port, on NVIDIA cards. My configuration is based on Primers XFree86Config file. The link to my XF86Config-4 is here.