CompileMPlayerShared

Version 2 (Adrian Stutz, 10/05/2008 03:45 pm)

1 1
2 2 Adrian Stutz
h1. Compile MPlayer with shared libraries
3 2 Adrian Stutz
4 2 Adrian Stutz
5 1
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).
6 1
7 2 Adrian Stutz
The first one, especially on OSX, is a lot easier to do and thanks to projects like "MacPorts":http://www.macports.org/, 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.
8 1
9 1
10 2 Adrian Stutz
h2. 1. Dependencies
11 2 Adrian Stutz
12 2 Adrian Stutz
13 1
Most of the hot stuff is done in the Terminal. You can find it in Applications > Utilities > Terminal.
14 1
15 1
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):
16 1
http://developer.apple.com/tools/download/
17 1
18 2 Adrian Stutz
The various dependencies of MPlayer can be conveniently installed using "MacPorts":http://www.macports.org/. You need to download and install (dmg + pkg installer) [[MacPorts]]:
19 1
http://www.macports.org/
20 1
21 2 Adrian Stutz
_Note: [[MacPorts]] will download and compile all dependencies. The packages can be quite big and take long to compile._
22 1
23 2 Adrian Stutz
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):
24 2 Adrian Stutz
<pre>
25 2 Adrian Stutz
<code class="rst">
26 1
sudo port install subversion pkgconfig freetype fontconfig libiconv ncurses zlib lzo2
27 2 Adrian Stutz
</code></pre>
28 1
29 2 Adrian Stutz
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.
30 1
31 2 Adrian Stutz
There's also some optional dependencies that can be installed with [[MacPorts]]:
32 2 Adrian Stutz
<pre>
33 2 Adrian Stutz
<code class="rst">
34 1
sudo port install xvid x264 lame libtheora libmad faac libcaca libogg libvorbis twolame libdts libdv jpeg libpng libungif
35 2 Adrian Stutz
</code></pre>
36 1
37 1
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.
38 1
39 2 Adrian Stutz
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:
40 1
http://www.mplayerhq.hu/design7/dload.html
41 1
42 1
43 2 Adrian Stutz
h2. 2. Compile
44 2 Adrian Stutz
45 2 Adrian Stutz
46 1
Now we can get to compile MPlayer. First, we create a directory and get the sources from svn:
47 2 Adrian Stutz
<pre>
48 2 Adrian Stutz
<code class="rst">
49 1
mkdir ~/dev/
50 1
cd ~/dev/
51 1
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
52 2 Adrian Stutz
</code></pre>
53 1
54 1
Now we need to configure our installation:
55 2 Adrian Stutz
<pre>
56 2 Adrian Stutz
<code class="rst">
57 1
cd mplayer
58 1
export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig"
59 1
./configure --with-extraincdir=/opt/local/include --with-extralibdir=/opt/local/lib --prefix=/opt/local
60 2 Adrian Stutz
</code></pre>
61 1
62 2 Adrian Stutz
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.
63 1
64 1
If everything went fine, we can now go one to compile MPlayer:
65 2 Adrian Stutz
<pre>
66 2 Adrian Stutz
<code class="rst">
67 1
make
68 2 Adrian Stutz
</code></pre>
69 1
70 1
This will take some time. Sit back an enjoy.
71 1
72 1
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):
73 2 Adrian Stutz
<pre>
74 2 Adrian Stutz
<code class="rst">
75 1
./mplayer
76 1
sudo make install
77 2 Adrian Stutz
</code></pre>
78 1
79 1
Finally, to make the terminal find our build, we need to edit bash's PATH variable:
80 2 Adrian Stutz
<pre>
81 2 Adrian Stutz
<code class="rst">
82 1
nano ~/.profile
83 2 Adrian Stutz
</code></pre>
84 1
85 1
Paste following into the terminal, use ctrl-x to exit and confirm to save:
86 2 Adrian Stutz
<pre>
87 2 Adrian Stutz
<code class="rst">
88 1
export PATH="$PATH:/opt/mplayer/bin"
89 2 Adrian Stutz
</code></pre>
90 1
91 1
And then reload the profile to apply:
92 2 Adrian Stutz
<pre>
93 2 Adrian Stutz
<code class="rst">
94 1
95 1
96 1
97 1
source ~/.profile
98 2 Adrian Stutz
</code></pre>
99 1
100 1
101 2 Adrian Stutz
h2. 3. Post-Installation
102 2 Adrian Stutz
103 2 Adrian Stutz
104 1
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:
105 2 Adrian Stutz
<pre>
106 2 Adrian Stutz
<code class="rst">
107 1
mkdir ~/.mplayer
108 1
nano ~/.mplayer/config
109 2 Adrian Stutz
</code></pre>
110 1
111 1
Here's how a config file could look like:
112 2 Adrian Stutz
<pre>
113 2 Adrian Stutz
<code class="rst">
114 1
# Enable ASS subtitles                   
115 1
ass=yes
116 1
fontconfig=yes
117 1
embeddedfonts=yes
118 1
119 1
# Subtitle languages
120 1
slang=en,de,fr
121 1
122 1
# Faster but unprecise decoding for MPEG2, MPEG4 and h264
123 1
lavdopts=fast=yes
124 2 Adrian Stutz
</code></pre>
125 1
126 1
127 2 Adrian Stutz
h2. 4. GUI
128 2 Adrian Stutz
129 2 Adrian Stutz
130 1
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:
131 2 Adrian Stutz
<pre>
132 2 Adrian Stutz
<code class="rst">
133 1
sudo cp /opt/mplayer/bin/mplayer /Applications/MPlayer\ OSX\ Extended.app/Contents/Resources/External_Binaries/mplayer.app/Contents/MacOS/mplayer
134 2 Adrian Stutz
</code></pre>