Linux - HOW-TO achieve perfect playback at 23.97 or 59.94 Hz with NVIDIA GPU hardware

  Thread Rating:
  • 16 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
JumJum Offline
Senior Member
Posts: 138
Joined: Jun 2009
Reputation: 7
Thumbs Up  HOW-TO achieve perfect playback at 23.97 or 59.94 Hz with NVIDIA GPU hardware
Post: #1
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".)
Code:
for i in 24 60; do xrandr -r $i; nvidia-settings -q RefreshRate | grep -o "[0-9][0-9].*Hz"; done
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:
  1. Adding a proper xorg.conf
  2. Finding what modes the TV says it supports in it's EDID.
  3. Adding the wanted modes to xorg.conf so XBMC can use them.
  4. Adjusting the settings in NVIDIA's drivers.
  5. 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
and then running the script using:
Code:
sh nvidia.sh
Xorg will be restarted twice and your old settings will be backed up to the directory ~/old

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
1. Adding a proper xorg.conf
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"
Now your /etc/X11/xorg.conf should look like this:
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
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.
Code:
sudo service gdm restart
or if you are running XBMC Live:
Code:
sudo service xbmc-live stop
sudo service xbmc-live start
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:
Code:
sed -n '/- Modes/,/- End/p' /var/log/Xorg.0.log | sed 's/.*(0)://g' > $HOME/Desktop/modes.txt
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.
Code:
nano $HOME/Desktop/modes.txt
sudo nano /etc/X11/xorg.conf
The relevant part of my modes.txt looks like this:
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): ---
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:

Code:
Modes "1920x1080_60_0" "1920x1080_24_0"
Save and exit. Restart Xorg for the settings to take effect:
Code:
sudo service gdm restart
or if you are running XBMC Live:
Code:
sudo service xbmc-live stop
sudo service xbmc-live start
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)
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
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:
Code:
sudo cp $HOME/old/xorg.conf /etc/X11/xorg.conf
Your driver settings: (Not necessary if running XBMC Live)
Code:
cp $HOME/old/.nvidia-settings-rc $HOME; nvidia-settings -l
Your XBMC settings:
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>
Thanks to X3lectric and bobo1on1 for pointing this out.
(This post was last modified: 2012-11-22 13:55 by FernetMenta.)
find quote
finite3 Offline
Member
Posts: 51
Joined: Aug 2008
Reputation: 0
Post: #2
Thanks - for reference sake, the script ran just fine under xbmcfreak v11 live.
find quote
Ayla Offline
Fan
Posts: 597
Joined: Feb 2008
Reputation: 0
Post: #3
Thanks...

In the other thread recovered, it says that: ""Sync playback to display" to On, A/V sync method to "Audio"" should be OFF, because it speeds up 23.976 to 24.000.

Here it says it should be ON.

What is the correct way to do it?
find quote
JumJum Offline
Senior Member
Posts: 138
Joined: Jun 2009
Reputation: 7
Post: #4
Ayla Wrote:Thanks...

In the other thread recovered, it says that: ""Sync playback to display" to On, A/V sync method to "Audio"" should be OFF, because it speeds up 23.976 to 24.000.

Here it says it should be ON.

What is the correct way to do it?

That was incorrect information. It does not speed up the video at all.
This is the correct way to do it.
find quote
Ayla Offline
Fan
Posts: 597
Joined: Feb 2008
Reputation: 0
Post: #5
Thanks for that, I will try it when I get home!

The only problem I have is, that I need to set a sound delay of 200ms for all my movies to be in sync, but when I save it with "Set as default for all movies", it only lasts until XBMC restarts... then it forgets the 200ms delay setting and resets it to zero.

Anyone else experiencing that?

PS. I only need the 200ms delay for 23.976hz movies (not 50hz videos). That's a bit strange!?
find quote
Ayla Offline
Fan
Posts: 597
Joined: Feb 2008
Reputation: 0
Post: #6
Another problem I have is that sometimes XBMC doesn't switch back to 1080p@60hz resolution when I stop a movie.

I always use 1080p@60hz when browsing in XBMC and when I start a 23.976hz movie, the resolution switches like it should to 1080p@24hz.

Then I press Stop and return to the menu and once in a while XBMC stays in 1080p@24hz instead of switching back to 1080p@60hz.

This is rather annoying as I have to go to Settings and switch back to 1080p@60hz manually every time.

Anyone else experiencing this or have a solution?

Thanks Smile
find quote
JumJum Offline
Senior Member
Posts: 138
Joined: Jun 2009
Reputation: 7
Post: #7
Ayla Wrote:Thanks for that, I will try it when I get home!

The only problem I have is, that I need to set a sound delay of 200ms for all my movies to be in sync, but when I save it with "Set as default for all movies", it only lasts until XBMC restarts... then it forgets the 200ms delay setting and resets it to zero.

Anyone else experiencing that?

PS. I only need the 200ms delay for 23.976hz movies (not 50hz videos). That's a bit strange!?

Works fine here.

You can check if it's saved at all with:
Code:
grep audiodelay ~/.xbmc/userdata/guisettings.xml

Also, make a backup of guisettings.xml and see if the problem still exists after xbmc creates a fresh one. I once had a similar issue but with screen calibration settings.

Create a new thread for this issue if that doesn't work.
find quote
bobo1on1 Offline
cheapass Team-XBMC Developer
Posts: 2,758
Joined: Dec 2008
Reputation: 22
Post: #8
Ayla Wrote:Another problem I have is that sometimes XBMC doesn't switch back to 1080p@60hz resolution when I stop a movie.

I always use 1080p@60hz when browsing in XBMC and when I start a 23.976hz movie, the resolution switches like it should to 1080p@24hz.

Then I press Stop and return to the menu and once in a while XBMC stays in 1080p@24hz instead of switching back to 1080p@60hz.

This is rather annoying as I have to go to Settings and switch back to 1080p@60hz manually every time.

Anyone else experiencing this or have a solution?

Thanks Smile

What revision are you running?
find quote
Ayla Offline
Fan
Posts: 597
Joined: Feb 2008
Reputation: 0
Post: #9
bobo1on1 Wrote:What revision are you running?

I'm using the latest "safe" build, r28256.
find quote
coupas Offline
Member
Posts: 80
Joined: Jan 2010
Reputation: 33
Post: #10
I just wanted to say thanks for this post. It saved me a lot of time and everything works pretty good for me now. Not perfect, but good enough.

Thanks!
find quote
sonic Offline
Senior Member
Posts: 103
Joined: May 2004
Reputation: 0
Post: #11
Nice script!. I get this error when running the script on my newly installed system. Anyone who can help me fix it?, because nvidia-settings --help doesnt help me much Sad . I can add that I am new to linux.

5/6 Applying NVIDIA settings
No protocol specified

ERROR: The control display is undefined; please run `nvidia-settings --help`
for usage information.

No protocol specified

ERROR: The control display is undefined; please run `nvidia-settings --help`
for usage information.


EDIT: Hmmm everything seems to be working as it should, even with the error Smile.
(This post was last modified: 2010-03-18 20:36 by sonic.)
find quote
JumJum Offline
Senior Member
Posts: 138
Joined: Jun 2009
Reputation: 7
Post: #12
sonic Wrote:Nice script!. I get this error when running the script on my newly installed system. Anyone who can help me fix it?, because nvidia-settings --help doesnt help me much Sad . I can add that I am new to linux.

5/6 Applying NVIDIA settings
No protocol specified

ERROR: The control display is undefined; please run `nvidia-settings --help`
for usage information.

No protocol specified

ERROR: The control display is undefined; please run `nvidia-settings --help`
for usage information.


EDIT: Hmmm everything seems to be working as it should, even with the error Smile.

This part is acctually not needed if you have a newly installed system, so you're good!
find quote
Matija Offline
Junior Member
Posts: 12
Joined: Jan 2009
Reputation: 0
Post: #13
Just a short question. I have problems with video jutter and tear and a lot people say it's due to xorg.conf, would your solution solve this?

Thank you in advance.
find quote
johnskiller Offline
Junior Member
Posts: 3
Joined: Mar 2010
Reputation: 0
Post: #14
which refresh rate should I use for 29.97 movie? 1920x1080_30 or 1920x1080_0? Also if my tv support 25Hz, should I use it instead of 50Hz for some PAL TV show?

I have a movie that has lots of jutter and tear when use 24Hz, but played well when use 60Hz. the movie is 24p(or 23.97, not sure), any idear?
find quote
Matija Offline
Junior Member
Posts: 12
Joined: Jan 2009
Reputation: 0
Post: #15
Matija Wrote:Just a short question. I have problems with video jutter and tear and a lot people say it's due to xorg.conf, would your solution solve this?

Thank you in advance.

Sorted by using your script! Worked awesome, thanks again!
find quote
Post Reply