This guide supports Ubuntu Precise Pangolin 12.04 server.
Combined from https://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide
sudo apt-get remove ffmpeg x264 libav-tools libvpx-dev libx264-dev
########################
# Get the dependencies #
########################
sudo apt-get update
sudo apt-get -y install autoconf automake build-essential git libass-dev libgpac-dev \
libtheora-dev libtool libvorbis-dev libxext-dev libxfixes-dev pkg-config texi2html \
zlib1g-dev
mkdir ~/ffmpeg_sources
########
# YASM #
########
cd ~/ffmpeg_sources
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure --prefix="$HOME/ffmpeg_build"
make
make install
make distclean
. ~/.profile
########
# X264 #
########
cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264.git
cd x264
./configure --prefix="$HOME/ffmpeg_build" --enable-static
make
make install
make distclean
###########
# fdk-aac #
###########
cd ~/ffmpeg_sources
git clone --depth 1 git://github.com/mstorsjo/fdk-aac.git
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean
##################
# libmp3lame-dev #
##################
sudo apt-get install libmp3lame-dev -y
##########
# libvpx #
##########
cd ~/ffmpeg_sources
git clone --depth 1 http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples
make
make install
make clean
##########
# FFmpeg #
##########
cd ~/ffmpeg_sources
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" --extra-libs="-ldl" --enable-gpl \
--enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libtheora \
--enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree
make
make install
make distclean
hash -r