How to compile mplayer with vdpau support on Ubuntu

In February of 2009 I wrote an article on how to compile mplayer with vdpau support. Since then things have changed a little bit with mplayer and compiling mplayer with vdpau support has become a whole lot easier.

The biggest and most important thing is that mplayer has built in support for vdpau. You no longer need to use the patched version made available by nVidia.

Before we start compiling, you might want to know a bit more about it and if it’s something you want to do.

What is VDPAU?
WikiPedia defines it as follows:

VDPAU (Video Decode and Presentation API for Unix) is an API designed by NVIDIA for its GeForce 8 series and later GPU hardware, targeted at the X Window System on Unix operating-systems (including Linux, FreeBSD, and Solaris). The VDPAU API allows video programs to offload portions of the video decoding process and video post-processing to the GPU video-hardware. Currently, the portions designed to be offloaded by VDPAU onto the GPU are motion compensation (mo comp) and inverse discrete cosine transform (iDCT), and VLD (Variable-Length Decoding) for MPEG-1, MPEG-2, MPEG-4 AVC (H.264), VC-1, and WMV3/WMV9 encoded videos.

Great! What does it mean?
What it means that instead of using your processor is utilizes your graphics processor for certain decoding processes. This allows you to run other things when you are watching a video, the most known application that benefits from this is mythTV, you can use a less powerful processor to watch videos.

Why do I want it?
Well like I said, if you have a less powerful processor and you want to watch a DVD, movie on your computer this implementation makes it possible.

It says it is designed by nVidia, can I use it with other graphic cards?
Short answer, No. The API is designed specifically for nVidia graphic card, and then only for the GeForce 8 and higher.

Let’s start

First of all you’ll need to use the official nVidia graphics driver, not the one that comes with Ubuntu itself.
To download the latest driver go to this site. At the time I’m writing this, the latest version is 180.51. You’ll need to download the pkg1 version.

Install nVidia driver
To compile mplayer with VDPAU support we need to run the nVidia driver.
Install this driver follow the following steps.

  • Log off from your computer. Not restart but Logoff
  • Press Ctrl-Alt-1. Your on the console right now
  • Login like you normally would
  • Type:
    sudo su -

    And when asked for your password give your password

  • If you are running Gnome type:
    /etc/init.d/gdm stop

    If you are running KDE type:

    /etc/init.d/kdm stop
  • In order to install the driver we’ll need to install some software:
    apt-get install build-essential linux-headers-`uname -r`
  • Go to the directory where you downloaded the driver
  • Type: sh NVIDIA-Linux-x86-180.51-pkg1.run
  • Accept the license, no need to search the FTP site and let the installer modify the X configuration
  • Personally I always reboot after this
    reboot

Compiling mplayer
I download everything in /d1/software/mplayer

Get the latest version from the official mplayer site, you will have to download the version marked Subversion snapshot.
You will also need all the development files for mplayer, we can get those by using aptitude.
In order to compile mplayer you’ll also need two extra files, nVidia does provide them but for your convenience I tarred them up. You can find the download link in the sidebar of this blog under Local Downloads.

Prepare for configuration and compilation
Open a terminal.

cd /d1/software/mplayer
tar xf mplayer-checkout-snapshot.tar.bz2
tar xf vdpau_20090305.tar.gz
mv vdpau /usr/include/
sudo aptitude build-dep mplayer

Configuring, Compiling and Installing
I use the –target in my configure script to force mplayer to use this that specific target. For some reason the configure script doesn’t recognize I have a core2 processor. You can leave it out and mplayer will figure out what kind of processor you have.

cd mplayer-checkout-2009-05-29
./configure --enable-gui --disable-x264-lavc --disable-x264 --enable-vdpau --target=i686-linux --prefix=/usr --confdir=/etc/mplayer --mandir=/usr/share/man

As mentioned earlier, mplayer doesn’t recognize the core2 I have, so in order for the compilation to use core2 I modify the output created by the configuration script.
Skip this if you don’t have a core2 processor!

sed 's/i686/core2/g' config.mak > /tmp/config.mak
mv /tmp/config.mak config.mak

Now for the compilation and installation

make
sudo make install

That’s all, you should have mplayer with VDPAU capabilities.

In order for mplayer to use vdpa you will need to add the following lines to the mplayer configuration.

cd ~/.mplayer

Use your favorite text editor to modify or create the file config
Add the following lines

# Write your default config options here!
vo=vdpau,xv,
vc=ffh264vdpau,ffmpeg12vdpau,

And that’s it, you are all set.

How do you know if you are using the VDPAU capabilities?
Download a clip from here

  • Open mplayer from the menu
  • Open a terminal and type: top
  • Open the movie in mplayer and play it
  • Check top in the terminal, you should see gmplayer in the command column. This is the GUI version of mplayer. Check the %CPU column. Try to remember the approximate percentage.
  • Close mplayer
  • Open another terminal
  • Type: gmplayer
  • Open the movie in mplayer and play it
  • Check top in the terminal, you should see gmplayer in the command column. This is the GUI version of mplayer. Check the %CPU column.
  • If the percentages of CPU is lower while playing the movie started from the menu you are running VDPAU. Congrats.
    If the percentages are about the same something went wrong during the configuration/compilation steps I described

Putting it all together
I have put the above steps together in a small shell script, called do-it.sh. Whenever I want to update mplayer, I just run the script and “automatically” have the latest version.

#!/bin/bash
rm -rf mplayer-checkout*
curl http://www.mplayerhq.hu/MPlayer/releases/mplayer-checkout-snapshot.tar.bz2 -o mplayer-checkout-snapshot.tar.bz2 -v
tar xf mplayer-checkout-snapshot.tar.bz2
cd mplayer*
./configure --enable-gui --disable-x264-lavc --disable-x264 --enable-vdpau --target=i686-linux --prefix=/usr --confdir=/etc/mplayer --mandir=/usr/share/man
sed 's/i686/core2/g' config.mak > /tmp/config.mak
mv /tmp/config.mak config.mak
make
sudo make install
This article is filed under the category Ubuntu and has the following tags associated with it: , , , , , , , .
  • Zivago

    Compiling takes too long.. just add this repo:

    http://www.avenard.org/files/ubuntu-repos/

    • The repo is only for interpid.
      As for compilation taking to long: The whole process take about 6 minutes, from start to finish and you’ll end up with an mplayer that is optimized for your own computer.

    • Steve

      I have a fedora system. How do I get the mplayer build-dev files if I don’t have aptitude?

      • Peter

        I believe Fedora uses yum.

  • I wonder if people who use GeForce 8 series cards are really that low on processing specs… Probably not but a good tip anyway.

    • Most new machines are quite capable of playing HD videos without the VDPAU capability. Personally I never tried playing a 1080P video with or without vdpau, 720P is enough for me, but playing a 720p movie without VDPAU shoots my CPU up to around 60%. I have an Intel core 2 duo 2.50Ghz, if I run it with VDPAU the CPU is around 6%,

  • giacomo

    hi
    i’ve tried to use vdpau with my 9600m gt
    i was using NVIDIA-Linux-x86_64-185.18.10-pkg2.run driver
    and trying your guide with smplayer, i receive black screen without video, only audio.
    this “trick” is avaible only with 180 driver?

    thanks
    giacomo

    • In order for smplayer to work you will have to do the following:
      In smplayer Prefrences:
      General -> Video -> Output Driver -> Custom = vdpau, xv
      General -> General -> Folder for storing screenshots = Should be empty
      Advanced -> Options for MPlayer -> Options = -vc ffh264vdpau,ffmpeg12vdpau,
      Also use normal subtitle, not SSA/ASS

      That should make it work

  • Chris Lees

    drseergio: I have an Nvidia 8600, a Core 2 Duo 3GHz and a Blu-ray drive. Playing Blu-ray 1080p files pushes my CPU to 100% (of one core) and the video still isn’t silky smooth. So I will try compiling Mplayer with VDPAU and we’ll see how it goes!

    Anyone know if the VDPAU support works with newer cards like the GTX260? I’ve got my eye on one of those.

  • giacomo
  • sodagnu

    its such a rip off that they dont support older GPUs. marketing only!

  • larinux

    hi there!
    I did this”how to” and I’m afraid that it didn’t work for me. Or, more probably, I did something wrong.

    I installed the 185.19 nvidia driver and compiled mplayer accordingly to the “how to”. When I play a 720p movie without the config lines vo=vdpau,xv, vc=ffh264vdpau,ffmpeg12vdpau the CPU usage is arround 40%-60%. (I a have a intel dual core at 3Ghz). When I use the suggested config lines I get a bunch of “error while decoding frame” errors and these messages: “Too many audio packets in the buffer” and “FATAL: Could not initialize video filters (-vf) or video output (-vo).”.

    Any ideas?
    10x

  • Jeremy

    Great instructions! Nice work.. thanks!

  • Hi,

    I just want to ask you: Why disabling x264 ?

    Thanks in advance for your answer ! =)

    • You know what, I’m not really sure but my guess is that vdpau, which is a x264 decoder, conflicts with the standard x264 encoder.

  • https://bugs.launchpad.net/ubuntu/+source/mplayer/+bug/437039

    Sign in and click “Does this bug affect you?” / “Yes, it affects me.” to encourage ubuntu to build this feature in.

    Thanks for the writeup.

  • Mattias

    I added this repo :
    http://www.avenard.org/files/ubuntu-repos/

    At the time of writing it says it’s only for intrepid, it works just as well with jaunty.

    1080p is nice, and runs well on my hardware :
    NVIDIA GPU GeForce 8400 GS (G86)
    AMD Athlon(tm) 64 X2 Dual Core Processor 4200+

  • Stanza

    Has somebody tried already this https://help.ubuntu.com/community/RestrictedFormats/BluRayAndHDDVD about vdpau with Karmic?

  • mobrien118

    Too bad mencoder won’t encode using vdpau. I get an error message as described in http://www.nvnews.net/vbulletin/showthread.php?p=2164451

  • SmartiePants

    Nice guide. The manual installation of the vdpau-dev libs should be replaced with:
    `sudo apt-get install libvdpau-dev` which is available in the vdpau ppa for ubuntu.

    Note, the mplayer supplied in that PPA doesn’t work for me in 9.10 Karmic with the 190 driver.

  • funicorn

    I am not very familiar with these steps. But I compile mplayer svn version directly and the configure log shows mplayer already support vdpau video output and has the relevant vdpau codecs built. So I’m wondering what the difference is.

  • Jose Ibañez

    Great post!
    It’s work fine for me!
    Thanks a lot of!

  • This was included in the Ubuntu Karmic build in September 2009 (see previous launchpad.net link). So current versions of Ubuntu already have it built in.

    funicorn: The difference is these instructions are older than the version that already has vdpau support built in.