2010-03-17, 16:12
OUTDATED with NVidia driver 302.17!!!!!
(It has support for xrandr 1.2/1.3 and can distinguish between 23.976 and 24)
Howto achieve judder free perfectly synced playback.
Since there's a lot of misinformation in the forum about how xorg display modes works, I though I'd post a howto and explain how to do it the (in my opinion) right way.
First of all, modelines are not a the magic solution to all your problems. Modelines are only needed with tv's that have faulty EDID information. Most TVs provide the correct modes for 29.97/59.94 Hz, but the modes are not used by xrandr by default, so XBMC can't see that they are available.
To check how ~24 and ~60 Hz modes are currently handled on your setup you can run the following command:
(XBMC Live doesn't have libgtk, which is required by nvidia-settings. Either check the refresh inside XBMC instead by pausing a video and pressing "o", or run "sudo apt-get install libgtk2.0-0".)
The command will print the actual refresh rates used when switching the way XBMC does. Most setups will show 24 and 60 Hz instead of the wanted 23.97 and 59.94 Hz. You can run the command again after step 3 to check the difference.
The steps needed to set everything up are:
Automatic installation
All the steps can be performed automatically by dropping to a shell by pressing CTRL-ALT-F1 and running this script either by using copy & paste to an empty file
or by downloading it using:
and then running the script using:
Xorg will be restarted twice and your old settings will be backed up to the directory ~/old
The script has been tested on
If you don't trust my bash scripting skills. (Nobody's perfect... ) Here's how to do it step by step:
Manual installation
Backing up your current settings
1. Adding a proper xorg.conf
Now your /etc/X11/xorg.conf should look like this:
The XBMC forum contains a lot of posts with messy xorg.conf settings, using options that are enabled by default, deprecated or unrelated to video playback.
This is all that is needed. Don't use options you don't understand! Explanations to all the options can be found in the NVIDIA drivers manual.
The ModeDebug option makes the nvidia driver print all the available modes to Xorg's log file.
2. Finding what modes the TV says it supports in it's EDID.
Now that ModeDebug is enabled Xorg needs to be restarted so the available modes will be written to the log file.
Hook up your HDMI cable and restart Xorg.
or if you are running XBMC Live:
When Xorg is up and running again, bring up a terminal and run the following command to Parse Xorg's log file and output a text file with all the available modes on your desktop:
3. Adding the wanted modes to xorg.conf so XBMC can use them.
Open up modes.txt and /etc/X11/xorg.conf in your favourite editor.
The relevant part of my modes.txt looks like this:
If you don't have any 23.97 or 59.94 modes here, that's when you need to use modelines instead! Use the test command in the beginning of the post to see if your modelines work as expected. Then continue with step 4.
My TV supports both both 60 and 59.94 Hz. The left column is the name of the mode. As you can see both modes have names that start with "1920x1080_60". Since xrandr can't have two ~60 Hz modes available at the same time, we need to tell it to use the 59.94 Hz mode when switching to a ~60 Hz refresh rate. Same needs to be done with the ~24 Hz mode.
The two modes I want are called "1920x1080_60_0" and "1920x1080_24_0" since they provide the correct refresh rates. To enable these, paste the names of the modes to the Modes-line of /etc/X11/xorg.conf replacing the current setting. The first mode on the line will be your default mode. In my case it looks like this when done:
Save and exit. Restart Xorg for the settings to take effect:
or if you are running XBMC Live:
4. Adjusting the settings in NVIDIA's drivers.
To enable all the right and disable all the wrong options in the drivers you can run this command: (Not needed on XBMC Live)
All these options are available though the gui of nvidia-settings aswell.
5. Adjusting the settings in XBMC.
In XBMC you want to set "Render method" to Auto, "Use pixel buffer objects" to On, "Adjust display refresh..." to On, "Sync playback to display" to On, A/V sync method to "Audio" and "Vertical blank sync" to Always.
Voila, XBMC now automatically switches between 23.97, 50, and 59.94 Hz for 23.97, 25 and 29.97 FPS content respectively.
Two settings that you might want to try if you run into trouble is setting "Sync playback to display" to Off in XBMC and/or change NoFlip to "false" in /etc/X11/xorg.conf.
Restoring your previous settings
Your Xorg settings:
Your driver settings: (Not necessary if running XBMC Live)
Your XBMC settings:
Forcing target refresh rates for ranges of source fps
advancedsettings.xml
Thanks to X3lectric and bobo1on1 for pointing this out.
(It has support for xrandr 1.2/1.3 and can distinguish between 23.976 and 24)
Howto achieve judder free perfectly synced playback.
Since there's a lot of misinformation in the forum about how xorg display modes works, I though I'd post a howto and explain how to do it the (in my opinion) right way.
First of all, modelines are not a the magic solution to all your problems. Modelines are only needed with tv's that have faulty EDID information. Most TVs provide the correct modes for 29.97/59.94 Hz, but the modes are not used by xrandr by default, so XBMC can't see that they are available.
To check how ~24 and ~60 Hz modes are currently handled on your setup you can run the following command:
(XBMC Live doesn't have libgtk, which is required by nvidia-settings. Either check the refresh inside XBMC instead by pausing a video and pressing "o", or run "sudo apt-get install libgtk2.0-0".)
Code:
for i in 24 60; do xrandr -r $i; nvidia-settings -q RefreshRate | grep -o "[0-9][0-9].*Hz"; done
The steps needed to set everything up are:
- Adding a proper xorg.conf
- Finding what modes the TV says it supports in it's EDID.
- Adding the wanted modes to xorg.conf so XBMC can use them.
- Adjusting the settings in NVIDIA's drivers.
- Adjusting the settings in XBMC.
Automatic installation
All the steps can be performed automatically by dropping to a shell by pressing CTRL-ALT-F1 and running this script either by using copy & paste to an empty file
or by downloading it using:
Code:
curl "http://pastebin.com/download.php?i=bU1QFQ3c" | tr -d \\r > nvidia.sh
Code:
sh nvidia.sh
The script has been tested on
- Ubuntu 9.10
- Xubuntu 9.10
- Ubuntu 10.04 Alpha 3
- XBMC Live 9.11 LiveCD
- XBMC Live 9.11 (installed on a USB stick)
If you don't trust my bash scripting skills. (Nobody's perfect... ) Here's how to do it step by step:
Manual installation
Backing up your current settings
Code:
mkdir $HOME/old; cp /etc/X11/xorg.conf $HOME/.nvidia-settings-rc $HOME/.xbmc/userdata/guisettings.xml $HOME/old 2>/dev/null
Code:
wget "http://pastebin.com/download.php?i=5xAKDHNi" -O ~/nvidia-xorg.conf
sudo bash -c "tr -d \\r < ~/nvidia-xorg.conf > /etc/X11/xorg.conf"
Code:
Section "Device"
Identifier "nvidia"
Driver "nvidia"
Option "NoLogo" "true"
Option "DynamicTwinView" "false"
Option "NoFlip" "false"
Option "FlatPanelProperties" "Scaling = Native"
Option "ModeValidation" "NoVesaModes, NoXServerModes"
Option "UseDisplayDevice" "DFP-1"
Option "ModeDebug" "true"
Option "HWCursor" "false"
EndSection
Section "Screen"
Identifier "screen"
Device "nvidia"
SubSection "Display"
Modes "1920x1080_60"
EndSubSection
EndSection
Section "Extensions"
Option "Composite" "false"
EndSection
This is all that is needed. Don't use options you don't understand! Explanations to all the options can be found in the NVIDIA drivers manual.
The ModeDebug option makes the nvidia driver print all the available modes to Xorg's log file.
2. Finding what modes the TV says it supports in it's EDID.
Now that ModeDebug is enabled Xorg needs to be restarted so the available modes will be written to the log file.
Hook up your HDMI cable and restart Xorg.
Code:
sudo service gdm restart
Code:
sudo service xbmc-live stop
sudo service xbmc-live start
Code:
sed -n '/- Modes/,/- End/p' /var/log/Xorg.0.log | sed 's/.*(0)://g' > $HOME/Desktop/modes.txt
Open up modes.txt and /etc/X11/xorg.conf in your favourite editor.
Code:
nano $HOME/Desktop/modes.txt
sudo nano /etc/X11/xorg.conf
Code:
--- Modes in ModePool for Philips FTV (DFP-1) ---
"nvidia-auto-select" : 1920 x 1080 @ 60.0 Hz (from: EDID)
"1920x1080" : 1920 x 1080 @ 60.0 Hz (from: EDID)
"1920x1080_60" : 1920 x 1080 @ 60.0 Hz (from: EDID)
"1920x1080_60_0" : 1920 x 1080 @ 59.94/60 Hz (CEA-861B Format 16) (from: EDID)
"1920x1080_50" : 1920 x 1080 @ 50.0 Hz (from: EDID)
"1920x1080_30" : 1920 x 1080 @ 29.97/30 Hz (CEA-861B Format 34) (from: EDID)
"1920x1080_25" : 1920 x 1080 @ 25 Hz (CEA-861B Format 33) (from: EDID)
"1920x1080_24" : 1920 x 1080 @ 24.0 Hz (from: EDID)
"1920x1080_24_0" : 1920 x 1080 @ 23.97/24 Hz (CEA-861B Format 32) (from: EDID)
"1920x1080_60i" : 1920 x 1080 @ 59.94/60 Hz (CEA-861B Format 5) (from: EDID)
"1920x1080_50i" : 1920 x 1080 @ 50 Hz Interlace (CEA-861B Format 20) (from: EDID)
--- End of ModePool for Philips FTV (DFP-1): ---
My TV supports both both 60 and 59.94 Hz. The left column is the name of the mode. As you can see both modes have names that start with "1920x1080_60". Since xrandr can't have two ~60 Hz modes available at the same time, we need to tell it to use the 59.94 Hz mode when switching to a ~60 Hz refresh rate. Same needs to be done with the ~24 Hz mode.
The two modes I want are called "1920x1080_60_0" and "1920x1080_24_0" since they provide the correct refresh rates. To enable these, paste the names of the modes to the Modes-line of /etc/X11/xorg.conf replacing the current setting. The first mode on the line will be your default mode. In my case it looks like this when done:
Code:
Modes "1920x1080_60_0" "1920x1080_24_0"
Code:
sudo service gdm restart
Code:
sudo service xbmc-live stop
sudo service xbmc-live start
To enable all the right and disable all the wrong options in the drivers you can run this command: (Not needed on XBMC Live)
Code:
export DISPLAY=:0; nvidia-settings -a "SyncToVBlank=1" -a "AllowFlipping=1" -a "FSAAAppControlled=1" -a "OpenGLImageSettings=3" -a "LogAniso=0" -a "GPUScaling[DFP-1]=1,1"; nvidia-settings -r
5. Adjusting the settings in XBMC.
In XBMC you want to set "Render method" to Auto, "Use pixel buffer objects" to On, "Adjust display refresh..." to On, "Sync playback to display" to On, A/V sync method to "Audio" and "Vertical blank sync" to Always.
Voila, XBMC now automatically switches between 23.97, 50, and 59.94 Hz for 23.97, 25 and 29.97 FPS content respectively.
Two settings that you might want to try if you run into trouble is setting "Sync playback to display" to Off in XBMC and/or change NoFlip to "false" in /etc/X11/xorg.conf.
Restoring your previous settings
Your Xorg settings:
Code:
sudo cp $HOME/old/xorg.conf /etc/X11/xorg.conf
Code:
cp $HOME/old/.nvidia-settings-rc $HOME; nvidia-settings -l
Code:
cp $HOME/old/guisettings.xml $HOME/.xbmc/userdata
Forcing target refresh rates for ranges of source fps
advancedsettings.xml
Code:
<advancedsettings>
<video>
<adjustrefreshrate>
<override>
<fpsmin>29.96</fpsmin>
<fpsmax>30.01</fpsmax>
<refresh>60</refresh>
</override>
<override>
<fpsmin>23.96</fpsmin>
<fpsmax>24.01</fpsmax>
<refresh>24</refresh>
</override>
<override>
<fpsmin>24.99</fpsmin>
<fpsmax>25.01</fpsmax>
<refresh>25</refresh>
</override>
</adjustrefreshrate>
</video>
</advancedsettings>