Installing FFMpeg and FFMpeg-PHP

/* This article can possibly be re-written using the RPMs available from 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; \ wget; \ wget; \ wget</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 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 ffmpeg svn checkout mplayer</sxh>
  • Edit /etc/ 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/ /usr/lib/; \ ln -s /usr/local/lib/ /usr/lib/; \ ln -s /usr/local/lib/ /usr/lib/; \ ln -s /usr/local/lib/ /usr/lib/; \ ln -s /usr/local/lib/ /usr/lib/; \ ln -s /usr/local/lib/ /usr/lib/; \ ln -s /usr/local/lib/ /usr/lib/</sxh>
  • Let's finish the compilation of FFMpeg-PHP now:
    <sxh shell; auto-links: false>cd /usr/local/src/ wget “” 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 in your php.ini:
    <sxh plain>;ffmpeg-php extension</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!