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!
  • 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:
    <sxh shell; auto-links: false>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</sxh>
  • Extract the files you just downloaded.
    <sxh shell>tar xjvf essential-20061022.tar.bz2; \ tar xzvf flvtool21.0.5rc6.tgz; \ tar xzvf lame-3.98.4.tar.gz; \ tar xzvf ruby-1.9.1-p0.tar.gz</sxh>
  • Next you'll want to create a codec location and import the codecs there:
    <sxh shell>mkdir /usr/local/lib/codecs/ mv essential-20061022/* /usr/local/lib/codecs/ chmod -R 755 /usr/local/lib/codecs/</sxh>
  • Next we'll need to satisfy some other pre-requisites:
    <sxh shell>yum install subversion ncurses-devel automake autoconf libtool* neon neon-devel</sxh>
    • 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:
      <sxh shell; auto-links: false>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 ..</sxh>
    • NOTE: You may need to change the APR paths to reflect your own Apache installation (e.g. /etc/httpd/bin/).
  • Get the latest FFMpeg and Mplayer via Subversion:
    <sxh shell; auto-links: false> svn checkout svn:svn.mplayerhq.hu/ffmpeg/trunk ffmpeg svn checkout svn:svn.mplayerhq.hu/mplayer/trunk mplayer</sxh>
  • Edit /etc/ld.so.conf and add /usr/local/lib then run:
    <sxh shell>ldconfig -v</sxh>
  • Let's compile all the codecs and libraries (& pre-reqs!) at once:
    <sxh shell>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/flvtool21.0.5rc6 ruby setup.rb config && ruby setup.rb setup && ruby setup.rb install cd /usr/local/src/mplayer ./configure –yasm='' make && make install</sxh>
  • Install FFMpeg:
    <sxh shell>cd /usr/local/src/ffmpeg ./configure –enable-libmp3lame –disable-mmx –enable-shared make && make install</sxh>
    • 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.
  • Set up links to the codecs:
    <sxh shell>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</sxh>
  • Let's finish the compilation of FFMpeg-PHP now:
    <sxh shell; auto-links: false>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</sxh>
    • If ./configure fails saying it cannot find ffmpeg headers, you need to perform the following:
      <sxh shell>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</sxh>
  • Add the extension for ffmpeg.so in your php.ini:
    <sxh plain>;ffmpeg-php extension extension=ffmpeg.so</sxh>
  • Restart Apache:
    <sxh shell>/etc/init.d/httpd restart</sxh>
  • Check to make sure it started okay:
    <sxh shell>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</sxh>
  • Check to ensure ffmpeg is loaded into PHP:
    <sxh shell>php -i|grep ffmpeg ffmpegffmpeg support (ffmpeg-php) ⇒ enabled ffmpeg-php version ⇒ 0.6.0 ffmpeg.allow_persistent ⇒ 0 ⇒ 0</sxh>

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