Installing FFMPEG & FFMPEG-PHP from source

by admin on April 15, 2011

in Http Maid Note

This thing’s quite confusing me when i was trying to install FFMPEG and FFMPEG-PHP extension. You know it was always very easy if you’re install it from yum or rpm, but CentOS even EPEL doesn’t provide FFMPEG in their repository, so it is a bit bothering me if i had to use repository other than CentOS or EPEL, and that’s why i’m trying to install it from source. I was googling and found a lot of ‘how to’ about this, but they didn’t give a complete tutorial, also when there’s an error in dependency, i had to googling again until i found the solution. I had succeeded installing FFMPEG and FFMPEG-PHP extension both on 32bit / 64bit CentOS 5.6 and Ubuntu 10.10 Maverick, here’s the tutorial and the errors with solutions during the process of me installing FFMPEG.

I assume that your box is already installed with PHP, here as the example i’m using preinstalled NginX, MySQL, PHP from NginX Auto Installer without FFMPEG. First we’re going to install codecs and dependencies, after that FFMPEG and FFMPEG-PHP.

note:
Lib directory CentOS 32bit is /usr/lib
Lib directory CentOS 64bit is /usr/lib64
Lib directory Ubuntu 32bit and 64bit is /usr/lib64

YASM

wget http://pkgs.serversreview.net/files/yasm-1.1.0.tar.gz
tar -zxvf yasm-1.1.0.tar.gz
cd yasm-1.1.0
./configure --prefix=/usr --libdir=/usr/lib
make
make install


x264
You can download the files using git clone

git clone git://git.videolan.org/x264

or direct download all files, i’ve already download and compress it

wget http://pkgs.serversreview.net/files/x264.tar.gz
tar -zxvf x264.tar.gz
cd x264
./configure --prefix=/usr --libdir=/usr/lib --enable-shared --enable-pic --enable-visualize
make
make install

mp4v2

wget http://pkgs.serversreview.net/files/mp4v2-1.9.1.tar.bz2
tar -jxvf mp4v2-1.9.1.tar.bz2
cd mp4v2-1.9.1
./configure --prefix=/usr --libdir=/usr/lib
make
make install

FAAC

wget http://pkgs.serversreview.net/files/faac-1.28.tar.gz
tar -zxvf faac-1.28.tar.gz
cd faac-1.28
./configure --prefix=/usr --libdir=/usr/lib --with-mp4v2
make
make install

If you’re using Ubuntu, you might get this error when executing ‘make’ command

/usr/include/string.h:369: error: ambiguates old declaration ‘const char* strcasestr(const char*, const char*)’

and the solution is removing line ‘126’ from ‘common/mp4v2/mpeg4ip.h’

char *strcasestr(const char *haystack, const char *needle);

after that, make clean and repeat the install commands

make clean
./configure --prefix=/usr --libdir=/usr/lib --with-mp4v2
make
make install

LAME MP3 Encoder

wget http://pkgs.serversreview.net/files/lame-3.98.4.tar.gz
tar -zxvf lame-3.98.4.tar.gz
cd lame-3.98.4
./configure --prefix=/usr --libdir=/usr/lib --enable-nasm --enable-efence --enable-decode-layer1 --enable-mp3x --enable-mp3rtp
make
make install

opencore-amr

wget http://pkgs.serversreview.net/files/opencore-amr-0.1.2.tar.gz
tar -zxvf opencore-amr-0.1.2.tar.gz
cd opencore-amr-0.1.2
./configure --prefix=/usr --libdir=/usr/lib
make
make install

Ogg

wget http://pkgs.serversreview.net/files/libogg-1.1.4.tar.gz
tar -zxvf libogg-1.1.4.tar.gz
cd libogg-1.1.4
./configure --prefix=/usr --libdir=/usr/lib
make
make install

Vorbis Audio Compression

wget http://pkgs.serversreview.net/files/libvorbis-1.2.3.tar.gz
tar -zxvf libvorbis-1.2.3.tar.gz
cd libvorbis-1.2.3
./configure --prefix=/usr --libdir=/usr/lib
make
make install

Simple DirectMedia Layer

wget http://pkgs.serversreview.net/files/SDL-1.2.14.tar.gz
tar -zxvf SDL-1.2.14.tar.gz
cd SDL-1.2.14
./configure --prefix=/usr --libdir=/usr/lib --enable-ipod --enable-x11-shared --enable-video-carbon
make
make install

another error might be happened if you’re using Ubuntu

./src/video/x11/SDL_x11dyn.h:45: fatal error: X11/extensions/XShm.h: No such file or directory

the solution is install xorg-dev

apt-get install xorg-dev

and then run the installation again, but first don’t forget to run ‘make clean’

make clean
./configure --prefix=/usr --libdir=/usr/lib --enable-ipod --enable-x11-shared --enable-video-carbon
make
make install

Theora Video Compression

wget http://pkgs.serversreview.net/files/libtheora-1.1.1.zip
unzip libtheora-1.1.1.zip
cd libtheora-1.1.1
./configure --prefix=/usr --libdir=/usr/lib
make
make install

VP8 Codec SDK

git clone git://review.webmproject.org/libvpx.git

or

wget http://pkgs.serversreview.net/files/libvpx.tar.gz
tar -zxvf libvpx.tar.gz
cd libvpx
./configure --prefix=/usr --libdir=/usr/lib --enable-shared --enable-pic --enable-debug --enable-gprof --enable-gcov --enable-vp8 --enable-mem-tracker
make
make install

Xvid

wget http://pkgs.serversreview.net/files/xvidcore-1.3.1.tar.gz
tar -zxvf xvidcore-1.3.1.tar.gz
cd xvidcore/build/generic
./configure --prefix=/usr --libdir=/usr/lib
make
make install

FFMPEG
Download the files using git

git clone git://git.videolan.org/ffmpeg.git ffmpeg

or directly

wget http://pkgs.serversreview.net/files/ffmpeg.tar.gz
tar -zxvf ffmpeg.tar.gz
cd ffmpeg
./configure --prefix=/usr --libdir=/usr/lib --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-x11grab --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid
make
make install

Okay, FFMPEG installation has been completed, check whether FFMPEG is working or not with ‘ffmpeg’ command

root@server3:~# ffmpeg
FFmpeg version UNKNOWN, Copyright (c) 2000-2011 the FFmpeg developers
  built on Apr 15 2011 20:15:13 with gcc 4.4.5
  configuration: --prefix=/usr --libdir=/usr/lib --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-x11grab --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid
  libavutil    50. 40. 0 / 50. 40. 0
  libavcodec   52.116. 0 / 52.116. 0
  libavformat  52.104. 0 / 52.104. 0
  libavdevice  52.  4. 0 / 52.  4. 0
  libavfilter   1. 76. 0 /  1. 76. 0
  libswscale    0. 13. 0 /  0. 13. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfi
le}...

Use -h to get full help or, even better, run 'man ffmpeg'

for FFMPEG supported formats and other commands, you can use the following commands

ffmpeg -format
ffmpeg --help

FFMPEG-PHP
If you are using CentOS 64bit, it is better to check libav, libpostproc, and libswscale location before starts install FFMPEG-PHP extension, if they’re located in /usr/lib directory then symlink to /usr/lib64 directory

ln -s /usr/lib/libav* /usr/lib64
ln -s /usr/lib/libpostproc.* /usr/lib64
ln -s /usr/lib/libswscale.* /usr/lib64

now install the FFMPEG-PHP extension

wget http://pkgs.serversreview.net/files/ffmpeg-php-0.6.0.tar.gz
tar -zxvf ffmpeg-php-0.6.0.tar.gz
cd ffmpeg-php-0.6.0
phpize
./configure --prefix=/usr --libdir=/usr/lib --with-ffmpeg --with-pic
make
make install

after that add the following line to php.ini

extension="ffmpeg.so"

and then restart your PHP

/etc/init.d/php-fpm restart

or

/etc/init.d/php-fastcgi restart

or

/etc/init.d/php-fcgi restart

or

/etc/init.d/httpd restart

or

/etc/init.d/apache2 restart

Voila!!!

FFMPEG-PHP

That’s it, FFMPEG and FFMPEG-PHP extension is now ready to roll! If there’s something missing or problems, let’s discuss!

{ 13 comments… read them below or add one }

Leave a Comment

Previous post:

Next post: