Oct 06

Compiling a recent ffmpeg

Category: Linux,multimedia   — Published by tengo on October 6, 2009 at 4:33 pm

This guide is mostly referring to Debian Etch (4.0). Go to the bottom for ffmpeg on Debian Squeeze (6.0)

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:

  1. > wget http://www.tortall.net/projects/yasm/releases/yasm-0.8.0.tar.gz
  2. > tar xvf yasm-0.8.0.tar.gz
  3. > cd yasm-0.8.0
  4. > ./configure
  5.  > make
  6. > make install

cd up again and now we are going to build a recent x264:

  1. > aptitude install git-core
  2. > git clone git://git.videolan.org/x264.git
  3. > cd x264
  4. > ./configure --enable-pthread --enable-shared --enable-mp4-output --enable-pic
  5. > make
  6. > 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>):

  1. > 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
  2. Ffmpeg uses git now!!
    git clone git://git.videolan.org/ffmpeg.git
    If you use the older svn stuff, you might get an error like: "ERROR: libx264 version must be >= 0.99. " alhtough you've get the most up-to-date x264!
    > 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
  3. > cd ffmpeg-trunk
  4. > ./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
  5. Think about adding: --enable-libxvid --enable-shared (the latter installs the libav* libs in /usr/local/lib
  6. > 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!)

  1. > ln -s libswscale/libswscale.so.0 ./
  2. > ln -s libavdevice/libavdevice.so.52 ./
  3. > ln -s libavformat/libavformat.so.52 ./
  4. > ln -s libavcodec/libavcodec.so.52 ./
  5. > 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):

Update

Make sure you check out ffmpeg from the new git repository!!

This page might give good clues where specific libaries can be found.

And this is a really helpful download this, compile this then compile ffmpeg guide.

Compile string: ./configure --enable-gpl --disable-shared --enable-pthreads --enable-libfaac --enable-libgsm --enable-libmp3lame --enable-libtheora --enable-libvorbis  --disable-debug --enable-nonfree

Be sure to set --enable-shared when you compile x264, otherwise x264 will not install the shared libraries our static linking ffmpeg will look for to include and complain with error: "libx264 version must be >= 0.115" although you've got the latest version from git!
And I had to tdo this to get ffmpeg working: ln -s /usr/local/lib/libx264.so.118 /usr/lib/libx264.so.118

Compiling ffmpeg on Debian Squeeze

Add debian-multimedia to your apt-get sources:

  • wget http://www.debian-multimedia.org/pool/main/d/debian-multimedia-keyring/debian-multimedia-keyring_2010.12.26_all.deb
  • dpkg -i debian-multimedia-keyring_2008.10.16_all.deb
  • nano /etc/apt/sources.list and add deb http://www.debian-multimedia.org squeeze main non-free

NOTE: After that you shoudl check if the debian-multimedia version of ffmpeg doesn't do the trick for you! For that, just adding the repo and doing apt-get update && apt-get upgrade won't replace the ffmpeg on your machine! Do this:

  • apt-get remove ffmpeg && apt-get install ffmpeg

After that your ffmpeg should report with a version 0.7+
If you still want to compile your own, proceed like this:

Add all the libs we need:

  • install build-essential subversion git-core yasm libgpac-dev libdirac-dev libgsm1-dev libschroedinger-dev libspeex-dev libvorbis-dev libopenjpeg-dev libdc1394-22-dev libsdl1.2-dev zlib1g-dev texi2html libfaac-dev libfaad-dev libmp3lame-dev libtheora-dev libxvidcore4-dev libopencore-amrnb-dev libopencore-amrwb-dev

Grab the latest x264 code:

  • git clone git://git.videolan.org/x264.git
  • cd x264
  • ./configure --enable-shared --disable-asm
  • make
  • make install
  • cd ..

Grab FFmpeg from Subversion:

  • svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
  • cd ffmpeg

Configure ffmpeg to your liking and make / install:

  • ./configure --enable-gpl --disable-shared --enable-pthreads --enable-libfaac --enable-libdirac --enable-libgsm --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --disable-debug --enable-nonfree
  • make
  • make install
     

ALSO:
the original ffmpeg installs to /usr/bin/ffmpeg. The compiled version by default installs to /usr/local/bin/ffmpeg. Know this when you execute the binaries or want to place a default ffmpeg in /usr/bin!
Think about adding this to your config: --prefix=/usr --extra-version=goeszen

This here is a tweaked version of this post. There you can find a dynamically linked compile and related info.

For reference,
the originally shipped version of ffmpeg on my Squeeze was:
FFmpeg version SVN-r0.5.6-4:0.5.6-3, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --extra-version=4:0.5.6-3 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libdirac --enable-libgsm --enable-libopenjpeg --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libfaad --enable-libdc1394 --enable-shared --disable-static

At the time of writing, debian-multimedia supplied this version:
ffmpeg version 0.7.12, Copyright (c) 2000-2011 the FFmpeg developers
built on Apr 11 2012 07:40:07 with gcc 4.4.5
configuration: --enable-libdc1394 --prefix=/usr --extra-cflags='-Wall -g ' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-avfilter --enable-libdirac --disable-decoder=libdirac --enable-libfreetype --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-libvpx --enable-librtmp --extra-libs=-lgcrypt --disable-altivec --disable-armv5te --disable-armv6 --disable-vis