Video Card Configuration

Disclaimer reminder

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

Introduction into 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/image is drawn per second. Standard U.S. TV refresh rates are 59.94 odd+even interlaced screens/cycles per second (Hz). Each time a frame is drawn on a TV, every other line gets drawn each refresh. This is because the first TV's made could not draw every line on a screen fast enough and the phosphor that would light up would fade before it was redrawn (Or would stay lit too long and make the picture look too bright where the next frame were dark), this has been since improved in TV's. Interlaced TV was created to get around this problem, so TV refresh is also refered to as 29.97 interlaced (meaning it gets 29.97 Full frames are drawn per second). Progressive video came when screens could hold their image long enough that the whole screen could be redrawn before the phosphor faded and phosphors faded quickly at the right time. Because TV signals were all sent interlaced, progressive would not catch on until a new way of broadcasting came about, such as DTV. Film (In movie theaters) is 24 Hz (Progressive). DVD players handle many refresh rates such as 23.976, 24, 25, and 29.97Hz interlaced and non-interlaced and have an output for interlaced, and sometimes progressive video. HDTV standards include 24, 25, 29.97, 30, 50, 59.94, and 60 Hz and can be interlaced and non-interlaced. The reason for so many different refresh rates is because of ugly backwards compatibility issues.

Walt R. mailed me with some good history to help explain things.

If I remember right the refresh rate on a black&white
televixion was 60 HZ.  Changing it to 59.??HZ had to do
with the color burst add on to NTSC.  I think the horizontal
oscillator was changed to 15749.??
                                                                                                                    
In the color TV CRT the three cathodes are tied together
and controlled with the luminamce signal for brightness
and contrast of the black and picture, and the control
grids control the color component of the NTSC picture.
                                                                                                                    
The horizontal oscillator in a B&W TV =15750HZ
                                                                                                                    
refresh rate = 60 HZ =30HZ Frame Rate
                                                                                                                    
15750 / 30 = 525 Lines of Horizontal Resolution
                                                                                                                    
The "color killer" circuit in the color TV turned off the color
to prevent the confetti "color snow" and the problem of
pink and purple vice black&white picture in the 1970's
color TVs.

A sad fact, is many HDTV's are interlaced because it's cheaper to make them. The highest resolution HDTV signal is 1920x1080 interlaced, so really 1920x540. The reason for this was that 1920x1080 was "too much" bandwidth for broadcasters to use. 1080i (1920x1080) is 19.6Mb/s, 720p (The highest resolution progressive stream at 1440x720) is about 14Mb/s. Some HDTV's do support 1080p (about 27Mb/s .. not double because audio is in that stream) and hopefully one day we'll see people broadcasting 1080p, but that will require the DTV specs to be modified to include it.

As for if interlaced or progressive is better, it depends on what you're watching. If it's fast motion then 720p (full/progressive) frames will look better. If it's a static picture (not moving) then interlaced means little and will look more detailed. Mostly all sports are 720p and nature shows are 1080i, everything else is just what gets picked.

With modern technology like DVD players or HDTV's, 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.

When you introduce a video card into this area you complicate things a bit more. On some video cards you don't know if or when video frames were drawn or missed. This makes it hard to produce smooth video using a computer. In early 2004, support was added for NVidia cards in MythTV so that it knows if a frame had been drawn or not. Although not as perfect as pulldown, code was added to find out if you need to insert or drop a frame from being displayed in real time. This has greatly improved how smooth video is inside of MythTV, but this doesn't help with DVD's since MythTV opens a program like MPlayer or Xine for DVD playback (Although these program do something similar, but note yet as good). What this helps with is if you can't match your TV refresh perfectly with your video card refresh (Which is near impossible as you're probably learning) video will still look smooth and you probably won't even notice jitter.

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. (The closer your video card refresh to your display refresh the less jitter you will have)

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. If you can find it, your TV has one permanent refresh rate and it modifies any other ones it gets to that. Finding this refresh rate may not always be easy, but it's what you need to find and then set your video card to as close to that as possible. 120 Hz is usually the "best all around" since 120/24frames=5 and 120/30frames=4 which means that without doing pulldown, your frames will be displayed with little jitter without the help of special code. If you can't run at 120, don't worry, you probably won't even notice it much (If you have an NVida card) and some people may just opt to ignore figuring the refresh stuff out to save time. If you do not want to spend too much time here, pick 72 or 60 if you can and you'll be fairly close.

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. First just adjust the projector so you you only have the top part of X showing on your 16:9 screen and setup programs so they display in that geometry (This works very well and is what I do now). Most projectors can also take signals such as 1024x576, even if your manual doesn't say it is supported (Mine did for VGA, but not DVI, hence why I do the former now that I use DVI). You can find out what a HDTV ratio resolution by doing the following.

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 and a "good" config file to work from. For tearing/multihead, you can only have one screen using overlay if you are running dual head. I took some time and now have a new XF86Config file that makes it easy to pick which head gets overlay. My configuration is based on Primers XFree86Config file. The link to my XF86Config-4 is here. If someone is able to make this even more generic (Such as put support for the TV-out into this) send it back. I'll try to keep this as HTPC optimized as possible.

Next Page