search
Innovative Web Design and Application Development
PawPrint.net

PawPrint.net News

October 20th, 2010
October 20th, 2010

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



Share this:
Comments (22 )
Great tutorial! Thatīs the fastest Iīve *ever* gotten FFMPEG installed!
November 15th, 2010 00:14:04
I trying to install ffmpeg for a Joomla site hosted on ClearOS 5.2....which uses CentOS/RedHat as its base.  Everything works fine until I try to build ffmpeg itself.  The build process generates MULTIPLE warnings, etc.  Iīm using the most recent versions of the library codecs.  So two questions, Iīm a bit of a linux newbie :)
1.  is there a way to log the ffmpeg build so that I can check the build process for errors?
2.  are warnings ok, or should this be a "clean" build?

appreciate your help
Robert
May 2nd, 2011 13:15:49
@rdwatson there are a couple of ways to do it, either set a large scrollback buffer in your terminal window (I usually SSH into my server for builds and set a huge buffer or log the session - a function of my SSH client)
or
redirect the output to a file > log.txt and view that when itīs done.

That said:
Usually warnings arenīt much to worry about and the error that stops you will be the last thing that comes up - so you can almost just start at the last line and work backwards. dealing with one thing at a time.
May 3rd, 2011 06:57:46
# svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
-bash: svn: command not found

lol
May 23rd, 2011 11:07:56
Ah... svn is usually there if you have any of the development tools packages installed. But you should be able to
# yum install svn

to add it in if it isnīt
May 23rd, 2011 11:26:20
I get an error when executing make for faac-1.28:

...
make[3]: Entering directory `/root/ffmpeg_new/faac-1.28/common/mp4v2ī
source=ī3gp.cppī object=ī3gp.oī libtool=no
DEPDIR=.deps depmode=none /bin/sh ../../depcomp
g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../include   -Wall  -c -o 3gp.o 3gp.cpp
../../depcomp: line 512: exec: g++: not found
make[3]: *** [3gp.o] Error 127
make[3]: Leaving directory `/root/ffmpeg_new/faac-1.28/common/mp4v2ī
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/root/ffmpeg_new/faac-1.28/commonī
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/ffmpeg_new/faac-1.28ī
make: *** [all] Error 2


May 23rd, 2011 11:53:07
Oh I guess Iīm missing g++ also... _that_ is strange. This is a CentOS server...
May 23rd, 2011 11:54:45
not too strange if when the server was installed the devel packages werenīt included (I dud that as a matter of practice but not everyone does)

May 23rd, 2011 11:59:42
Yes indeed I had to manually install gcc-c++. I wonder whatīs the reasoning behind including the c compiler but not the c++ compiler in a linux distribution....
May 23rd, 2011 12:05:56
What I canīt understand is, why g++ is considered something only developers need and gcc is considered something everybody needs :)
May 23rd, 2011 12:08:17
I also get some warnings:
WARNING: yasm version is too old
WARNING: nasm version is too old

(Iīve just installed them a minute ago!)
And then:
WARNING: no correct assemblef found. Compiling only generic sources...

should I worry?
May 23rd, 2011 12:13:15
now everything seems to work fine untill configuring libvorbis:

checking for OGG... no
checking for Ogg... no
*** Could not run Ogg test program, checking why...
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding Ogg or finding the wrong
*** version of Ogg. If it is not finding Ogg, youīll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location  Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
configure: error: must have Ogg installed!


However I donīt see any error in the previous step which I guess should install libogg......
May 23rd, 2011 12:22:48
May 23rd, 2011 12:26:53
Hereīs the fix:

echo /usr/local/lib >> /etc/ld.so.conf; ldconfig

and then compile libvorbis again. Have no idea what that means, but it worked for me.
May 23rd, 2011 12:32:30
Ok I finally got it to "work", but I get the same problem I was getting with the packaged version from the repositories: when I try to decode amr files I get:

[amrnb @ 0x626e90] dtx mode not implemented. Update your FFmpeg version to the newest one from SVN. If the problem still occurs, it means that your file has a feature which has not been implemented.If you want to help, upload a sample of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ and contact the ffmpeg-devel mailing list.

I can decode the very same files with ffmpeg on Ubuntu (the packaged version); also, on a CentOS server that a friend of mine was running, he installed a version of ffmpeg _years_ ago that can decode these same files without issues.... so I donīt understand!!!
May 23rd, 2011 12:50:22
Well the SVN is not being updated any more. The svn checkout part needs to be replaced with git clone. Anyway I doubt this is the cause of my problem.
May 23rd, 2011 14:15:08
Good to know they changed to git - Iīll have to do up a new install steps guide - (adding that to my infinitely long todo list)
May 23rd, 2011 14:51:46
I fixed the problem by adding --disable-decoder=amrnb to the configure command :)
I donīt know why, but it works.
May 23rd, 2011 15:54:50
(with the latest version taken from git, of course)
May 23rd, 2011 15:55:22
btw THANKS
May 23rd, 2011 15:55:45
Firstly, thank you for sharing this...it is much appreciated and very helpful with my project.

I just got this compiled and running as of 8/8/2011, here are a few notes on the above:

1.  Some version changes:

# changed to 1.3.2
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz

# changed to 2.1.3
wget http://downloads.sourceforge.net/project/libdc1394/libdc1394-2/libdc1394-2.1.3.tar.gz

# changed to 1.3.0
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz

#changed to 1.3.2
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.2.tar.gz

2.  x264 issue - not sure what impact this will have on this codec

git clone git://git.videolan.org/x264.git
# per http://blog.gmane.org/gmane.comp.video.x264.devel
# latest git snapshot will not compile on centos as of 8/7/2011
# git clone git://git.videolan.org/x264.git
# revert this commit to get it to work:
git revert 44c881766e9fcba80035e8a127bbee851cdb8584
August 9th, 2011 01:19:32
Thatīs awesome thanks @bitjanitor I really appreciate your updates. Iīll keep an eye on the x264 issue hopefully that will get fixed without the rollback soon.
August 9th, 2011 01:29:17
i
You must login or register to post comments Login/Signup
RSS feed Feed Description
Subscribe to the complete PawPrint.net News RSS news feedAll News RSS feed Complete RSS feed
Subscribe to the PawPrint.net News RSS news feed for this category onlyTechnobloggle RSS feed for: Technobloggle
A Rich Site Summary (RSS) feed is an xml data file that provides a summary of the information contained here. It is not designed to be viewed in your browser, but instead by rss reader software. If you do not know what this means - you can safely ignore it, as it is provided for advanced users with rss reader software only.
Copyright © 1992-2024 PawPrint.net
web development: PawPrint.net