Compile MPlayer with shared libraries

If you want to compile MPlayer (the command-line player behind MPlayerOSX), there are two ways to go at it. MPlayer depends on various libraries and you can compile a version linked to the libraries installed on your system (shared) or put the libraries into one self-contained binary (static).

The first one, especially on OSX, is a lot easier to do and thanks to projects like MacPorts, a lot of it is automated. You won't, however, be able to distribute the resulting binary since it depends on the libraries on your system and anyone who'd want to run it needs to have the same libraries installed at the same locations, which is rarely the case.

1. Dependencies

Most of the hot stuff is done in the Terminal. You can find it in Applications > Utilities > Terminal.

To compile anything on OSX, the Developer Tools are required. The current version (3.0) can be found on the Leopard install dvd or downloaded from Apple (registration required):
http://developer.apple.com/tools/download/

The various dependencies of MPlayer can be conveniently installed using MacPorts. You need to download and install (dmg + pkg installer) MacPorts:
http://www.macports.org/

Note: MacPorts will download and compile all dependencies. The packages can be quite big and take long to compile.

Once MacPorts is installed, open up a Terminal and enter following line to install the basic dependencies (ass subtitles but no additional codec support - enter admin password):

1 sudo port install subversion pkgconfig freetype fontconfig libiconv ncurses zlib lzo2

Explanation: We will need subversion in a moment to get the current MPlayer sources. If you've got OSX 10.5, subversion is already installed and you can use that. MacPorts will install a more current version, though. pkgconfig tells mplayer where some of our libraries are. freetype, fontconfig and libiconv will be needed for ass subtitles, ncurses is used for terminal output and zlib and lzo2 are compression libraries.

There's also some optional dependencies that can be installed with MacPorts:

1 sudo port install xvid x264 lame libtheora libmad faac libcaca libogg libvorbis twolame libdts libdv jpeg libpng libungif

Explanation: Those are all additonal codecs and some are needed only for encoding (like xvid/h264), mplayer has the basic codecs already included with libavcodec.

MPlayer can use binary codecs to play proprietary formats like WMV, RealVideo and QuickTime. To enable those codecs, you will have to download and install the OSX binary codec pack from the MPlayer homepage:
http://www.mplayerhq.hu/design7/dload.html

2. Compile

Now we can get to compile MPlayer. First, we create a directory and get the sources from svn:

1 mkdir ~/dev/
2 cd ~/dev/
3 svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer

Now we need to configure our installation:

1 cd mplayer
2 export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig" 
3 ./configure --with-extraincdir=/opt/local/include --with-extralibdir=/opt/local/lib --prefix=/opt/local

This will tell the compile script that we have some additonal stuff installed with MacPorts and tells it to install mplayer to /opt/local. The command will print a long list with checks. Everything you want to have in your MPlayer should show up with a "yes" and if configure finishes successfully, it prints a summary at the end.

If everything went fine, we can now go one to compile MPlayer:

1 make

This will take some time. Sit back an enjoy.

If no error shows up (there's no "successful" message), we can check if our binary is fine and then proceed to installing (enter admin password):

1 ./mplayer
2 sudo make install

Finally, to make the terminal find our build, we need to edit bash's PATH variable:

1 nano ~/.profile

Paste following into the terminal, use ctrl-x to exit and confirm to save:

1 export PATH="$PATH:/opt/mplayer/bin" 

And then reload the profile to apply:

1 
2 source ~/.profile

3. Post-Installation

Now we have our own MPlayer that's usable from the command line. If we want to set some general options, we can do that with a configuration file:

1 mkdir ~/.mplayer
2 nano ~/.mplayer/config

Here's how a config file could look like:

 1 # Enable ASS subtitles                   
 2 ass=yes
 3 fontconfig=yes
 4 embeddedfonts=yes
 5 
 6 # Subtitle languages
 7 slang=en,de,fr
 8 
 9 # Faster but unprecise decoding for MPEG2, MPEG4 and h264
10 lavdopts=fast=yes

4. GUI

You can use your build together with the GUI. To install your own, copy the "MPlayer OSX Extended" application to your Applications folder and execute following command in a terminal:

1 sudo cp /opt/mplayer/bin/mplayer /Applications/MPlayer\ OSX\ Extended.app/Contents/Resources/External_Binaries/mplayer.app/Contents/MacOS/mplayer