Compiling FFMpeg on Centos 5
a procedural guide to getting ffmpeg to work with webm, mp4(x264) and ogg(theora) output
**Updated May 24th 2011 to change to ffmpeg git repository per comments.This is a highly technical guide to how we managed to install ffmpeg on several CentOS 5.5 32 and 64bit platforms to achieve an effective modern web video transcoder.
For those struggling to figure out how to get ffmpeg to install and to have it work with as many input video formats as possible, we hope this guide saves you some time. It took us roughly a month of searching, trial and error, and tests to eventually get this to work over a period of a year on and off.
Some Assumptions:
1) CentOS5.x 32 or 64 bit This may work for other platforms - probably should on RHEL and Fedora, but I have only tested it on CentOS.
2) Minimal extra repositories We know you can add yum repos that will give you ffmpeg, our goal here was a finer level of control and to get the latest latest libraries and svn of ffmpeg itself - also to keep our CentOS yum repo as clean as possible. Therefore - this is taking the long/manual way around.
3) If ffmpeg fails - CLEAN IT if you hit an error trying to build ffmpeg (we certainly hope you won't) be sure to completely clean that folder out (heck, I'd suggest even just re-grabbing the snapshot again) because you start to get unusual errors when you try to build on top of a failed build even if you "make clean" first.
4) Video Encoding Tests The video encoding tests at the bottom of the procedure were our own tests comprising videos we have had troubles encoding in the past. You can obviously replace these with your own test videos, we only left the command lines in there for your reference. These are not necessarily sane values and switches for encoding ffmpeg for the web - we're still researching the best solutions for that - they are merely tests to see if it works.
5) The ffmpeg SVN Works is it working right now, it may not when you try this - you should be able to switch to the ffmpeg release 0.61 if the svn download failes to work. That had just been released when these guide was prepared so we expect it will serve as a baseline for a functioning code base to use.
6) VERSIONS CHANGE!!!! to simplify things we have added a lot of direct download links for various libraries - if you are working through this guide and more then a month or two has elapsed since it was written (October 20th 2010) you should check if newer versions of the various libraries are available. As time passes this guide will obviously become obsolete.
##################################################
# FFMPEG Install Notes: 2010-10-20
#
# This install of FFMPEG has been designed to work on CentOS 5 platforms.
# It have installed several systems 32 and 64 bit as well as on the EC2 cloud using this procedure.
#
# The goal here was to generate a web-focuse FFMPEG install that will read as many different formats as possible
# and output to x264, webm, and ogg suitable for HTML5 web-based and mobile delivery.
# If this is roughly your need then hopefully this procedure will help you as it took me several days to sort
# it all out and get everything working.
#
# The following "scripted" install is designed to be manually copy and pasted
# Watch each step and check for errors.
#
###################################################
#
# Might Be Required:
# If you don't already have the epel repository
# note: several install guides suggest adding other repositories - this procedure attempts
# a manual compilation of ffmpeg specifically to avoid adding extra repositories that may
# cause other problems with CentOS - thus only the epel and centos repos are assumed here.
#
wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm -Uvh epel-release-5*.rpm
#
##################################################
# If you already have epel start here:
# First Download all required libraries
#
git clone git://git.videolan.org/ffmpeg.git ffmpeg
wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz
wget http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2
wget http://downloads.xvid.org/downloads/xvidcore-1.2.2.tar.gz
wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
wget http://downloads.sourceforge.net/faac/faad2-2.7.tar.gz
wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
wget http://downloads.sourceforge.net/project/libraw1394/libraw1394/libraw1394-2.0.5.tar.gz
wget http://downloads.sourceforge.net/project/libdc1394/libdc1394-2/2.1.2/libdc1394-2.1.2.tar.gz
wget http://downloads.sourceforge.net/project/opencore-amr/opencore-amr/0.1.2/opencore-amr-0.1.2.tar.gz
wget http://www3.mplayerhq.hu/MPlayer/releases/codecs/essential-20071007.tar.bz2
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
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
yum install yasm nasm
yum install php-devel
yum install libvpx*
yum install git
git clone git://git.videolan.org/x264.git
tar -zxf lame-3.98.4.tar.gz
tar -zxf xvidcore-1.2.2.tar.gz
tar -jxf ffmpeg-php-0.6.0.tbz2
tar -zxf a52dec-0.7.4.tar.gz
tar -zxf faad2-2.7.tar.gz
tar -zxf faac-1.28.tar.gz
tar -zxf libraw1394-2.0.5.tar.gz
tar -zxf libdc1394-2.1.2.tar.gz
tar -zxf opencore-amr-0.1.2.tar.gz
tar -jxf essential-20071007.tar.bz2
tar -jxf libtheora-1.1.1.tar.bz2
tar -zxf libogg-1.1.4.tar.gz
tar -zxf libvorbis-1.2.3.tar.gz
mkdir /usr/local/lib/codecs/
cp ./essential-20071007/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/
##############
# For 64 Bit Systems ALSO do this:
#
mkdir /usr/local/lib64/codecs/
cp ./essential-20071007/* /usr/local/lib64/codecs/
chmod -R 755 /usr/local/lib64/codecs/
##############
cd x264
./configure --enable-shared
make
make install
cd ..
cd xvidcore/build/generic
./configure
make
make install
cd ../../../
cd lame-3.98.4
./configure
make
make install
cd ..
cd a52dec-0.7.4
./configure --enable-shared=PKGS
make
make install
cd ..
cd faad2-2.7
autoreconf -vif
./configure
make
make install
cd ..
cd faac-1.28
./bootstrap
./configure
make
make install
cd ..
cd libraw1394-2.0.5
./bootstrap
./configure
make
make install
cd ..
cd libdc1394-2.1.2
./configure
make
make install
cd ..
cd opencore-amr-0.1.2
./configure
make
make install
cd ..
cd libogg-1.1.4
./configure
make
make install
cd ..
cd libvorbis-1.2.3
./configure
make
make install
cd ..
cd libtheora-1.1.1
./configure
make
make install
cd ..
export LD_LIBRARY_PATH=/usr/local/lib/
echo /usr/local/lib > /etc/ld.so.conf.d/custom-libs.conf
ldconfig
cd ffmpeg
./configure --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --disable-ffplay --enable-shared --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --extra-cflags=-fPIC
make
make install
cd ..
ldconfig
##################################################
#
# The following is to add ffmpeg-php if you need that
#
#
cd ffmpeg-php-0.6.0
######################################################
# For version 0.6.0 fix a typo in the framer function:
# Copy & Paste each line seperately
vi ffmpeg_frame.c
:%s/PIX_FMT_RGBA32/PIX_FMT_RGB32
:wq
######################################################
phpize
./configure
make
make install
cd ..
#
# your php.ini may be somewhere else:
#
vi /etc/into php.ini
# add the line:
extension=ffmpeg.so
:wq
#
/etc/rc.d/init.d/httpd restart
##################################################
# Encoding Tests
#
# The following assume 5 source video files exist in the current directory.
# This part was added to test several video files that have caused problems in the past as a baseline and
# to prove the various encoding outputs can handle them.
#
# alien.mpg
# soccer.flv
# scratch.wmv
# pump.asf
# recent.mp4
#
#############################################
# MPEG Source
# Baseline MP4
ffmpeg -i alien.mpg -vcodec libx264 -vpre main -b 340000 -bt 400000 -threads 0 -y alienBase.mp4
# iPod MP4
ffmpeg -i alien.mpg -acodec libfaac -ab 96000 -vcodec libx264 -vpre slow -vpre ipod640 -b 348160 -bt 524288 -aspect 16:9 -threads 0 -f ipod -y alienPod.mp4
# WebM
ffmpeg -i alien.mpg -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y alienWeb.webm
# Ogg Vorbis
ffmpeg -i alien.mpg -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y alienWeb.ogg
#############################################
# FLV Source
# iPod MP4
ffmpeg -i soccer.flv -acodec libfaac -ab 96000 -vcodec libx264 -vpre slow -vpre ipod640 -b 348160 -bt 524288 -aspect 16:9 -threads 0 -f ipod -y soccerPod.mp4
# WebM
ffmpeg -i soccer.flv -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y soccerWeb.webm
# Ogg Vorbis
ffmpeg -i soccer.flv -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y soccerWeb.ogg
#############################################
# WMV Source
# iPod MP4
ffmpeg -i scratch.wmv -acodec libfaac -ab 96000 -vcodec libx264 -vpre slow -vpre ipod640 -b 348160 -bt 524288 -aspect 16:9 -threads 0 -f ipod -y scratchPod.mp4
# WebM
ffmpeg -i scratch.wmv -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y scratchWeb.webm
# Ogg Vorbis
ffmpeg -i scratch.wmv -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y scratchWeb.ogg
#############################################
# ASF Source
# iPod MP4
ffmpeg -i pump.asf -acodec libfaac -ab 96000 -vcodec libx264 -vpre slow -vpre ipod640 -b 348160 -bt 524288 -aspect 16:9 -threads 0 -f ipod -y pumpPod.mp4
# WebM
ffmpeg -i pump.asf -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y pumpWeb.webm
# Ogg Vorbis
ffmpeg -i pump.asf -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y pumpWeb.ogg
#############################################
# mp4 Source
# iPod MP4
ffmpeg -i recent.mp4 -acodec libfaac -ab 96000 -vcodec libx264 -vpre slow -vpre ipod640 -b 348160 -bt 524288 -aspect 16:9 -threads 0 -f ipod -y recentPod.mp4
# WebM
ffmpeg -i recent.mp4 -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y recentWeb.webm
# Ogg Vorbis
ffmpeg -i recent.mp4 -b 348160 -bt 524288 -acodec libvorbis -ab 96000 -threads 0 -y recentWeb.ogg