AppleTV Video Setup

'''THIS PAGE IS WORK IN PROGRESS.. SORRY!'''

For the majority of users, the following settings will give great playback on their AppleTV:

[ pic will go here ]

Adjust Display Refresh Rate To Match Video
If set to OFF, XBMC will play media at XBMC's default refresh rate. This is probably 60.000Hz, the native rate of most LCD and Plasma screens. If set to "Always" or "On start/stop" XBMC will change refresh rate so the display rate matches the rate of the media; as long as the TV has a matching mode (in Xorg-speak, mode = refresh rate). The modes your TV supports are presented to Xorg by the nVidia driver at boot-time based on the drivers' interpretation of the EDID data from your TV's HDMI connection. If an exact mode match is not available XBMC will choose the next-best mode from the ones available. This is important, because if modes do not exactly match, or the media rate does not divide equally into the refresh rate of the TV, XBMC will need to perform "pull-up" corrections during playback to keep things in-sync. Depending on when they occur, corrections may be completely invisible, or very visible.

There is a long-standing "rounding" bug in the nVidia driver that often prevents it from offering a 23.976Hz refresh rate to Xorg, and 23.976Hz is the native rate for Blu-Ray media so it's one of the most common modes needed. In online forums it is often referred to as the "24p" playback mode, though most TV's also have a true 24.000Hz mode. If there is no 23.976Hz mode available XBMC will perform pull-up corrections during playback.

To see if your combination of AppleTV and TV are affected you can run the following SSH command:

DISPLAY=:0 /usr/lib/xbmc/xbmc-xrandr

The output of the command will look like this:

root ~ # DISPLAY=:0 /usr/lib/xbmc/xbmc-xrandr                 <mode id="0x1f3" name="1280x1024" w="1280" h="1024" hz="60.01974" current="false" preferred="false"/> <mode id="0x1f4" name="1280x720" w="1280" h="720" hz="60.00000" current="false" preferred="false"/> <mode id="0x1f5" name="1280x720" w="1280" h="720" hz="59.94343" current="false" preferred="false"/> <mode id="0x1f6" name="1280x720" w="1280" h="720" hz="50.00000" current="false" preferred="false"/> <mode id="0x1f7" name="1024x768" w="1024" h="768" hz="60.00384" current="false" preferred="false"/> <mode id="0x1f8" name="800x600" w="800" h="600" hz="60.31654" current="false" preferred="false"/> <mode id="0x1f9" name="720x576" w="720" h="576" hz="50.00000" current="false" preferred="false"/> <mode id="0x1fa" name="720x480" w="720" h="480" hz="59.94006" current="false" preferred="false"/> <mode id="0x1fb" name="640x480" w="640" h="480" hz="59.94048" current="false" preferred="false"/> <output name="DVI-I-1" connected="false">

Here we can see that the nearest mode to 23.976Hz is 23.97091Hz:

<mode id="0x1ed" name="1920x1080" w="1920" h="1080" hz="23.97091" current="false" preferred="false"/>

I know from reading the manual for my TV that it supports 23.976Hz playback, so this is the correct mode being incorrectly reported (rounded) by the nVidia driver. The solution is to create a custom xorg.conf the contains custom modelines with the correct values. I do this by copying the default file and then editing:

cp /etc/X11/xorg-nvidia.conf /storage/.config/xorg.conf vi /storage/.config/xorg.conf

I need to add a "Monitor" section, then add "Modes" information to the "Display" SubSection as per the example below:

Section "Device" Identifier    "nvidia" Driver        "nvidia" Option        "DynamicTwinView" "False" Option        "NoFlip" "false" Option        "NoLogo" "true" Option        "ConnectToAcpid" "0" Option        "FlatPanelProperties" "Scaling = Native" Option        "ModeValidation" "NoVesaModes, NoXServerModes" Option        "HWCursor" "false" Option        "ModeDebug" "false" EndSection

Section "Monitor" Identifier    "monitor" Option        "DPMS" Option        "ExactModeTimingsDVI" "true" ModeLine	  "1920x1080_24" 74.250 1920 2558 2602 2750 1080 1084 1089 1125 +hsync +vsync ModeLine	  "1920x1080_23.976" 74.175 1920 2558 2602 2750 1080 1084 1089 1125 +hsync +vsync EndSection

Section "Screen" Identifier    "screen" Device        "nvidia" Monitor	  "monitor" DefaultDepth   24 Option        "ColorRange" "Full" Option        "ColorSpace" "RGB" SubSection    "Display" Depth      24 Modes     "1920x1080_24" "1920x1080_23.976" EndSubSection EndSection

Section "Extensions" Option        "Composite" "false" EndSection

Once I have finished editing the file and rebooted to effect the changes, the xrandr command output looks like:

<screen id="0" minimum_w="8" minimum_h="8" current_w="1920" current_h="1080" maximum_w="4096" maximum_h="4096"> <output name="TV-0" connected="false"> <output name="HDMI-0" connected="true" w="1920" h="1080" x="0" y="0" wmm="160" hmm="90"> <mode id="0x1bd" name="1920x1080" w="1920" h="1080" hz="60.00000" current="false" preferred="true"/> <mode id="0x1be" name="1920x1080" w="1920" h="1080" hz="50.00000" current="true" preferred="false"/> <mode id="0x1bf" name="1920x1080" w="1920" h="1080" hz="29.96970" current="false" preferred="false"/> <mode id="0x1c0" name="1920x1080" w="1920" h="1080" hz="25.00000" current="false" preferred="false"/> <mode id="0x1c1" name="1920x1080" w="1920" h="1080" hz="24.00000" current="false" preferred="false"/> <mode id="0x1c2" name="1920x1080" w="1920" h="1080" hz="23.97576" current="false" preferred="false"/> <mode id="0x1c3" name="1920x1080" w="1920" h="1080" hz="59.93939" current="false" preferred="false"/> <mode id="0x1c4" name="1920x1080" w="1920" h="1080" hz="29.97172" current="false" preferred="false"/> <mode id="0x1c5" name="1920x1080" w="1920" h="1080" hz="23.97091" current="false" preferred="false"/> <mode id="0x1c6" name="1920x1080" w="1920" h="1080" hz="30.02669" current="false" preferred="false"/> <mode id="0x1c7" name="1920x1080" w="1920" h="1080" hz="29.99838" current="false" preferred="false"/> <mode id="0x1c8" name="1920x1080" w="1920" h="1080" hz="25.02224" current="false" preferred="false"/> <mode id="0x1c9" name="1280x720" w="1280" h="720" hz="60.00000" current="false" preferred="false"/> <mode id="0x1ca" name="1280x720" w="1280" h="720" hz="59.94343" current="false" preferred="false"/> <mode id="0x1cb" name="1280x720" w="1280" h="720" hz="50.00000" current="false" preferred="false"/> <mode id="0x1cc" name="720x576" w="720" h="576" hz="50.00000" current="false" preferred="false"/> <mode id="0x1cd" name="720x480" w="720" h="480" hz="59.94006" current="false" preferred="false"/> <mode id="0x1ce" name="640x480" w="640" h="480" hz="59.94048" current="false" preferred="false"/>

This shows I now have the following extra mode:

<mode id="0x1c2" name="1920x1080" w="1920" h="1080" hz="23.97576" current="false" preferred="false"/>

This is still not a 100% match for 23.976Hz, but 23.97576Hz is close enough to avoid pull-up corrections :)

Pause During Refresh Rate Change
The AppleTV is slow to make refresh rate changes. It's all about raw CPU speed and the AppleTV has a fairly slow (by modern standards) CPU. XBMC also contains some hacky workarounds for a few problems in the CrystalHD driver. XBMC must read ahead in the video stream to figure out the correct refresh rate, before changing to it. This can increase the number of packets dropped as playback starts and stabilises. Most users benefit from a 2-5 second pause value as this gives time for everything to buffer and settle before playback commences.

Changing XBMC's Default Refresh Rate
It is also good practice to understand the refresh rate of what you play most, and adjust XBMC's default to suit. For example; I have a large library of 25.000Hz content so XBMC is configured to use 50.000Hz as the default refresh rate. Because 25.000Hz * 2 = 50.000Hz, XBMC can simply render each frame twice instead of performing a slightly clunky mode change to 25.000Hz. If you mostly play Blu-Ray movies with a 23.976Hz refresh rate, you can set XBMC to use this mode as its default to minimise mode change activity.

The XBMC settings GUI currently displays the mode rounded up to 2 digits, so 23.976Hz is normally displayed as 23.98Hz. To make sure you select the correct mode, run the xrandr command again to check which is mode has "current=true" against it. In the example above this is:

<mode id="0x1be" name="1920x1080" w="1920" h="1080" hz="50.00000" current="true" preferred="false"/>

Sync Playback To Display
This should always be set of OFF because this instructs XBMC to drop either audio packets or video frames to keep a constant fps rate. Ultimately it takes CPU cycles to process the video stream and figure out which packets/frames to drop and it results in playback glitches.