I’ve spent a bit of time working with Amazon EC2 recently. One of the things I’ve been working on is getting a stable build of FFMPEG and FFMPEG-PHP running on a Fedora 8 image in Amazon EC2. This is essentially going to be a tutorial to get things up and running. Of course, your milage may vary.
These instructions apply to a 32-bit Fedora 8 installation. The hardware I primarily use happens to be on EC2, but these instructions aren’t specific to EC2. You may need to tweak things a smidge for an x64 system.
Preparing the LAMP stack (and a few other things)
For FFMPEG-PHP to work, you need to have a web server with PHP support up and running. You’ll definitely need GD for image processing and mbstring is helpful in conjunction with PHP5’s built-in iconv support for managing multiple character sets in ID3 tags.
-
Install PHP, necessary extensions and supporting software.
yum -y install \ php-devel \ php-gd \ php-mbstring \ gcc \ gcc-c++ \ libtool \ svn \ git \ yasm \ gsm-devel \ libogg-devel \ libvorbis-devel \ libtheora-devel \ ;
-
Also, I like to create a directory with symlinks to important files so that I can access everything more efficiently. These will be used throughout this tutorial.
mkdir /www-config; \ ln -s /etc/init.d/httpd /www-config/httpd; \ ln -s /etc/httpd/conf/httpd.conf /www-config/httpd.conf; \ ln -s /var/log/httpd/ /www-config/logs; \ ln -s /usr/lib/php/modules/ /www-config/php5-extensions; \ ln -s /etc/httpd/conf.d/php.conf /www-config/php.conf; \ ln -s /etc/httpd/conf.d/ /www-config/apache-conf; \ ln -s /etc/php.ini /www-config/php.ini; \ ln -s /etc/php.d/ /www-config/php-ini; \ ln -s /var/www/html/ /www-config/public-html; \ /www-config/httpd restart;
PHP 5.x should now be installed and you should have a directory prepared that lets you easily access important files for managing your configuration.
Installing FFMPEG
FFMPEG can be fairly complicated to get running properly, so here’s what I’ve gotten working thus far.
-
Download FFMPEG source. Export the latest FFMPEG trunk from Subversion, then change to the source directory.
svn export svn://svn.mplayerhq.hu/ffmpeg/trunk /ffmpeg-trunk-source; \ cd /ffmpeg-trunk-source;
-
Install x264. Export the latest x264 trunk from Git. Enter the directory, make, install, and go back to the parent directory.
git clone git://git.videolan.org/x264.git; \ cd x264; \ ./configure --prefix=/usr --enable-shared --enable-pthread; \ make; \ make install; \ cd ..;
-
Install liba52. Download the latest version of liba52 (Currently 0.7.4). Decompress the package, enter the directory, run configure, make, install, and go back to the parent directory.
wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz; \ tar -zxvf a52dec-0.7.4.tar.gz; \ cd a52dec-0.7.4; \ ./configure --prefix=/usr --enable-double; \ make; \ make install; \ cd ..;
-
Install FAAC. Download the latest version of FAAC (Currently 1.26). Decompress the package, enter the directory, create the configure file, run configure, make, install, and go back to the parent directory.
wget http://downloads.sourceforge.net/faac/faac-1.26.tar.gz; \ tar -zxvf faac-1.26.tar.gz; \ cd faac; \ autoreconf -vif; \ ./configure --prefix=/usr; \ make; \ make install; \ cd ..;
-
Install FAAD. Download the latest version of FAAD (Currently 2.6.1). Decompress the package, enter the directory, create the configure file, run configure, make, install, and go back to the parent directory.
wget http://downloads.sourceforge.net/faac/faad2-2.6.1.tar.gz; \ tar -zxvf faad2-2.6.1.tar.gz; \ cd faad2; \ autoreconf -vif; \ ./configure --prefix=/usr; \ make; \ make install; \ cd ..;
-
Install LAME. Download the latest version of LAME (Currently 3.98b8). Decompress the package, enter the directory, run configure, make, install, and go back to the parent directory.
wget http://downloads.sourceforge.net/lame/lame-3.98b8.tar.gz; \ tar -zxvf lame-3.98b8.tar.gz; \ cd lame-3.98b8; \ ./configure --prefix=/usr; \ make; \ make install; \ cd ..;
-
Install libmpeg2. Download the latest version of libmpeg2 (Currently 0.4.1). Decompress the package, enter the directory, run configure, make, install, and go back to the parent directory.
wget http://libmpeg2.sourceforge.net/files/mpeg2dec-0.4.1.tar.gz; \ tar -zxvf mpeg2dec-0.4.1.tar.gz; \ cd mpeg2dec-0.4.1; \ ./configure --prefix=/usr; \ make; \ make install; \ cd ..;
-
Install Xvid. Download the latest version of Xvid (Currently 1.1.3). Decompress the package, enter the directory, run configure, make, install, and go back to the parent directory.
wget http://downloads.xvid.org/downloads/xvidcore-1.1.3.tar.gz; \ tar -zxvf xvidcore-1.1.3.tar.gz; \ cd xvidcore-1.1.3/build/generic; \ ./configure --prefix=/usr; \ make; \ make install; \ cd ../../../;
-
Install AMR/3GPP. Download the latest version of AMR (Currently 7.0.0.1). Decompress the package, enter the directory, run configure, make, install, and go back to the parent directory.
wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-7.0.0.1.tar.bz2; \ tar -jxvf amrnb-7.0.0.1.tar.bz2; \ cd amrnb-7.0.0.1; \ ./configure --prefix=/usr; \ make; \ make install; \ cd ../;
-
Compile FFMPEG. Configure, make, and install the software, including all options that enable enhanced functionality.
./configure \ --prefix=/usr \ --enable-static \ --enable-gpl \ --enable-nonfree \ --enable-postproc \ --enable-avfilter \ --enable-avfilter-lavf \ --enable-liba52 \ --enable-liba52bin \ --enable-libamr-nb \ --enable-libfaac \ --enable-libfaad \ --enable-libfaadbin \ --enable-libgsm \ --enable-libmp3lame \ --enable-libtheora \ --enable-libvorbis \ --enable-libx264 \ --enable-libxvid \ ; make; make install;
Installing FFMPEG-PHP
Once you have FFMPEG functioning properly, you can install the FFMPEG-PHP extension.
-
Download and install FFMPEG-PHP source. Enter the directory, download the source, run phpize, configure, make, install, and go back to the parent directory.
cd /ffmpeg-trunk-source; \ wget http://downloads.sourceforge.net/ffmpeg-php/ffmpeg-php-0.5.3.1.tbz2; \ tar -jxvf ffmpeg-php-0.5.3.1.tbz2; \ cd ffmpeg-php-0.5.3.1; \ phpize; \ ./configure --prefix=/usr; \ make; \ make install; \ cd ..;
-
Add FFMPEG-PHP to the PHP configuration.
echo "extension=ffmpeg.so" > /www-config/php-ini/ffmpeg.ini
-
Restart Apache.
/www-config/httpd restart
All done!
FFMPEG and FFMPEG-PHP should now be installed and ready to go. Make sure to check your error log if something isn’t working properly.
cat /www-config/logs/error_log