How to: Tips and Tricks

Ubuntu 9.10: compiling FFmpeg with x264

FFmpeg logo

FFmpeg is a versatile tool to encode and convert a multitude of video and audio formats. x264 encodes high-quality video superior to other popular encoders. Ubuntu 9.10 (Karmic Koala) ships with a version of ffmpeg without libfaac and x264 support because of licensing issues. This means you will need to compile ffmpeg yourself. This guide explains how.

1. Uninstall old ffmpeg

If you have previously installed ffmpeg with x264, uninstall them. Open a terminal and run this command:

sudo apt-get remove ffmpeg x264 libx264-dev

2. Install needed packages

sudo apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libfaad-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libx11-dev libxfixes-dev libxvidcore4-dev zlib1g-dev

3. Install x264

Get the most current source files from the official x264 git repository, compile, and install.

cd
git clone git://git.videolan.org/x264.git
cd x264
./configure
make
sudo checkinstall --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`+`git rev-list HEAD -n 1 | head -c 7`" --backup=no --default

4. OPTIONAL: Install libtheora

Needed for Theora OGG files. The repository libtheora is too old, so it must be compiled.

sudo apt-get install libogg-dev
cd
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
tar xzvf libtheora-1.1.1.tar.gz
cd libtheora-1.1.1
./configure --disable-shared
make
sudo checkinstall --pkgname=libtheora --pkgversion "1.1.1" --backup=no --default

5. Install FFmpeg

Get the most current source files from the official FFmpeg svn, compile, and install.

cd
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libx264 --enable-libxvid --enable-x11grab
make
sudo checkinstall --pkgname=ffmpeg --pkgversion "4:0.5+svn`date +%Y%m%d`" --backup=no --default
hash ffmpeg

DONE. You can keep the ~/x264 and ~/ffmpeg directories if you later want to update the source files to a new revision. See "Updating Your Installation" below for more details.

Updating your installation

Development of FFmpeg and x264 is active and an occasional update can give you new features and bug fixes. To update FFmpeg and x264 you will need to remove the packages, make distclean, update the source, recompile, and install. To update x264:

sudo apt-get remove ffmpeg x264 libx264-dev
cd ~/x264
make distclean
git pull

Now compile x264 as shown earlier in the guide starting with the x264 ./configure line. Now FFmpeg:

cd ~/ffmpeg
make distclean
svn update

Now continue with the installation starting with the FFmpeg ./configure line.

Easiest way :)

For those who do not want to compile ffmpeg and install many dependencies, I attach my compiled packages. Follow these steps:

1. Install needed depencies

sudo apt-get install libfaac0 libfaad0 libmp3lame0 libopencore-amrnb0 libopencore-amrwb0 libxvidcore

2. Download and install

Create temporary folder, download packages and install them:

cd
mkdir my-ffmpeg
cd my-ffmpeg
wget http://howto.blbosti.com/files/ffmpeg/x264_1:0.svn20100317+1144615-1_i386.deb
wget http://howto.blbosti.com/files/ffmpeg/libtheora_1.1.1-1_i386.deb
wget http://howto.blbosti.com/files/ffmpeg/ffmpeg_4:0.5+svn20100317-1_i386.deb
sudo dpkg -i *.deb

Or download the files manually and install. That's it.

Reverting Changes Made by This Tutorial

To remove FFmpeg/x264 and any changes made from this tutorial:

sudo apt-get remove x264 ffmpeg build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libfaad-dev libmp3lame-dev libsdl1.2-dev libx11-dev libxfixes-dev libxvidcore4-dev zlib1g-dev

How to use

I downloaded Full HD mp4 video from YouTube using youtube-dl, and I want to convert it into smaller mp4 file for my portable player.

ffmpeg -i input.mp4 -vcodec libx264 -vpre slow -s qvga -b 600k -acodec libfaac -ab 128k output.mp4

Some examples can be found at www.catswhocode.com.

.deb files to download

Credit goes here

  • Thanks kindly for this post. Besides the method of getting aac and h.264 encoding into ffmpeg, I also learnt about checkinstall.

  • hi!!!

  • I also learnt about youtube-dl
    thank you