Installing FFMpeg and FFMpeg-PHP

/* This article can possibly be re-written using the RPMs available from RPMForge. http://wiki.centos.org/AdditionalResources/Repositories/RPMForge */

Below is a step-by-step how-to on installing ffmpeg and ffmpeg-php on CentOS 5.3. The reason we (or anyone really) have not published a script to automate the process is due to the complexity of the installation and the fact that it is very prone to failures along the way, almost always requiring some sort of human intervention. We have attempted to address the most common of issues in this article, but if you find that you're stuck at one that is not mentioned, please feel free to send support an email.

We have also used very explicit versions of each of the libraries/codecs/software in this guide as we have found these to have the highest rate of success. If you need the additional functionality provided by a newer version of any of these, please note that doing so may break other parts of the installation; caveat emptor!
  1. First start out by downloading the necessary sources. These versions are subject to change so you may want to browse each repo to find the latest version (again caveat emptor!). This also installs Ruby, which is a pre-requisite for installing Flvtool; if you already have Ruby, skip the second line in this step and the first three lines in step 7:
    cd /usr/local/src; \
    wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.gz; \
    wget http://www1.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2; \
    wget http://rubyforge.org/frs/download.php/9225/flvtool2_1.0.5_rc6.tgz; \
    wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz
  2. Extract the files you just downloaded.
    tar xjvf essential-20061022.tar.bz2; \
    tar xzvf flvtool2_1.0.5_rc6.tgz; \
    tar xzvf lame-3.98.4.tar.gz; \
    tar xzvf ruby-1.9.1-p0.tar.gz
  3. Next you'll want to create a codec location and import the codecs there:
    mkdir /usr/local/lib/codecs/
    mv essential-20061022/* /usr/local/lib/codecs/
    chmod -R 755 /usr/local/lib/codecs/
  4. Next we'll need to satisfy some other pre-requisites:
    yum install subversion ncurses-devel automake autoconf libtool* neon neon-devel
    • You may encounter an error saying that no suitable perl(URI) was found for subversion. If so, run the following and then re-run the yum command above without subversion:
      wget http://subversion.tigris.org/downloads/subversion-1.5.9.tar.bz2
      tar xjvf subversion-1.5.9.tar.bz2
      cd subversion-1.5.9 && ./configure --with-apr=/usr/local/apache/bin/ --with-apr-util=/usr/local/apache/bin/ --with-ssl --disable-mod-activation
      make && make install
      cd ..
    • NOTE: You may need to change the APR paths to reflect your own Apache installation (e.g. /etc/httpd/bin/).
  5. Get the latest FFMpeg and Mplayer via Subversion:
    svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
    svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
  6. Edit /etc/ld.so.conf and add /usr/local/lib then run:
    ldconfig -v
  7. Let's compile all the codecs and libraries (& pre-reqs!) at once:
    cd /usr/local/src/ruby-1.9.1-p0
    ./configure
    make && make install
    cd /usr/local/src/lame-3.98.4
    ./configure
    make && make install
    cd /usr/local/src/flvtool2_1.0.5_rc6
    ruby setup.rb config && ruby setup.rb setup && ruby setup.rb install
    cd /usr/local/src/mplayer
    ./configure --yasm=''
    make && make install
    • As of this writing, the latest version of Mplayer now requires Git to download it's own copy of the FFMpeg source. CentOS' default repos don't include the RPMs (if yours does, then lucky you!), so here's how to install the needed RPMs manually. Re-run the configure step after you've done this.
      rpm -ivh http://kernel.org/pub/software/scm/git/RPMS/i386/git-core-1.5.4.2-1.i386.rpm \
      http://kernel.org/pub/software/scm/git/RPMS/i386/perl-Git-1.5.4.2-1.i386.rpm \
      http://packages.sw.be/perl-Error/perl-Error-0.17016-1.el5.rf.noarch.rpm
  8. Install FFMpeg:
    cd /usr/local/src/ffmpeg
    ./configure --enable-libmp3lame --disable-mmx --enable-shared
    make && make install
    • Use ./configure --help if you'd like to enable additional libraries/codecs. Many will require additional downloads & builds like those above. Note that after each library/codec install, you'll need to run ldconfig -v.
  9. Set up links to the codecs:
    ln -s /usr/local/lib/libavformat.so.50 /usr/lib/libavformat.so.50; \
    ln -s /usr/local/lib/libavcodec.so.52 /usr/lib/libavcodec.so.52; \
    ln -s /usr/local/lib/libavdevice.so.52 /usr/lib/libavdevice.so.52; \
    ln -s /usr/local/lib/libavutil.so.50 /usr/lib/libavutil.so.50; \
    ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0; \
    ln -s /usr/local/lib/libavformat.so.52 /usr/lib/libavformat.so.52; \
    ln -s /usr/local/lib/libswscale.so.0 /usr/lib/libswscale.so.0
  10. Let's finish the compilation of FFMpeg-PHP now:
    cd /usr/local/src/
    wget "http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2?use_mirror=garr"
    tar xjvf ffmpeg-php-0.6.0.tbz2
    cd ffmpeg-php-0.6.0
    phpize
    ./configure
    make && make install
    • If ./configure fails saying it cannot find ffmpeg headers, you need to perform the following:
      cp /usr/local/include/libavcodec/* /usr/local/include/ffmpeg; \
      cp /usr/local/include/libavutil/* /usr/local/include/ffmpeg; \
      cp /usr/local/include/libavformat/* /usr/local/include/ffmpeg; \
      cp /usr/local/include/libavdevice/* /usr/local/include/ffmpeg; \
      cp /usr/local/include/libswscale/* /usr/local/include/ffmpeg
  11. Add the extension for ffmpeg.so in your php.ini:
    ;ffmpeg-php extension
    extension=ffmpeg.so
  12. Restart Apache:
    /etc/init.d/httpd restart
  13. Check to make sure it started okay:
    ps auxf|grep http
    root      5684  0.0  0.0  66064  5052 ?        Ss   Sep15   0:49 /usr/local/apache/bin/httpd -k start -DSSL
    nobody   17175  0.0  0.0  66340  4836 ?        S    15:32   0:00  \_ /usr/local/apache/bin/httpd -k start -DSSL
    nobody   17176  0.0  0.0  66344  4768 ?        S    15:32   0:00  \_ /usr/local/apache/bin/httpd -k start -DSSL
  14. Check to ensure ffmpeg is loaded into PHP:
    php -i|grep ffmpeg
    ffmpegffmpeg support (ffmpeg-php) => enabled
    ffmpeg-php version => 0.6.0
    ffmpeg.allow_persistent => 0 => 0

That's it! Your PHP installation will not have the ability to use ffmpeg functions!