Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compile FFmpeg on Ubuntu

Compile FFmpeg on Ubuntu

This guide supports Ubuntu Precise Pangolin 12.04, Ubuntu Oneiric Ocelot 11.10, Ubuntu Natty Narwhal 11.04, and Ubuntu Maverick Meerkat 10.10. Separate guides are available for Ubuntu Lucid Lynx 10.04 and Ubuntu Hardy Heron 8.04. This guide will enable several external encoding and decoding libraries: libfaac (AAC encoder), libfdk-aac (AAC encoder), libmp3lame (MP3 encoder), libopencore-amr (AMR encoder/decoder), librtmp (for additional RTMP protocols), libtheora (Theora encoder), libvorbis (Vorbis encoder), libvpx (VP8 encoder/decoder), and libx264 (H.264 encoder). These are optional and may be omitted if desired. This guide will also install many filters (see the filter list in the Filtering Guide).

Note: Copy and paste the whole code box for each step.

Preparation

Remove any existing packages:

sudo apt-get remove ffmpeg x264 libav-tools libvpx-dev libx264-dev

Get the dependencies (Ubuntu Desktop users):

sudo apt-get update
sudo apt-get -y install build-essential checkinstall git libfaac-dev libgpac-dev \
  libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev \
  librtmp-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev \
  libx11-dev libxfixes-dev pkg-config texi2html yasm zlib1g-dev

Get the dependencies (Ubuntu Server or headless users):

sudo apt-get update
sudo apt-get -y install build-essential checkinstall git libfaac-dev libgpac-dev \
  libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev librtmp-dev libtheora-dev \
  libvorbis-dev pkg-config texi2html yasm zlib1g-dev

Installation

x264

H.264 video encoder. The following commands will get the current source files, compile, and install x264. See the x264 Encoding Guide for some usage examples.

cd
git clone --depth 1 git://git.videolan.org/x264
cd x264
./configure --enable-static
make
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
  awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
  --fstrans=no --default

Note: You can download the nightly x264 source snapshot as an alternative to using git.

libfdk-aac

AAC audio encoder.

cd
wget http://downloads.sourceforge.net/opencore-amr/fdk-aac-0.1.0.tar.gz
tar xzvf fdk-aac-0.1.0.tar.gz
cd fdk-aac-0.1.0
./configure
make
sudo checkinstall --pkgname=fdk-aac --pkgversion="0.1.0" --backup=no \
  --deldoc=yes --fstrans=no --default

libvpx

VP8 video encoder and decoder.

cd
git clone --depth 1 http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure
make
sudo checkinstall --pkgname=libvpx --pkgversion="1:$(date +%Y%m%d%H%M)-git" --backup=no \
  --deldoc=yes --fstrans=no --default

Note: You can download a libvpx source snapshot as an alternative to using git.

FFmpeg

cd
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
  --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis \
  --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab
make
sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(date +%Y%m%d%H%M)-git" --backup=no \
  --deldoc=yes --fstrans=no --default
hash x264 ffmpeg ffplay ffprobe

Note: You can download the nightly FFmpeg source snapshot as an alternative to using git.

Note: Ubuntu Server users should omit --enable-x11grab.

Finish

Installation is now complete and FFmpeg is now ready for use. You can keep the x264, libvpx, and ffmpeg directories in your home directory if you plan on updating later. See Updating FFmpeg below for more details. Some optional steps are next followed by instructions on updating FFmpeg and finally instructions on reverting all changes made by this guide.

Optional Installation

qt-faststart

This is a useful tool if you're showing your H.264 in MP4 videos on the web. It relocates some data in the video to allow playback to begin before the file is completely downloaded. Usage: qt-faststart input.mp4 output.mp4.

cd ~/ffmpeg
make tools/qt-faststart
sudo checkinstall --pkgname=qt-faststart --pkgversion="$(date +%Y%m%d%H%M)-git" --backup=no \
  --deldoc=yes --fstrans=no --default install -Dm755 tools/qt-faststart \
  /usr/local/bin/qt-faststart

Add lavf support to x264

This allows x264 to accept just about any input that FFmpeg can handle and is useful if you want to use x264 directly. See a more detailed explanation of what this means.

cd ~/x264
make distclean
./configure --enable-static
make
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
  awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
  --fstrans=no --default

Updating FFmpeg

Development of FFmpeg and x264 is active and an occasional update can give you new features and bug fixes. First, remove some packages and then update the dependencies:

sudo apt-get -y remove ffmpeg x264 libx264-dev libvpx-dev
sudo apt-get update
sudo apt-get -y install build-essential checkinstall git libfaac-dev libgpac-dev \
  libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev \
  librtmp-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev \
  libx11-dev libxfixes-dev texi2html yasm zlib1g-dev

x264

cd ~/x264
make distclean
git pull

Now run ./configure, make, and make install as shown in the install x264 section.

libvpx

cd ~/libvpx
make clean
git pull

Now run ./configure, make, and make install as shown in the install libvpx section.

FFmpeg

cd ~/ffmpeg
make distclean
git pull

Now run ./configure, make, and make install as shown in the install FFmpeg section.

Reverting Changes Made by This Guide

To remove FFmpeg/x264 and other packages added for this guide:

sudo apt-get -y autoremove build-essential checkinstall fdk-aac ffmpeg git libfaac-dev libgpac-dev \
  libjack-jackd2-dev libmp3lame-dev librtmp-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev \
  libvorbis-dev libvpx libx11-dev libxfixes-dev pkg-config qt-faststart texi2html x264 yasm zlib1g-dev

Lastly, delete the x264, fdk-aac, libvpx, and ffmpeg directories in your home folder.

If You Need Help

Feel free to ask your questions at the #ffmpeg IRC channel or the ffmpeg-user mailing list.

@llogan

This comment has been minimized.

Copy link

llogan commented May 24, 2013

This gist is an outdated, verbatim copy of Compile FFmpeg on Ubuntu.

@avmohan

This comment has been minimized.

Copy link

avmohan commented Jun 5, 2013

I had some problems in ffmpeg configure. It said libopencore-amrnb not found. I fixed it using
sudo apt-get install libopencore-amrnb-dev
Next, it complained that libx264 not found even though I had compiled using the steps here. So I uninstalled this x264 version and installed from the official repo
sudo apt-get install libx264-dev
before configuring ffmpeg. It worked now :-)
Is my build OK?

@jlaimins

This comment has been minimized.

Copy link

jlaimins commented Jul 14, 2013

If ffmpeg configure complains about libx264, try adding --extra-libs="-ldl"

@squamous

This comment has been minimized.

Copy link

squamous commented Sep 17, 2013

I was able to alleviate the problem of ffmpeg configure complaining that it couldn't find libx264 by configuring x264 with --enable-shared

@j0k3r

This comment has been minimized.

Copy link

j0k3r commented Jun 28, 2014

libvpx repo has changed to: https://chromium.googlesource.com/webm/libvpx

@amy475

This comment has been minimized.

Copy link

amy475 commented Nov 15, 2014

Thanks working for me

@NataliaDiaz

This comment has been minimized.

Copy link

NataliaDiaz commented Sep 18, 2017

The first command to install x264 fails. The right command is
git clone --depth 1 https://git.videolan.org/git/x264.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.