Nepherte (dot) be

Comprehensive MPlayer Guide II: Installation

This article is the follow up of Comprehensive MPlayer Guide I: Introduction.

To acquire a good MPlayer setup, you really don’t want to install the version packaged by your favorite distribution. The mainstream linux distributions like Ubuntu use “the latest” but very dated release of MPlayer. Their latest release,  v1.0rc2, dates from 7 October 2007. Go figure!  That doesn’t mean MPlayer isn’t actively being developed though. You see, the MPlayer developers believe in making continuous changes to their latest development version, generally referred to as the SVN version, rather than releasion official versions. This SVN version is 99% of the time stable, no need to worry there. Unfortunately, you will have to build it yourself. I will try to guide you through this rather lengthy process.

The build process consists of 3 main steps:

  • Install x264
  • Install useful multimedia libraries and FFMPEG
  • Install MPlayer

Part I: x264
x264 is necessary for encoding videos in the  MPEG 4 AVC (H264/x264) codec. At the moment of writing this codec is one of the best and most popular codecs used (e.g. Blu-Ray) and undispensible if you intend to do some encoding. Before we continue, make sure you have the necessary build tools like make. They are usually bundled by your distribution in a general “build” package. Ubuntu, for example, has put everything in build-essential. Consult your distribution’s documentation to figure out what packages you need to build software.

x264 depends on the following packages:

  • libx11
  • gpac (optional).

The packages git, yasm and gettext are necessary for building x264. Technically you can remove the build dependencies after the x264 installation is completed but you will need them so often you might as well leave them installed. The installation of x264 goes as follows:

Get the sources:

git clone git://git.videolan.org/x264.git

Configure x264:

cd x264/
./configure --prefix=/usr --enable-visualize --enable-shared --enable-pic --enable-mp4-output

You don’t need to worry much about these configuration options but I’ll briefly explain them. prefix= determines where the final build of x264 will reside. /usr is generally a good option. If prefix is not specified it will default to /usr/local/. enable-shared allows other programs to access this x264 build. This is something we really need. enable-mp4-output makes sure that we can save media files with the x264 codec to mp4 files. mp4-output requires you installed gpac. If you didn’t, remove this option from the ./configure line. enable-visualize speaks for itself. enable-pic builds position-independent code. You can get more info on the available configuration options with ./configure –help (that’s two ‘-’ in case you are wondering).

Build and install x264:

make && sudo make install

You can verify that x264 is correctly installed by typing  x264 –version (again, two ‘-’). You might have encountered a build error during the installation process. Therefore I advise you to always carefully read the output generated by ./configure and make. Errors are usually printed at the end of the output. There is no point in continuing with another step/command if you have an error. Errors often occur because you overlooked a required dependency.

Part II: Install useful multimedia libraries and FFMPEG
To get a working MPlayer setup you technically don’t have to perform this step because the svn server of MPlayer already holds the necessary ffmpeg and other libraries. The main disadvantage of using a built-in ffmpeg is that MPlayer and MPlayer only can make use of it. This means that if another program requires ffmpeg, you will have to install it again which leads to a lot of duplicate ffmpegs. An advantage of having a built-in ffmpeg over a separate one is that the mplayer devs often add some optimizations to their ffmpeg branch that are not availabe in the official branch. The mplayer devs recommend using their branch (stating the obvious I suppose), I’ll explain both methods. If you prefer a built-in ffmpeg, skip this section. Still here? Libraries that I recommend to install for a separate ffmpeg, are:

  • subversion, imlib2- build requirements for ffmpeg
  • xvidcore – Support for xvid codec
  • faad2 and faac - for AAC decoding and encoding
  • smbclient – for network files playback
  • lame – for mp3 encoding
  • libtheora, libvorbis, speex – support for the open source theora, vorbis and speech codec
  • zlib – support for compression

Some less commonly used optional features for ffmpeg:

  • sdlif you want ffmpeg to be able to play video files
  • gsm – another lossy speech compression codec
  • dirac or libschroedinger – video compression codec
  • amrnb, amrwb – adaptive amr narrow and wide band speech codec

Try to install them with the package management installer that comes with your distribution but I suggest you check the repository version of a library with the latest version.

Now let’s continue with FFMPEG. FFMPEG and MPlayer are practically twins, they go hand in hand with eachother. FFMPEG provides MPlayer with the most important tools to play multimedia: the common and not so common codecs for playback and encoding, (de)muxers for opening containers like mp4 and avi, filters and post processors.

Get the source:

svn co svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg

Compile it:

cd ffmpeg/
./configure --prefix=/usr --enable-gpl --enable-libmp3lame --enable-libvorbis --enable-libfaac --enable-xvid --enable-x264 --enable-libtheora --enable-libspeex --enable-postproc --enable-avfilter --enable-avfilter-lavf --enable-shared --enable-network --enable-pthreads --enable-x11grab --arch=`uname -m`

If you didn’t install all the packages from above, simply remove the corresponding configure option. If you  installed something out of the list of less commonly used libraries, add the corresponding option to the ./configure line. Remember to check ./configure –help for more information on the configuration options. After the ./configure [...] command, a nice layout with all the supported codecs and much more will be printed.

Build and install it:

make && sudo make install

Et voilà. You should have a working ffmpeg. FFMPEG includes a player (if you installed sdl, that is) so you can verify that you installed it successfully by playing a media file. This is how you do it: ffplay <path to video file>. I will remind you here again that you may have encountered a build error during the installation process. Therefore I advise you to always carefully read the output generated by ./configure and make. Errors are usually printed at the end of the output. There is no point in continuing with another step/command if you have an error. Errors often occur because you overlooked a required dependency.

Part III: Install MPlayer
Now we can finally move on to installing MPlayer. Some additional packages you could install:

  • freetype, fribidi, aalib – for unicode and ascii support (subtitles)
  • live555 support for streaming
  • libmpcdec for musepack
  • twolame or toolame – for optimized mpeg layer 2 encoding (twolame excludes toolame and vice versa)
  • openal, opengl, libxmvc, libxv, directfb, libpng, libjpeg – for more video and audio outputs .

They’re all optional dependencies but they increase the capabilities of MPlayer a lot so there’s no reason not the install them.

Get the sources:

svn co svn://svn.mplayerhq.hu/mplayer/trunk mplayer

Patch MPlayer so it can disable the gnome-screensaver as well. There are patches for KDE as well, but I use GNOME:

wget http://www.nepherte.be/files/mplayer-svn-gnome-screensaver.patch
cd mplayer
patch -p1 ../mplayer-svn-gnome-screensaver.patch

The configure script of MPlayer incorporates a sort of auto-detection. It will check for a certain library/feature where it is normally located and afterwards it will set everything correct to use that feature. It is therefore recommended not to force or –enable an option in the ./configure line as it breaks the path detection of that feature.

Configure MPlayer with built-in (static) ffmpeg:

./configure --prefix=/usr --confdir=/etc/mplayer --disable-gui --enable-menu --enable-runtime-cpudetection --enable-largefiles

Configure MPlayer without built-in (shared) ffmpeg:

./configure --prefix=/usr --confdir=/etc/mplayer --disable-gui --enable-menu --enable-runtime-cpudetection --enable-largefiles --disable-libavutil_a --disable-libavcodec_a --disable-libavformat_a --disable-libpostproc_a --disable-libswscale_a

I explicitely disabled the built-in gui because there are a lot better guis available. I’ll deal with this in Comprehensive MPlayer Guide III. The configure options that end with _a disable the built-in ffmpeg. The rest is pretty self-explanatory. You can save some space and compilation time by disabling unneeded features. Things I usually disable, are:

--disable-inet6  --disable-tv  --disable-radio  --disable-ossaudio --disable-jack --disable-esd --disable-lirc --disable-dvb

More information on the configure options can be found by executing ./configure –help.

Now build and install MPlayer:

make && sudo make install

Again check the outputs of each command for errors. You can verify that mplayer is installed correctly with the command mplayer <path to video file>. As mentioned before, I’ll deal with the good guis for MPlayer in the next article.

If you come across an error during one of the installs and you can’t figure out how to fix them, drop a note and I’ll try to help out wherever possible.

The follow up, Comprehensive Guide III: Video Playback & Desktop Integration, will soon be available.

Leave a Reply