Compiling mplayer on Mac OSX Snow Leopard with ffmpeg-mt, ordered chapters and libass.

I finally installed Mac OS X Snow Leopard and managed to do a 64bit compilation using Uoti’s mplayer fork build scripts. I hope this will be useful for anyone running Snow Leopard (note that some of the chunks of this post are taken from my previous one about building on Leopard).
This has been tested on a clean slate install of SL, if you upgraded from Leopard you should reinstall MacPorts and all the ports or install the ports as universal binaries to include the x86_64 version.


1) First you need to install a couple of dependencies. MacPorts automates the building process for the dependencies. Make sure your MacPorts directories are at the start of your path and that you exported the PKG_CONFIG variable correctly. To achieve this your .bash_profile file should look something like this:

export PATH=/opt/local/bin:/opt/local/sbin:${PATH}
export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig"

Install those dependencies:

sudo port install git-core autoconf automake libtool pkgconfig freetype fontconfig libiconv ncurses zlib lzo2

2) Download the build scripts from the git repository:

git clone git://repo.or.cz/mplayer-build.git

To launch the build script you do not use the usual ./configure && make && make install, read the README for more information on how the scripts work.

Download the source code for ffmpeg, libass and mplayer (this is done with the ./init command), and enable multithreading in ffmpeg:

cd mplayer-build
./enable-mt
./init

3) Edit the configuration files.

“common_options”:

--cc=gcc-4.2

“ffmpeg_options”:

--cpu=core2
--arch=x86_64

“mplayer_options”:

--disable-x11
--disable-gl
--disable-mencoder
--enable-macosx-bundle
--enable-macosx-finder
--target=x86_64-Darwin

4) Compile using

make

The build script will take care of compiling ffmpeg, libass, mplayer and then linking them together.
After you are done you should find your mplayer executable in the mplayer subdirectory.

5) To use your newly compiled mplayer with the MPlayerOSX Extended GUI:

cd mplayer
sudo cp mplayer /Applications/MPlayer\ OSX\ Extended.app/Contents/Resources/External_Binaries/mplayer.app/Contents/MacOS/mplayer

Enjoy your bleeding edge mplayer!

Note that at the moment it is not possible to embed mplayer in the GUI Window; in Preferences->Display you need to choose “As separate window (CoreVideo)” as your video output.

EDIT (26/9/2009): Removed the source code fix from this article, since it has been added on the repository.
EDIT (10/10/2009): As of current release video embed works again.

Advertisements

55 Comments »

  1. Jesse said

    Hello,

    I’m curious why I have this problem on final linking stage:

    “_sws_scale_ordered”, referenced from:
    _scale in vf_scale.o
    _scale in vf_scale.o
    _scale in vf_scale.o
    _draw_slice in vf_screenshot.o
    _put_image in vf_screenshot.o
    “_av_fifo_reset”, referenced from:
    _reset in ao_coreaudio.o
    “_av_fifo_alloc”, referenced from:
    _init in ao_coreaudio.o
    _init in ao_coreaudio.o
    “_av_free_packet”, referenced from:
    _demux_lavf_fill_buffer in demux_lavf.o
    _demux_lavf_fill_buffer in demux_lavf.o
    “_avcodec_decode_video2”, referenced from:
    _decode in vd_ffmpeg.o
    ld: symbol(s) not found

    While I was able to build the mplayer manually without using your python script. But, it’s not using ffmpeg-mt.

    It also has the ability to play the video integrated with the GUI.

  2. pigoz said

    edit: as you found out you get that linking error when linking against a different version of ffmpeg. To find ffmpeg libraries that might get in the way do a “mdfind libpostproc.a” (you need to do the same with libavcodec, libswscale, etc.) in the Terminal, then you can proceed to delete any ffmpeg libraries outside of the mplayer-build path and the related header files.

  3. Jesse said

    Nevermind, it’s because I did installed ffmpeg from MacPorts. It’s caused by linking to the wrong libs.

    This is what I used in mplayer_options (other options are the same):

    –target=x86_64-Darwin
    –disable-x11
    –disable-gl
    –disable-openal
    –disable-mencoder
    –enable-apple-remote
    –enable-macosx-bundle
    –enable-macosx-finder

    I’m disabling openal only because I think it would not be used by me.

    Besides, if I had to fix something related to sdl, I got build error caused by undeclared SDLK_SLASH.

    I’m using MacBook4,1, with:
    System Version: Mac OS X 10.6.1 (10B504)
    Kernel Version: Darwin 10.0.0
    64-bit Kernel and Extensions: No

    It’s not booting into 64-bit kernel, because I’m using a MacBook. But, that’s not related to whether I could run 64-bit software or not. My build arch is x86_64.

    It’s an upgrade from Leopard.

    Thanks for your effort to write those scripts.

  4. Jesse said

    *Typo, the options should start with —

  5. Jesse said

    Sorry, it seems double dash is not displayed correctly here.

  6. Jesse said

    Well, until I figured out why your build is different from manual build. I may have to stick with the manual build. Because, it works with integrated window using CoreVideo.

    I’m also using your git repo for manual build. I disabled sdl, openal, liba52, and mp3lib.

    I also did not use your patch osx_common.c in this case.

  7. Cavin G. said

    It would be super helpful if you to include a how-to on what to do with the source code for ffmpeg, libass and mplayer, and enable multithreading in ffmpeg.Are your instructions all that is needed for them to be installed? Where do you get those source code packages? Do they need to be installed or are they fine in the folder you specified?

    Also,it would be helpful for there to be a link to the things you refer to, such as the mplayer compilation readme. http://www.mplayerhq.hu/DOCS/README

  8. Cavin G. said

    Oh, also, does one need to download the extended GUI from the link you gave? Or do we just try (and then fail) to use to sudo cp command with nothing else?

    You gave really really helpful instructions. But they would be even better if you could be as specific and elementary as possible. :)

  9. Cavin G. said

    I decided also, that it might be better using the readme and another source, that on Snow Leopard this might be the best way to use ./configure on SL:

    ./configure –enable-gui –target=x86_64-Darwin

    That is if and only if you’re on a Core 2 Duo Mac or higher, of course.

  10. Cavin G. said

    ohohoh! I kind of just got it. You did in fact give a place to dl/install ffmpeg, etc… I was not expecting the ./init to do that. Sorry! Thanks! :D

  11. http://pastebin.com/m336c07a3 :(

    • Jesse said

      You should type – -disable-gl not g”one”

      It supposed to mean disabling OpenGL.

  12. Jesse said

    I’m not sure why his previous post about this works better on my machine than using these build scripts.

    There are several sources on mplayer-build that might not be necessary.

    Anyway Cavin, you only need MPlayer OS X Extended if you want to use the app to play it. Command line is fine too.

    I’m also planning to fork and update the MPlayer OS X Extended, the sources are not up to date, and it’s not utilizing the latest API in SL.

    • Well I just don’t know how to do subtitles without the GUI.
      It turns out, if I don’t run the command to copy the compiled mplayer, then it works perfectly. Otherwise, it gives me an error when I try to open anything. :\

      • It being OSX Extended

      • pigoz said

        As I wrote at the moment embedding in the window fails. You need to use an external CoreVideo window.

        These build scripts are better because they use use the newest libass: if you by chance watch fansubbed anime the newest libass renders subtitles (almost) as good as VSFilter on Windows; this is not true for the libass that comes with mplayer’s source.

        To use libass with the CLI just activate it in the config file. My “.mplayer/config” looks like this:
        # Write your default config options here

        # Enable ASS subtitles
        ass=yes
        fontconfig=yes
        embeddedfonts=yes

        # Subtitle languages
        slang=en,de,fr

        # Faster but unprecise decoding for MPEG2, MPEG4 and h264
        lavdopts=fast=1:threads=2

      • Oh I see. Thanks :)

    • pigoz said

      I wouldn’t mind working on a clean GUI using the newest technologies when it makes sense, and objective-c 2.

      If you start working on something let me know please. :)

      • Jesse said

        Definitely,

        I’m okay with my own build of mplayer for playing most files. ASS works, subtitle works, integrated window with corevideo works.

        I’m a bit clueless with mplayer intricacies, so I’ll leave that to you.

        I’ll work on MPlayer OS X Extended instead.

    • Okay so I did that, and I still get an error. :\
      http://pastebin.com/m65ee3be

      • pigoz said

        Go to MPlayer OSX Extended Preferences->Audio and disable the bs2b filter, I would need to Google around to find out how to compile mplayer with bs2b support.

      • Oh okay. Thanks so much for your help it works now. :D

  13. Jesse said

    Anyway, I don’t know why they named it as ‘OSX’ instead of OS X just like Mac OS X.

    Is it a typo ? Not sure.

  14. Do either of you know if I would be able to make the corevideo window stay on top? When that option is checked in mplayer, it doesn’t apply to the external window.
    Also, and this is not a big deal, but if I try to resize the window (which I do often when I’m chatting/watching something) the video stops until I let it go, and then speeds up to the point it would be at had it not stopped.
    :)

    • Jesse said

      Sorry, didn’t happened to me.

      My player works smoothly. Try the latest version.

      • I did try the latest version? I mean, I used everything I got here^^. Do I need an updated… something? If so, will you link me? :) Thx

  15. Jesse said

    Sorry, I think it doesn’t have anything to do with the extended.

    There might have been a difference between my mplayer and yours, which affects the GUI.

    I’m uploading my mplayer binary to Dropbox. It will be there soon.

    • Hey thanks I appreciate it!

    • Nevermind I fix it by adding something to the directions above. I did make and then mplayer command wouldn’t work. So then I did sudo make install and it did this:
      MacBook-Pro:mplayer-build Cavin$ sudo make install
      Password:
      make -C mplayer install
      if test ! -d /usr/local/bin ; then install -d /usr/local/bin ; fi
      if test ! -d /usr/local/etc/mplayer ; then install -d /usr/local/etc/mplayer ; fi
      if test ! -d /usr/local/lib ; then install -d /usr/local/lib ; fi
      install -m 755 -s mplayer /usr/local/bin
      if test ! -d /usr/local/share/man/man1 ; then install -d /usr/local/share/man/man1 ; fi
      install -m 644 DOCS/man/en/mplayer.1 /usr/local/share/man/man1/

      And now it works! :D

  16. Jesse said

    Command not found means that your path to mplayer is not recognized to the environment.

    If you want to use my binary, you just have to install aalib from macports.

    You can also install other things which is required. Run this to found out:

    otool -L /path/to/mplayer

  17. GreenSkye said

    what do i do with step 3) edit the configuration files. I type –cc=gcc-4.2
    and press enter and it says command not found. I’ve been following this guide by copy/pasting everytime it gives me a prompt. Is there something else I need to do?

    This is what I did:
    HAL9000:mplayer-build Blue$ –cc=gcc-4.2
    -bash: –cc=gcc-4.2: command not found

    is there a place I put the config commands?

    • pigoz said

      You have to edit the text files with a text editor (TextEdit is good enough, as well TextMate, vim or emacs) and add the lines I mentioned.

      • GreenSkye said

        text files? how do i open/edit these? sorry I’ve never done command line before

      • pigoz said

        they are files containing text, you will find them in your mplayer-build directory, just right click and open with textedit.

      • GreenSkye said

        I got it to work! Thanks! One quick thing tho. You say that it only works with the “seperate window” option enabled, but in mine it works with both. I installed the .dmg version of Mplayer osx extended before compiling this version, would that make a difference?

      • pigoz said

        Thanks for reporting it; it seems the problem was fixed with the merge of the svnupdate 4 days ago: will update the article accordingly.

  18. rezzo said

    Somebody can upload the mplayer ready to use? I want use mkv this Ordered Chapters. thx!

    • pigoz said

      Check the most recent article on this blog :)

      • rezzo said

        Awesome! thanks for the fast reply (=

  19. dramaQUEEN said

    hello! first THX for this tuto. I am new to mac, came from linux, this saved my live :)

    BUT i need mencoder aswell.
    so i did in mplayer_options
    –enable-mencoder

    but what came out is not recognized as a binary :(
    instead terminal spits out -bash: mencoder: command not found
    aaaah

    any clue how to compile mplayer right to get mencoder working?
    thx in advance
    DQ

    • pigoz said

      I was never able to compile mencoder from git (I never really tried to look into it). Doing it from svn should be possibile, as it is the official mplayer release. I would take a look on the Portfiles of mplayer-devel in Macports to find out the ./configure flags you need.

      • dramaQUEEN said

        thanks for your fast reply!

        the first time i tried to install mplayer via macports it didn’t work. i had macports 1.8.0 installed on snow leo running 64bit kernel mode.

        so i found your how to as the best way to install a nice compiled mplayer.

        your mplayer-devel hint was very good. it installed nicely with macports 1.8.1 and mencoder is working aswell.

        i did copy the macports-mplayer binary to the inside of mplayer-osx-extended as you mentioned and now everything is working fine.

        thanks a lot!
        nice xmas :)

    • pigoz said

      Well, I’m glad it worked. Notice that mplayer-devel doesn’t support ordered chapters and it uses an older libass. If you are not watching anime fansubs it is not going to make any difference.

      Happy Christmas :)

  20. MarkWJ said

    Found this site as I was trying to compile FFMEPG-MT and Mencoder/ Mplayer for use with PS3 Media Player on a Mac – the versions included are over 6 months old and I figured would have much improved since then. After much tweaking and googling I got all three to compile for a 32bit Snow Leopard Core Duo (NOT Core2) system using GCC 4.0 (which is thankfully included in Snow Leopard – I used gcc_select from Macports to select it). GCC 4.2 would NOT compile – kept getting ASM errors. I have installed the new binaries and they all SEEM to work fine.

    The main changes to the options files was to remove all lines referring to X86_64 and to change the option –CPU=prescott in the ffmpeg_options file.

  21. CavinSays said

    Hi,
    I just thought it would be good to post that it is no longer relevant to the newest version of Mplayer OS X Extended to put things in:
    /Applications/MPlayer\ OSX\ Extended.app/Contents/Resources/External_Binaries/mplayer.app/Contents/MacOS/

    Now, it is more complex. Basically, though, the directories are like this:
    MP=/Applications/’MPlayer OSX Extended.app’/Contents/Resources/Binaries/mpextended.mpBinaries/Contents/*.mpBinaries/

    ** $MP/Contents/Info.plist
    ** $MP/Contents/Resources/dsa_pub.pem
    ** $MP/Contents/Resources/config
    ** $MP/Contents/MacOS/mplayer
    ** $MP/MacOS/lib/ — in this folder, obviously, there are libraries.

    I’ll also mention that in the multi-thread binary package, the libraries are all links to the libraries of the non-multi-thread binary, in its respective package.

    I’m not sure how this will do when trying to use your own mplayer binary that you’ve compiled yourself. I’m going to test to see and should write back soon.

  22. drosan said

    You forgot about yasm – it need to be installed as dependency for building too.

  23. Dogan Bilge said

    The last few builds, multithreading is not working anymore. Whether I add the lavdopts command, mplayer still uses a single CPU.

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: