Oct 06
Compiling a recent ffmpeg
Before you start, it might be useful to again read the post How do I compile stuff.
Okay, here is how you build a recent binary of ffmpeg from source. Please be aware that configure switches and library neames tend to change over time and as this post ages might need adjustment.
We will need a very recent yasm (a rewrite of nasm, etc.), an assembler:
Download yasm from the official yasm homepage:
- > wget http://www.tortall.net/projects/yasm/releases/yasm-0.8.0.tar.gz
- > tar xvf yasm-0.8.0.tar.gz
- > cd yasm-0.8.0
- > ./configure
- > make
- > make install
cd up again and now we are going to build a recent x264:
- > aptitude install git-core
- > git clone git://git.videolan.org/x264.git
- > cd x264
- > ./configure –enable-pthread –enable-shared –enable-mp4-output –enable-pic
- > make
- > make install
On my version of Debian, I got an error on the make step: “/usr/bin/ld: cannot find -lgpac_static”. A thread discusion this issue can be found here. As I was unable to get libgpac-dev installed easily (lots of broken packages, unsatisfied dependencies, etc. - not sure if my system is screwed or x264 is too new for my Debian…) I had to find a different solution - which was to omit “–enable-pthread” on configure. After that make && make install worked ok.
After that, back to ffmpeg. ffmpeg has quite a few dependencies, so its good to start with some basic libs, everything else configure will tell you (you can search for the missing -dev package with apt-cache search lib<name>):
- > aptitude install libswscale-dev libavcodec-dev libavformat-dev libvorbis-dev libtheora-dev liblame-dev liblame0 libgsm1-dev libgsm-tools libgsm1 libfaad2-dev libfaac-dev libgpac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libdc1394-13-dev
- > svn export svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg-trunk
Note 1: If I remember correctly, I checked out version/revision 20182.
Note 2: The now official svn url is: svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg-trunk - > cd ffmpeg-trunk
- > ./configure –enable-gpl –enable-shared –enable-pthreads –enable-libdc1394 –enable-libfaac –enable-libfaad –enable-libgsm –enable-libmp3lame –enable-libtheora –enable-libvorbis –enable-libx264 –disable-debug –enable-nonfree
- Think about adding: –enable-libxvid –enable-shared (the latter installs the libav* libs in /usr/local/lib
- > make
On newer versions of ffmpeg “–enable-swscale” isn’t needed anymore, its permanently on. We need to set the the nonfree flag, as libfaac breaks the “free”. And as it seems, the omitted pthread flag on x264 has no relevance or at least doesn’t break the build of ffmpeg. (Comments welcome!).
Now: wait a minute!
As you may have noticed, we did not make install. The build binary is still residing in our ffmpeg-trunk dir, which is quite convenient, as we have a solid, older ffmpeg in /usr/bin and a turbocharged new version here. But there are some caveats - it doesn’t run out of the box. First we need to symlink some libs into place (otherwise you would get an error on loading shared libraries libavdevice.so.52, for example):
(Be sure to symlink the libs your build actually requests and not blindly copy/paste the lines below, versions may vary!)
- > ln -s libswscale/libswscale.so.0 ./
- > ln -s libavdevice/libavdevice.so.52 ./
- > ln -s libavformat/libavformat.so.52 ./
- > ln -s libavcodec/libavcodec.so.52 ./
- > ln -s libavutil/libavutil.so.50 ./
And you need to add another library search path to bash, for example by calling our new ffmpeg like this:
> LD_LIBRARY_PATH=”/path/to/ffmpeg-trunk” /path/to/ffmpeg-trunk/ffmpeg <options> <outfile>
or by permanently export‘ing this LD_LIB_PATH with:
> export LD_LIBRARY_PATH=”/path/to/ffmpeg-trunk”
A third option, preferred by some users, is to configure with –prefix=/opt/ffmpeg. This leads to, after make install, ffmpeg ending up under /opt in /opt/ffmpeg and binaries at /opt/ffmpeg/bin which conveneintly finds libraries at /opt/ffmpeg/lib. A bit more elegant that tweaking with ldconfig or the above symlinks/export LD_LIBRARY_PATH.
A nice guide to get a all-feature ffmpeg is here.
Other helpful ffmpeg compiling HOW-TOs are (both slightly out of date):
