Compiling FFmpeg for Raspberry Pi / Raspbian Jessie

There’s plenty of guides around, but none that worked flawlessly for me. Here’s my recipe for building and compiling FFmpeg for the Raspbian Jessie environment for Raspberry Pi.

If you’re doing this on the Raspberry Pi, I would encourage you to run the following commands as root, so enter “su” in the command prompt and switch to the root user. From my experience some builds can be flaky when done using the sudo command.

Install GIT & SVN

You’ll be getting some files from source, so it’s always best to have GIT and SVN installed.

~# apt-get install git && apt-get install svn

Source downloads

I usually create a directory called “srcs” in my home directory for when I am downloading and building packages from source code. This guide will assume that the following path: “/home/pi/srcs” exists already.

You will also notice the usage of the “-j3” switch on the “make” commands – this tells the ‘make’ tool to use 3 processor cores of the 4-cored Pi2/Pi3. If you are using an original Pi, Pi+, Model A or Zero for this, you should remove the -j3 switch when executing the command. Using the -j switch to allocate more cores gives a slight boost in compilation speed, as work is shared across more than one processor core. This can shave minutes or even hours of the compilation of some packages.

Install supporting Libraries and Build tools

~# apt-get install libasound2-dev build-essential make autoconf libtool

Install x264 video support

~# cd ~/srcs
srcs# git clone git://git.videolan.org/x264
srcs# cd x264
x264# ./configure –disable-asm –enable-shared
x264# make -j3
x264# make install

Install Lame audio support (for mp3 audio)

x26x# cd ~/srcs
srcs# wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.tar.gz
srcs# tar xzvf lame-3.99.tar.gz
srcs# cd lame-3.99
lame-3.99# ./configure
lame-3.99# make -j3
lame-3.99# make install

Install FAAC audio support (one possible AAC support)

lame-3.99# cd ~/srcs
srcs# curl -#LO http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
srcs# tar xzvf faac-1.28.tar.gz
srcs# cd faac-1.28

Now – before finishing off faac, you need to check and possibly edit a line of code in one of the headers (for v1.28 you need to do this, other versions may not require this).

run the following command to open Nano at the line in question:

faac-1.28# nano +126 common/mp4v2/mpeg4ip.h

You should see the following line highlighted:

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

Delete or comment this line out (eg add // to the start), then press CTRL+X then Y to save. Then carry on with configuring

faac-1.28# ./configure
faac-1.28# make -j3
faac-1.28# make install

Install FDK AAC audio support (alternate AAC support)

faac-1.28# ~/srcs
srcs# wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
srcs# tar xzvf fdk-aac.tar.gz
srcs# cd mstorsjo-fdk-aac*
mstorsjo-fdk-aac-<hash># autoreconf -fiv
mstorsjo-fdk-aac-<hash># ./configure –enable-shared
mstorsjo-fdk-aac-<hash># make -j3
mstorsjo-fdk-aac-<hash># make install

Once this is all done, reinitialise your library links with:

mstorsjo-fdk-aac-<hash># cd
~# ldconfig -v

Check the verbose output in the terminal. Look for any errors, and try and make sure that libfaac and libfdk-aac are listed.

Now I generally install both, as with my experience with FFmpeg, sometimes libfaac refuses to play ball during compilation, so I use libfdk-aac as a fallback.

Time to build FFmpeg

~# cd ~/srcs
srcs# git clone git://source.ffmpeg.org/ffmpeg.git
srcs# cd ffmpeg
ffmpeg# ./configure –enable-shared –enable-gpl –prefix=/usr –enable-nonfree –enable-libmp3lame –enable-libfaac –enable-libx264 –enable-version3 –disable-mmx

IF you get an error stating that “–enable-libfaac” is an unknown command, try using the following configure command (this will utilise libfdk-aac instead):

ffmpeg# ./configure –enable-shared –enable-gpl –prefix=/usr –enable-nonfree –enable-libmp3lame –enable-libfdk-aac –enable-libx264 –enable-version3 –disable-mmx

Finish compilation with the following commands:

ffmpeg# make -j3
ffmpeg# make install

Done, for now

With all this done, you should have a sufficient installation of FFmpeg at your disposal that can do most common video encoding.

Although do bare in mind that because FFmpeg is so modular and there are dozens of popular encoding formats for audio and video, that this guide may not always be sufficient for your needs. You may need to recompile FFmpeg with additional libraries that are not documented in this guide.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.