Install ffmpeg on Ubuntu 14.04

Posted on Saturday, July 4, 2015





ffmpeg is a great command line tool for converting videos and audio files from one format to another.  https://www.ffmpeg.org/about.html [1]

In this tutorial I will be going over how to install it in Ubuntu 14.04.







Why a tutorial?


Why should there even be a tutorial on how to install this?  Shouldn't it be just something like "sudo apt-get install ffmpeg"?

I am sure someone can answer this better than I, but here is my naive take on it…

There are two problems lots of codecs and licensed codecs. 

  1. If every codec and file format out there was open sourced and freely available we have a problem.  There are just too many formats out there to install all of them with ffmpeg… since 95%+ of them, you personally may not care about or need.
  2. Many formats are 'owned' by someone.  For example mp3.  Most of these don't seem to have a problem with you decoding it…. But making a piece of software that can read it may need to be licensed.  Since ffmpeg is open-source they cannot pay for the mp3 license for their tool.  But they can make it so that you can 'plug-in' an mp3 tool into ffmpeg.



So it's fairly easy to install ffmpeg, but it's hard to install all the other tools ffmpeg needs and to configure it correctly.


The Install process


My process is derived from notes at http://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu [2].  Go there if you want complete details.  I followed it very closely.  The main thing I did differently was find which tools could be installed via apt-get and I used apt-get for those.


This is the install process I followed for Ubuntu 14.04.

First update and upgrade apt


  > sudo apt-get upgrade
  > sudo apt-get update


Install needed build tools


  > sudo apt-get -y --force-yes install autoconf automake build-essential libass-dev libfreetype6-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev  libxcb-xfixes0-dev pkg-config texi2html zlib1g-dev




Create location to compile tools at


  > mkdir ~/ffmpeg_sources
  > cd ~/ffmpeg_sources



Install yasm via apt-get


  > sudo apt-get -y install yasm



Install libx264 via apt-get


  > apt-get -y install libx264-dev





Install libx265 via build tools


  > sudo apt-get -y install cmake mercurial
  > cd ~/ffmpeg_sources
  > hg clone https://bitbucket.org/multicoreware/x265
  > cd ~/ffmpeg_sources/x265/build/linux PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
   > make
   > make install


Install libfdk-acc via build tools


  > cd ~/ffmpeg_sources
  > wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
  > tar xzvf fdk-aac.tar.gz
  > cd mstorsjo-fdk-aac*
  > autoreconf -fiv
  > ./configure --prefix="$HOME/ffmpeg_build" --disable-shared
  > make
  > make install
  > make distclean




Install libmp3lame via apt-get
 

  > apt-get -y install libmp3lame-dev

 

Install libopus via apt-get
 

  > apt-get -y install libopus-dev



Install libvpx build from source
 

  > cd ~/ffmpeg_sources
  > wget http://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2
  > tar xjvf libvpx-v1.3.0.tar.bz2
  > cd libvpx-v1.3.0
  > PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests
  > PATH="$HOME/bin:$PATH" make
  > make install
  > make clean







Install ffmpeg build from source
 

  > cd ~/ffmpeg_sources
  > wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
  > tar xjvf ffmpeg-snapshot.tar.bz2
  > cd ffmpeg
  > PATH="$HOME/bin:$PATH"   PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree
  > PATH="$HOME/bin:$PATH" make
  > make install
  > make distclean
  > hash -r




Move ffmpeg tool from ~/bin to /bin
 

  > mv ~/bin/ff* /bin



And that is it!






Test it out


Now to test it out…

I have a video called zipper-vid.mp4 and I have an audio file called firefly_song.m4a.   I want to combine these.  In fact I want to replace the original audio from the .mp4 file with the audio file.

Here is the command I used.
 

  > ffmpeg -i zipper-vid.MP4 -i firefly_song.m4a -c copy -map 0:v:0 -map 1:a:0 new_video.mp4


This create a new video file called new_video.mp4.


I made a youtube video running through how I did this in detail.



 

Script


If you just want a script I posted one at https://gist.github.com/patmandenver/14590573545260163e3d 

Here is the script file.


#!/bin/bash

if [[ $EUID -ne 0 ]]; then
    echo "This script must be run with admin privileges 'sudo'"
    echo "exiting...."
    exit 1
fi

echo "*********************************"
echo "Installing ffmpeg on Ubuntu 14.04"
echo "*********************************"

echo "*********************************"
echo "1/12 Update apt-get"
echo "*********************************"

apt-get -y upgrade
apt-get -y update

echo "2/12 install needed build tools"

sudo apt-get -y --force-yes install autoconf automake build-essential libass-dev libfreetype6-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev  libxcb-xfixes0-dev pkg-config texi2html zlib1g-dev

echo "*********************************"
echo "3/12 Create location to do work in"
echo "*********************************"

mkdir ~/ffmpeg_sources
cd ~/ffmpeg_sources

echo "*********************************"
echo "4/12 Install yasm via apt-get"
echo "*********************************"

sudo apt-get -y install yasm

echo "*********************************"
echo "5/12 Install libx264 via apt-get"
echo "*********************************"

apt-get -y install libx264-dev

echo "*********************************"
echo "6/12 Install libx265 via build tools"
echo "*********************************"

sudo apt-get -y install cmake mercurial
cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make
make install

echo "*********************************"
echo "7/12 Install libfdk-acc via build tools"
echo "*********************************"

cd ~/ffmpeg_sources
wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
tar xzvf fdk-aac.tar.gz
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean


echo "*********************************"
echo "8/12 Install libmp3lame via apt-get"
echo "*********************************"

apt-get -y install libmp3lame-dev

echo "*********************************"
echo "9/12 Install libopus via apt-get"
echo "*********************************"

apt-get -y install libopus-dev

echo "*********************************"
echo "10/12 Install libvpx build from source"
echo "*********************************"

cd ~/ffmpeg_sources
wget http://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2
tar xjvf libvpx-v1.3.0.tar.bz2
cd libvpx-v1.3.0
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests
PATH="$HOME/bin:$PATH" make
make install
make clean

echo "*********************************"
echo "11/12 Install ffmpeg build from source"
echo "*********************************"

cd ~/ffmpeg_sources
wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree
PATH="$HOME/bin:$PATH" make
make install
make distclean
hash -r

echo "*********************************"
echo "12/12 Moving ffmpeg tool from ~/bin to /bin"
echo "*********************************"

mv ~/bin/ff* /bin











References

 [1]       ffmpeg main website
            Accessed 7/2015
 [2]       ffmpeg compile guide
            Accessed 7/2015




No comments:

Post a Comment