HowTo: Installing ffmpeg-php extension for MAMP (Mac)

Last updated on
12 February 2018
  • First of all point your php and phpize to your MAMP environment
    • Add/change following line in ~/.profile or ~/.bashrc (for bash):
      export PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.2.17/bin:/usr/local/bin:$PATH:/opt/local/bin
      and after that please re-login (or just execute e.g. /bin/bash).

    • You should also execute in your Terminal
      which php pecl phpize
      which should point to your MAMP installation:

    • phpize -v
      should give you the right API version of your PHP and Zend (without any errors), i.e.
      Configuring for:
      PHP Api Version: 20041225
      Zend Module Api No: 20060613
      Zend Extension Api No: 220060519

  • Make sure that you have command line package manager for Mac like brew or MacPorts:
    • Execute the following line in Terminal to check:
      (which brew || which port) && echo YES || echo NO
    • If you don’t have any, please install brew
  • Install ffmpeg (required by PHP extension)
    • Install via brew:
      sudo brew install ffmpeg
    • Install via port:
      sudo port install ffmpeg
  • Install ImageMagick (required by PHP extension)
    • Install via brew:
      sudo brew install ImageMagick
    • Install via port:
      sudo port install ImageMagick
  • Download MAMP components and configure
    • URL: (i.e.
    • Unpack your
    • Identify your php-5.x.x.tar.gz file (where 5.x.x is your version of PHP)
    • Create a directory for your PHP sources:
      mkdir -vp /Applications/MAMP/bin/php5/include
    • Untar php-5.x.x.tar.gz into /Applications/MAMP/bin/php/php5.*/include or /Applications/MAMP/bin/php5/include
      tar zxvf php-5.x.x.tar.gz -C /Applications/MAMP/bin/php/php5.?.??/include
    • Rename your php-5.x.x directory to php (without the version numbering)
      mv /Applications/MAMP/bin/php/php5.2.17/include/php-5.?.?? /Applications/MAMP/bin/php/php5.2.17/include/php
    • Configure PHP sources (it’ll create necessary files i.e.,zend_config.h, tsrm_config.h etc.)
      • cd /Applications/MAMP/bin/php/php5.?.??/include/php
      • ./configure
  • Install Imagick for PHP via pecl
    • Make sure that your PECL is up-to-date:
      sudo pecl channel-update
    • Install imagick via PECL:
      sudo pecl install imagick
      Or any other version e.g.: imagick-3.1.0RC1
      Check for more recent versions
  • If you want to install Imagick manually
    • Try to configure it as follows:
      ./configure -–with-imagick=/opt/local
  • Install ffmpeg-php for PHP
    • You may try: brew install ffmpeg-php
      if not, follow the below steps
    • svn co ffmpeg-php
    • cd ffmpeg-php/trunk/ffmpeg-php
    • phpize
    • ./configure && make install
      (if you have any errors during compiling about missing zend_config.h, you missed one step - configure your PHP sources first!)
    • You may test ffmpeg library by executing:
      make test
    • Then copy to the right directory (where php5.2.17 is your PHP version):
      cp -frv modules/ /Applications/MAMP/bin/php/php5.2.17/lib/php/extensions/no-debug-non-zts-20060613/
  • Configure your php.ini
    • add following line into your php5.x.x.ini (from MAMP menu: File->Edit Template->PHP->PHP 5.x.x php.ini):
  • Restart your Apache


  • Monitor the errors in your apache_error_log (MAMP: Server tab -> Apache sub-tab -> ‘View Log’)
  • Make sure that you’re compiling PHP extensions for the right CPU architecture, by:
    • checking which do you have on your machine: uname -p
    • comparing CPU architecture of your extensions with MAMP default extensions:
      file `find /Applications/MAMP/bin -name`
      file `find /Applications/MAMP/bin -name`
      file `find /Applications/MAMP/bin -name`
      if you have different, compile your extensions for the right cpu (e.g. ./configure CFLAGS="-m32")
      Instead of file, you could also use:
      otool -hLv `find /Applications/MAMP/bin -name`
  • If you want to back to the previous settings:
    • ○ Remove two extensions (two lines) previously added into your php.ini
  • Incompatible library version: libMagickWand.5.dylib requires version 13.0.0 or later, but libjpeg.8.dylib provides version 12.0.0
    • Reason: You may have duplicated libraries with different versions. MAMP envvars file declares the location of the libs. Edit /Applications/MAMP/Library/bin/envvars file and comment the following lines as below:
      #export DYLD_LIBRARY_PATH

      and restart Apache.

      • Try to locate your failing library:
        sudo locate libjpeg.8.dylib
        If it’s the first time that you uselocate, run:
      • Check the versions via otool:
      • file `locate libjpeg.8.dylib`
    • Solution: try to re-install/upgrade your ImageMagick package
  • When compiling ffmpeg, there is following error:
    ffmpeg-php/trunk/ffmpeg-php/ffmpeg_movie.c: In function ‘zim_ffmpeg_movie_getComment’:
    ffmpeg-php/trunk/ffmpeg-php/ffmpeg_movie.c:538: error: ‘AVDictionaryEntry’ undeclared (first use in this function)
    • Reason: some problem with libavformat library which supposes to be installed with ffmpeg
      sudo locate libavformat.dylib
    • Make sure that your ffmpeg is installed correctly.
    • Solution: re-install ffmpeg (different or more recent version)
      sudo brew uninstall ffmpeg && sudo brew install ffmpeg --use-gcc
  • When installing ffmpeg via brew you have following errors:
    Warning: Building with LLVM, but this formula is reported to not work with LLVM:
    Undefined symbols when linking libavfilter
    • Reason: this package can’t be compiled properly by your cc (which is linked to llvm-gcc; see: ls -al `which cc`)
    • Solution:sudo brew install ffmpeg --use-gcc
  • When you’re compiling ffmpeg via cc and you have any of following errors:
    Undefined symbols for architecture x86_64: "_MM_FIX_0_707106781", referenced from: _filter in vf_fspp.o "_MM_FIX_0_541196100", referenced from: _filter in vf_fspp.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make: *** [libavfilter/libavfilter.2.dylib] Error 1
  • When starting Apache, in logs you have following error:
    PHP Startup: Unable to load dynamic library
    no suitable image found. Did find: mach-o, but wrong architecture in Unknown on line 0
    • Reason: You’ve compiled your extensions for the wrong CPU architecture.
    • Check your current CPU architecture by:uname -p
    • Compare cputype between your extensions and existing one:
      file `find /Applications/MAMP/bin -name`
      file `find /Applications/MAMP/bin -name`
      file `find /Applications/MAMP/bin -name`
    • Here is the example of cpytype mismatch using: otool -hLv (X86_64 and X86_64):
      magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC_64 X86_64 ALL 0x00 BUNDLE 16 1824 DYLDLINK magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC I386 ALL 0x00 BUNDLE 9 1184 DYLDLINK TWOLEVEL SUBSECTIONS_VIA_SYMBOLS
    • Solution: Please compile the extensions for the right CPU architecture.
    • Some example when compiling manually (e.g. ffmpeg):
      ./configure CFLAGS="-m32"
    • Some example when installing extension via pecl:
      sudo CFLAGS="-arch i386 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -g -Os -pipe" CXXFLAGS="-arch i386 -g -Os -pipe" LDFLAGS="-arch i386 -bind_at_load" pecl install imagick
      sudo CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" pecl install imagick
  • When starting Apache, in logs you have one of following errors:
    dyld: lazy symbol binding failed: Symbol not found: _MagickWandGenesis
    Referenced from: /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/
    dyld: Symbol not found: __cg_jpeg_resync_to_restart
    Expected in: flat namespace
    • Reason: some PHP library incompatibilities
    • Possible solutions:
      • You could try to upgrade your MAMP to the recent version
      • You could edit /Applications/MAMP/Library/bin/envvars file and comment following lines as below:
        #export DYLD_LIBRARY_PATH
        and restart your Apache
  • When starting Apache, in logs you have:
    dyld: NSLinkModule() error
    dyld: Library not loaded: /usr/local/lib/libswscale.2.1.100.dylib
    Referenced from: /Applications/MAMP/bin/php/php5.2.17/lib/php/extensions/no-debug-non-zts-20060613/
    Reason: image not found
    • Reason: your ffmpeg.soextension is compiled with libraries which don’t exist anymore
    • The solution is to reinstall/recompile your extension again.
  • When configuring ffmpeg, there is following error:
    configure: error: ffmpeg headers not found. Make sure ffmpeg is compiled as shared libraries using the --enable-shared option
    • Reason: you messed something up with your ffmpeginstallation.
    • Possible solutions:
      • Find your cpffmpeg(installed with ffmpeg) and configure it (where /usr/local/cpffmpeg is your right path to cpffmpeg):
        ./configure --with-ffmpeg=/usr/local/cpffmpeg
      • If you still have the problems, reinstall your ffmpeg.
  • When executing pecl, there is an error:
    Notice: unserialize(): Error at offset 276 of 1133 bytes in Config.php on line 1050
    ERROR: The default config file is not a valid config file or is corrupted.
    • Reason: your pecl configuration file is corrupted
    • Possible solutions: Remove your pecl configuration
      • rm -v /Applications/MAMP/bin/php/php5*/conf/pear.conf
      • rm -v ~/.pearrc