Installing ffmpeg-php on OS X against Apache2/PHP5 from MacPorts

    [Edit 2011/09/09] ffmpeg-php is long out of date and doesn't compile with later versions off ffmpeg: try this php version instead: , works with very few changes to code - I had to change new ffmpeg_movie() to new FFmpegMovie() 

    This is more for my own benefit that anyone elses, so when I inevitably have to recompile in future I don't have to do all this rediscovery again (Yes, I have done this before and forgotten how I did it the first time). However, I thought i'd hack it into some sort of tutorial (expression used lightly).

    Asusming you have Apache 2/PHP5 and FFMPEG installed from MacPorts *, and you are reasonably comfortable with the terminal. This is pretty much 'by the book' for the instructions from ffmpeg, save for a few little glitches with the configure script.

    Grab the latest ffmpeg-php tarball from here and, open terminal, cd to the download directory and decompress it:

    tar xvjf ffmpeg-php-0.6.0.tbz2

    change to the resultant directory

    cd ffmpeg-php-0.6.0/

    run your _port_ version of phpize


    now, the first gotcha, you need to run a custome configure line to make sure that the make finds the correct ffmpeg install, and the correct include dirs. Do this:

    CFLAGS=-I/opt/local/include ./configure --with-ffmpeg=/opt/local --enable-gd --enable-skip-gd-check

    That 'CFLAGS=-I/opt/local/include' part sets and environment variable called CFLAGS to have the value -I/opt/local/include which is a C compiler flag to tell it to search for include files in '/opt/local/include'. We set that, then run the ./configure script which takes that information, and the parameters '--with-ffmpeg=/opt/local --enable-gd --enable-skip-gd-check' to build an appropriate makefile.

    Without passing the --with-ffmpeg=/opt/local the configure script will fail with: configure: error: ffmpeg headers not found. Make sure ffmpeg is compiled as shared libraries using the --enable-shared option. If you have got ffmpeg installed correctly (and please make sure you do!) then this means it can't be found, so you need to tell it where it is. Of course you may have installed ffmpeg differently so you can change this appropriately.

    The --enable-gd flags force ffmpeg-php to enable gd extensions (so you can export an image in GD format for processing with PHP's GD libraries) and the --enable-skip-gd-check makes it take your word for it that GD is installed, which it was in my case, but I had to force the issue. Sometimes us mere mortals know best.

    Without passing the CFLAGS=-I/opt/local/include the make script will generate a message along the lines of error: libavutil/avutil.h: No such file or directory letting you know that the compiler can't fine an include file, and so you need to give it a base include path. Again if your ffmpeg install is not from macports you'll need to change this appropriately.

    Now do a simple:


    Which will compile our module. Normally now we'd type 'make install' and the module would be installed, but no such luck here. For some reason the configure script insists on installing in /usr/lib/php/extensions/... wherease the rest of our extensions are in /opt/local/lib/php/extensions/... however, to work out _where_ we want to install to we still need to run 'make install' (but not as root - we want the install to fail)

    make install

    With a bit of luck this will return an error (call that luck?) something along the lines of

    cp: /usr/lib/php/extensions/no-debug-non-zts-20060613/#INST@69638#: Permission denied

    the bit you are looking for is the equivalent to 'no-debug-non-zts-20060613' as you need this to install in the correct path, which shouldbe '/opt/local/lib/php/extensions/no-debug-non-zts-20060613/' (though you may need to change that last bit, obviously) We now enter:

    sudo cp modules/ /opt/local/lib/php/extensions/no-debug-non-zts-20060613/

    To copy the php module to our appropriate include directory. You'll need to enter your password to do the copy. Not quite there yet... now you need to add the extension to your php.ini file. By default this is /opt/local/etc/php5/php.ini but if you want to check:

    /opt/local/bin/php -r "phpinfo();" | grep "Configuration File"

    Will tell you for sure. Open up the file in your favourite text editor (textmate or vim for me) and search for the heading " Dynamic Extensions" in the config file. if it's not there don't worry, I'm just trying to be neat. You neeed to enter, under the rest of your extensions:


    then save the file. Now, to check it has installed into php:

    /opt/local/bin/php -r "phpinfo();" | grep "ffmpeg"

    should give you something along the lines of :

    ffmpeg-php version => 0.6.0-svn
    ffmpeg-php built on => Jul 21 2009 09:30:03
    ffmpeg-php gd support => disabled
    ffmpeg libavcodec version => Lavc52.20.0
    ffmpeg libavformat version => Lavf52.31.0
    ffmpeg swscaler version => SwS1.7.1
    ffmpeg.allow_persistent => 0 => 0
    ffmpeg.show_warnings => 0 => 0

    If so you can now restart apache and start playing with it.

    apachectl restart

    Hope that helps someone else...

    Please note that I'm by no means an expert on this and so can't help you get it working if there are all sorts of other issues, that said leave a comment below listing your problem and I'll see what I can do.

    * quick run through, YMMV , check out appropriate variants should you need to:

    sudo port install apache2
    sudo port install php5
    sudo port install ffmpeg +shared

    Also, look here for information on install ffmpeg from ports, and here for information on apache2/php5/mysql from ports, which both looks reasonably informative, but I've not bothered to use instead just bludgeoning on and doing it myself previously.

show menu