Yesterday I wrote about my foray into
using the proprietary NVidia Linux display driver on my
MythTV box to get better hardware acceleration. This initially meant using OpenGL for rendering of the MyhTV menus. The responsiveness of the menus was greatly improved; however, the
mythfrontend process continued to use around 70% of the CPU. This was surprising, especially considering that it's a Pentium 4 3.0 GHz CPU with HyperThreading. I determined that playback of the recordings and live programming was
not using the MPEG-2 acceleration present in the NVidia FX 5200 graphics card, which meant the MPEG-2 decoding was being performed entirely on the CPU. This resulted in a higher system load and arguably lower-quality output.
I found the XvMC section of the MythTV wiki describing how to use X-Video Motion Compensation (XvMC) to utilize hardware acceleration when decoding MPEG-2 video. It actually took me several hours to get XvMC working, but I'll summarize the effective steps below:
First, install the NVidia display driver for Linux. The x.org driver doesn't support XvMC, so there's no way around it. My previous post has information on how to do this.
First, set-up the /etc/X11/xorg.conf file for the NVidia driver. XvMC worked only when NVAGP was set to '1'. You find explanations of these options on the NVidia support site. The relevant section of my /etc/X11/xorg.conf follows:
Section "Device"
Identifier "Videocard0"
Driver "nvidia"
Option "NVAGP" "1"
Option "NoLogo" "True"
Option "RenderAccel" "True"
Option "XvmcUsesTextures" "True"
Option "UseEdidDpi" "False"
Option "DPI" "100 x 100"
Option "UseEvents" "False"
Option "DPMS" "False"
EndSection
Next, create or edit the file /etc/X11/XvMCConfig. Following are some shell commands that show my system setup:
[scott@eowyn lib]$ cd /usr/lib
[scott@eowyn lib]$ ll libXvMCNVIDIA*
-r--r--r-- 1 root root 152808 2008-03-31 08:47 libXvMCNVIDIA.a
lrwxrwxrwx 1 root root 23 2008-03-31 08:47 libXvMCNVIDIA_dynamic.so.1 -> libXvMCNVIDIA.so.169.12
-rwxr-xr-x 1 root root 139604 2008-03-31 08:47 libXvMCNVIDIA.so.169.12
[scott@eowyn lib]$ cat /etc/X11/XvMCConfig
libXvMCNVIDIA_dynamic.so.1
To confirm that XvMC is working in X Windows, start up X Windows (i.e. startx), create a shell window and run xdpyinfo to look for the XvMC info:
[scott@eowyn lib]$ xdpyinfo | grep XVideo
XVideo
XVideo-MotionCompensation
The next step is to instruct mythfrontend to use XvMC for playback. I did this by choosing a playback profile in the mythfrontend via the Setup -> TV Settings -> Playback menus. The CPU-- profile uses 'ivtv' for Standard Definition (SD) Television, and 'xvmc' for higher definition content. I'm only recording SD content right now, but would like to use 'xvmc' to lower the CPU load. So, I created a new playback profile that uses 'xvmc' for all content.
I'll also mention that the picture became skewed on my 16:9 Sony 32" flat-panel television. I corrected this by adding scaling values of X=2, Y=3 in the Setup -> TV Settings -> Playback menu. This shifted the picture left and down to fill the screen. I'm also using the DVI output of the NVidia FX 5200 card. I've got a DVI-to-HDMI cable that delivers a pure digital signal to the television. The clarity is phenomenal.
After making all of these changes, I was able to confirm that XvMC was in use simply by looking at the CPU utilization of the 'mythfrontend' process with 'top'. Before I enabled XvMC, CPU utilization was at 68-72% when playing video. After switching to XvMC, utilization is merely 18-20%. That's more than a 300% reduction in CPU utilization! Since I use the MythTV machine for the backend and frontend, the reduction in CPU utilization opens up the possibility of adding another encoder card, or running some additional services such as ZoneMinder.