======Building ffmpeg on Ubuntu======
ffmpeg is an incredibly versatile and handy tool for working with media files. Unfortunately, the Ubuntu repository no longer tracks changes to ffmpeg.
=====Objectives=====
Obtain the ffmpeg sources, and build a current version on an Ubuntu server.
=====Background=====
ffmpeg is a great tool, but, a little while ago, Ubuntu switched to avconv, a fork of ffmpeg. Unfortunately, avconv really isn't as good as ffmpeg. As such, the ffmpeg version with Ubuntu is pretty deprecated, and a lot of things don't work right.
=====Scope=====
This project will walk through the setup and compilation of the most recent ffmpeg version.
=====Procedure=====
====Step 1====
===Getting the required dependencies===
There are a few dependencies for ffmpeg that should be updated before we move onto compilation. First, update your repository.
sudo apt-get update
Next, we'll install the dependencies.
sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libgpac-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev
Finally, we'll install yasm, an assembler which will optimize the build time.
sudo apt-get install yasm
====Step 2====
===Getting the sources===
Now, we need to get the sources for ffmpeg. First, make a directory in your home directory titled ffmpeg_sources
mkdir ~/ffmpeg_sources
There are a few encoder dependencies that need to be gotten and built for ffmpeg. First, the H.264 video codec.
cd ~/ffmpeg_sources
wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
tar xjvf last_x264.tar.bz2
cd x264-snapshot*
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
make distclean
Next, we need the AAC audio encoder.
cd ~/ffmpeg_sources
wget -O fdk-aac.zip https://github.com/mstorsjo/fdk-aac/zipball/master
unzip fdk-aac.zip
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean
Next, the MP3 audio codec.
sudo apt-get install libmp3lame-dev
Now, we'll get the sources for ffmpeg and compile them.
cd ~/ffmpeg_sources
wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
export PKG_CONFIG_PATH
./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --extra-libs="-ldl" --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
make
make install
make distclean
hash -r
After this, ffmpeg should be all compiled and built, and should be in your ~/bin directory.
====Step 5 (Optional)====
===Set up a path variable to ~/bin===
If you want to run your new version of ffmpeg from anywhere, you may need to add ~/bin to your $PATH system variable. First, check to see if your ~/bin directory is listed in your $PATH. Do this by typing the following:
echo $PATH
Which will return something like this:
/home/shawn/bin:/usr/local/sbin:/usr/local/bin:/usr.sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
If you don't see "/home/username/bin" listed, we need to add it to our $PATH. This can be done by editing the ~/.profile file, and adding the following lines to the bottom.
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
This will check the home directory on login, and if it finds a ~/bin folder, it will add it to the path. After adding this line, save the ~/.profile and restart your shell. After this, we should be able to call the script from anywhere. So, let's test it. Run the following command from any directory.
ffmpeg
The ffmpeg run dialog should show up, and everything should be good to go!