Installing and configuring FFmpeg and FFpeg-Php

FFMPEG is a complete solution to record, convert and stream audio and video segments. It includes libavcodec, the leading audio/video codec library.
NOTES:

  • This guide had been used effectively on several Web production servers with CentOS v5.x and Red Hat v4/5, however there are some which might not be compatible.
  • Although this guide is designed for a Linux i386 powered server, it might work on a 86_64 system — (proceed at your own risk.)
  • If you experience any problems installing FFmpeg and FFmpeg-Php on your server and need help, just PM me or reply in thread i’ll install for you .

There are two methods to install FFmpeg and FFmpeg-Php, their libraries, and modules:

  1. Our preferred method is to use Yum on systems including Red Hat, CentOS, and Fedora Core.
  2. Manually, from source archives/packages –�NOT RECOMMENDED (proceed at your own risk.)

*** Caution

  • You must remove all previous installation of FFmpeg and FFmpeg-Php, then follow installation instructions below.
  • Follow these steps (in that order):

Method #1: Using yum 

First, make sure the following binary packages are installed on your server:

gcc, gcc4, gcc4-c++, gcc4-gfortran, gd, gd-devel, gmake, ImageMagick, ImageMagick-devel, libcpp, libgcc, libstdc++, make, ncurses, ncurses-devel, ruby, subversion

If any of these packages are missing, install them using Yum . For example:

  • yum install PACKAGE
  1. Install rpmforge repository. Follow the instructions on CentOS Wiki
  2. Install ffmpeg, mplayer, mencoder with all supported libraries/modules
    • yum -y install ffmpeg ffmpeg-devel mplayer mencoder flvtool2
  3. Manually, install FFmpeg-Php

If FFmpeg-Php is compiled successfully, an ffmpeg.so module will be generated and copied into the default Php directory. Next,�run the following command to enable FFmpeg-Php. By running this command you will be�addingffmpeg.so module into the�php.ini file:

echo ‘extension=ffmpeg.so’ >> /local_path_to_your/php.ini

Final step, restart apache

service httpd restart
OR
/etc/init.d/httpd restart

– Testing FFmpeg

Verify that FFmpeg is working properly by running the following two commands:

  • php -r ‘phpinfo();’ | grep ffmpeg

You will get a few lines similar to the following:

ffmpeg
ffmpeg-php version => 0.6.0-svn
ffmpeg-php built on => April� 15 2010 15:31:45
ffmpeg-php gd support� => enabled
ffmpeg libavcodec version => Lavc51.62.0
ffmpeg libavformat version => Lavf52.18.0
ffmpeg swscaler => disabled
ffmpeg.allow_persistent => 0 => 0
ffmpeg.show_warnings => 0 => 0

This is the second command to make sure that FFmpeg is working properly:

  • /usr/local/bin/ffmpeg

If you do not get any errors after running the test commands above, FFmpeg, FFmpeg-Php, MPlayer, MEncoder, and FLV2tool are working properly on your server. CONGRATULATIONS!

Method #1: Source archives/packages

*** Caution

  • You must remove all previous installation of FFmpeg and FFmpeg-Php, then follow installation instructions below.
  • Follow these steps (in that order):

First, make sure the following binary packages are installed on your server:

gcc, gcc4, gcc4-c++, gcc4-gfortran, gd, gd-devel, gmake, ImageMagick, ImageMagick-devel, libcpp, libgcc, libstdc++, make, ncurses, ncurses-devel, ruby, subversion

If any of these packages are missing, install them using Yum . For example:

  • yum install PACKAGE

*** Caution

  • The following source packages are always updated with newer versions. You might experience technical issues if you download and install a newer/older version of any of these applications.
  • You must remove all previous installation of FFmpeg and FFmpeg-Php, then follow installation instructions below.

To install FFmpeg from source, execute the following commands (in that order).

  1. Let’s create a directory to do our work in:
    • mkdir /usr/local/src
    • cd /usr/local/src
  2. Download source packages
  3. Extract source packages
    • tar xzf a52dec-0.7.4.tar.gz
    • tar jxvf amrnb-7.0.0.2.tar.bz2
    • tar jxvf amrwb-7.0.0.2.tar.bz2
    • tar jxvf essential-ppc-20071007.tar.bz2
    • tar jxvf faac-1.28.tar.bz2
    • tar xzf faad2-2.7.tar.gz
    • tar jxvf ffmpeg-php-0.6.0.tbz2
    • tar zxvf flvtool2-1.0.6.tgz
    • tar xzf lame-3.98.4.tar.gz
    • tar xzf libogg-1.1.4.tar.gz
    • tar jxvf libtheora-1.1.1.tar.bz2
    • tar xzf libvorbis-1.2.2.tar.gz
    • tar xzf re2c-0.13.5.tar.gz
    • tar xzf xvidcore-1.1.3.tar.gz
    • tar jxvf x264-snapshot-20080324-2245.tar.bz2
  4. Create the codecs directory & export files
    • mkdir /usr/local/lib/codecs
    • mv /usr/local/src/essential-ppc-20071007/* /usr/local/lib/codecs
    • chmod -R 755 /usr/local/lib/codecs
    • echo “/usr/local/lib” >> /etc/ld.so.conf
    • ldconfig
  5. Install SVN and Ruby (for RedHat/CentOS v5.x)
    • yum install subversion
    • yum install ruby
      OR (if you are using the cPanel control panel)

      • /scripts/installruby
      • /usr/local/cpanel/bin/ror_setup
    • yum install ncurses-devel
  6. Compile and install FLVtool2
    • cd /usr/local/src/flvtool2-1.0.6/
    • ruby setup.rb config
    • ruby setup.rb setup
    • ruby setup.rb install
  7. Compile and install LAME
    • cd /usr/local/src/lame-3.98.4
    • ./configure
    • make
    • make install
  8. Compile and install libOGG
    • cd /usr/local/src/libogg-1.1.4
    • ./configure
    • make
    • make install
    • PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    • export PKG_CONFIG_PATH
  9. Compile and install LibVorbis
    • cd /usr/local/src/libvorbis-1.2.2
    • ./configure
    • make
    • make install
  10. Compile and install Libtheora
    • cd /usr/local/src/libtheora-1.1.1
    • ./configure –with-ogg-libraries=/usr/local/lib/
    • make
    • make install
  11. Compile and install amrNB
    • cd /usr/local/src/amrnb-7.0.0.2
    • ./configure
    • make
    • make install
  12. Compile and install amrWB
    • cd /usr/local/src/amrwb-7.0.0.2
    • ./configure
    • make
    • make install
  13. Compile and install Liba52
    • cd /usr/local/src/a52dec-0.7.4
    • ./bootstrap
    • ARCh=’arch’
    • ./configure –enable-shared
    • make
    • make install
  14. Compile and install FAAC
    • cd /usr/local/src/faac-1.28
    • ./bootstrap
    • ./configure –with-mp4v2
    • make
    • make install
  15. Compile and install FAAD
    • cd /usr/local/src/faad2-2.7
    • ./configure –with-mpeg4ip
    • make
    • make install
  16. Compile and install XVIDCore
    • cd /usr/local/src/xvidcore/build/generic/
    • ./configure
    • make
    • make install
  17. Compile and Install�X264 Snapshot
    • cd /usr/local/src/x264-snapshot-20080324-2245
    • ./configure –enable-shared
    • make
    • make install
  18. Compile and install RE2C
    • cd /usr/local/src/re2c-0.13.5
    • ./configure
    • make
    • make install
    • cp -aP /usr/local/bin/re2c /usr/bin/
  19. Download the latest release for FFmpeg and MPlayer from svn.mplayerhq.hu
    • cd /usr/local/src
    • svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg -r 15594
    • svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
    • svn update
  20. Compile and install MPlayer
    • cd /usr/local/src/mplayer
    • ./configure
    • make

    (STOP here.) Make sure MPlayer has been compiled successfully with NO errors. Do NOT proceed any further unless the MPlayer package has been compiled successfully.

    • make install
  21. Compile and install FFmpeg
    • cd /usr/local/src/ffmpeg/
    • mkdir /usr/local/src/ffmpeg/tmp
    • export TMPDIR=/usr/local/src/ffmpeg/tmp

    (The following ./configure command is one single line)

    • ./configure –enable-shared –enable-nonfree –enable-gpl –enable-pthreads –enable-liba52 –enable-libamr-nb –enable-libamr-wb –enable-libfaac –enable-libfaad –enable-libmp3lame –enable-libtheora –enable-libvorbis –enable-libx264 –enable-libxvid –enable-cross-compile
    • make

    (STOP here.) Make sure FFmpeg has been compiled successfully with NO errors. Do NOT proceed any further unless the FFmpeg package has been compiled successfully.

    • make install
    • export LD_LIBRARY_PATH=/usr/local/lib/
  22. Finalize the codec setups:
    (Create symbolic links for the following modules. FYI: the number which comes after the extension *.so might differ from one server to another. The X‘s represent numbers. The number after *.so.5 must match the number after the *.so.5 at the end of the line.)

    • ln -s /usr/local/lib/libavformat.so.5X.XX.0 /usr/lib/libavformat.so.5X
    • ln -s /usr/local/lib/libavcodec.so.5X.XX.0 /usr/lib/libavcodec.so.5X
    • ln -s /usr/local/lib/libavutil.so.49.X.0 /usr/lib/libavutil.so.49
    • ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
    • /sbin/ldconfig
  23. Compile and install FFmpeg-Php
    • cd /usr/local/src/ffmpeg-php-0.6.0/
    • /usr/bin/phpize
    • ./configure
    • make

    (STOP here.) Make sure FFmpeg-Php has been compiled successfully with NO errors. Do NOT proceed any further unless the FFmpeg-Php package has been compiled successfully.

    • make install
      Verify that ffmpeg-php module is saved in the Php extensions directory by running:
    • ls -al /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so
  24. Add FFmpeg-Php module directive in php.ini file: (make sure the local path to your php.ini is correct.)
    • echo ‘extension=ffmpeg.so’ >> /usr/local/lib/php.ini
  25. Restart Apache to load FFmpeg-Php (for RedHat/CentOS v5.x)
    • service httpd restart

– Testing FFmpeg
Verify that FFmpeg is working properly by running the following two commands:

  • php -r ‘phpinfo();’ | grep ffmpeg

You will get a few lines similar to the following:

ffmpeg
ffmpeg-php version => 0.6.0-svn
ffmpeg-php built on => April� 15 2010 15:31:45
ffmpeg-php gd support� => enabled
ffmpeg libavcodec version => Lavc51.62.0
ffmpeg libavformat version => Lavf52.18.0
ffmpeg swscaler => disabled
ffmpeg.allow_persistent => 0 => 0
ffmpeg.show_warnings => 0 => 0

This is the second command to make sure that FFmpeg is working properly:

  • /usr/local/bin/ffmpeg

If you do not get any errors after running the test commands above, FFmpeg, FFmpeg-Php, MPlayer, MEncoder, FLV2tool, LAME MP3 encoder & libOGG are working properly.