Saturday, November 21, 2009

Installing FFMPEG on Centos

This is a bit troublesome work. I spent around 9 hours banging my head with ffmpeg and did many tries to install this. And there are alot of guides for this and ***I was honored*** to install using a few of them :P. I am compiling here the set of commands that worked for me and I will also include a few alternatives in some cases and solutions to some problem which may arise.

/*********Only for beginners***********/
First of all a very little introduction to installing FFMPEG. We will be follow these procedures:
  1. We will first download the required packages (different libs and extensions). These include::: mplayer, flvtool2, lame, libogg, libvorbis, ffmpeg-php etc.
  2. The above packages are in compressed form so we will uncompress those.
  3. The uncompressed set of files are source for those, so we will compile and build them.
  4. At the end we will configure these with our apache.

To download wget is used.
e.g. wget --no-check-certificate https://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
To extract, we use:
tar -xjf amrwb-7.0.0.3.tar.bz2 etc
To compile we use:
./configure
make
make install
This will make its binaries.
/******end of Only for beginners******/

/******Real stuff starts here*********/

First of all get all the packages we need:
//Better make a separate folder for this stuff here:::
wget http://www3.mplayerhq.hu/MPlayer/releases/codecs/essential-20071007.tar.bz2
wget --no-check-certificate https://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
wget http://biznetnetworks.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.6.0.tbz2
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.4.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.3.tar.gz
wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-7.0.0.3.tar.bz2
(If any of the above links are expired, you may just search google for these, but prefer using the latest version. An IMPORTANT note, use ffmpeg-php-0.6.0. Older version will make problems. This solves most of the issues.

Now extract them all.
tar -xjf amrwb-7.0.0.3.tar.bz2
tar -xjf essential-20071007.tar.bz2
tar -xjf ffmpeg-php-0.6.0.tbz2
tar -xzf flvtool2-1.0.6.tgz
tar -xzf lame-398-2.tar.gz
tar -xzf libogg-1.1.4.tar.gz
tar -xzf libvorbis-1.2.3.tar.gz
Now make directory for codecs and move them there.
mkdir /usr/local/lib/codecs
mv essential-20071007/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/
We will now download MPlayer and FFMPEG using SVN and update.
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk mplayer
cd mplayer/
svn update
IMPORTANT: Download these both from SVN, by other ways it will give error (I got them).

If you do not have SVN, you can install it using:
yum install subversion
yum install ruby
yum install ncurses-devel
or you can use apt-get too
Some guides asked to update configuration file too. But for me it worked without it. To update libs use vi
vi /etc/ld.so.conf
It will open up vi editor. Add the following line:
/usr/local/lib
and then load config file using
ldconfig -v
Now make all other libs

cd amrwb-7.0.0.3
./configure
make
make install

cd ../flvtool2-1.0.6
ruby setup.rb config && ruby setup.rb setup && ruby setup.rb install

cd ../lame-398-2
./configure
make
make install

cd ../libogg-1.1.4
./configure
make
make install

ldconfig -v

cd ../libvorbis-1.2.3
./configure
make
make install

cd ../mplayer/
./configure
make
make install

cd ../ffmpeg
./configure --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared
make
make install
Here, you may have problem with ffmpeg. I was having some issues with libvorbis. I first tried it by removing this. It works but you may need libvorbis. You may try using other version of vorbis we downloaded above. FFMPEG will take some time too on ./configure and make.
Also some of the guides used
echo '#define HAVE_LRINTF 1' >> config.h
after configure. I didn't use it but I think it will help.

Now add links to codecs:
ln -s /usr/local/lib/libavformat.so.52 /usr/lib/libavformat.so.52
ln -s /usr/local/lib/libavcodec.so.52 /usr/lib/libavcodec.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/libamrwb.so.3 /usr/lib/libamrwb.so.3
Now here comes an IMPORTANT part. This is a must do, it solved my all issues :P
Goto ffmpeg-php and edit ffmpeg_frame.c

cd ../ffmpeg-php-0.6.0
vi ffmpeg_frame.c
Now run this command:
:%s/PIX_FMT_RGBA32/PIX_FMT_RGB32
save and quit. Use :wq for this.

Now in the same folder (i.e. ffmpeg-php-0.6.0) do the following.
phpize
./configure
make
make install
Now major stuff is done. We just have to add the php extension to php.ini file. You will first need to locate php.ini. You may find it in /etc/
vi /etc/php.ini
Add this line at the end
extension=ffmpeg.so
Ok, all done now. Just restart the server and check phpinfo for ffmpeg extension.
To restart use:
/etc/init.d/httpd restart
You can also use your server's cpanel/plesk for restarting the service.

Now to test you may run php command for phpinfo. Use this:
php -r 'phpinfo();' | grep ffmpeg
You should get version info and build date etc.
ffmpeg
ffmpeg-php version => 0.6.0-svn
ffmpeg-php built on => Nov 21 2009 23:35:23
ffmpeg-php gd support => enabled
ffmpeg libavcodec version => Lavc52.32.0
ffmpeg libavformat version => Lavf52.36.0
ffmpeg swscaler version => SwS0.7.1
ffmpeg.allow_persistent => 0 => 0
ffmpeg.show_warnings => 0 => 0
PWD => /usr/src/ffmpeg-php-0.6.0
_SERVER["PWD"] => /usr/src/ffmpeg-php-0.6.0
_ENV["PWD"] => /usr/src/ffmpeg-php-0.6.0
I will discuss a serious error in another post.

No comments:

Post a Comment

Developer Instincts