| Version 138 (modified by , 9 years ago) ( diff ) |
|---|
Compile FFmpeg on Ubuntu, Debian, or Mint
Contents
This guide for supported releases of Ubuntu, Debian, and Linux Mint and will provide a local, non-system installation of FFmpeg with support for several common external encoding libraries.
You may also refer to the Generic Compilation Guide for additional information about compiling software.
Recent static builds are also available for lazy people or those who are unable to compile. The static builds do not support non-free encoders.
Note: FFmpeg is part of the Ubuntu packages and can be installed via apt-get install ffmpeg. You may still wish to compile if you want the latest version, experience a bug, or want to customize your build, and it will not interfere with the ffmpeg package in the repository.
This guide is designed to be non-intrusive and will create several directories in your home directory:
ffmpeg_sources– Where the source files will be downloaded. This can be deleted if desired when finished with the guide.ffmpeg_build– Where the files will be built and libraries installed. This can be deleted if desired when finished with the guide.bin– Where the resulting binaries (ffmpeg,ffplay,ffserver,x264,x265) will be installed.
You can easily undo any of this as shown in Reverting Changes Made by This Guide.
Get the Dependencies
Get the dependencies. These are required for compiling, but you can remove them when you are done if you prefer:
sudo apt-get update -qq && apt-get -y install autoconf automake build-essential git libass-dev libfreetype6-dev \ libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \ libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev
Note: Server users can omit the ffplay and x11grab dependencies: libsdl2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev.
In your home directory make a new directory to put all of the source code and binaries into:
mkdir ~/ffmpeg_sources ~/bin
Compilation & Installation
Tip: If you do not require certain encoders you may skip the relevant section and then remove the appropriate ./configure option in FFmpeg. For example, if libvorbis is not needed, then skip that section and then remove --enable-libvorbis from the Install FFmpeg section.
NASM
An assembler used by some libraries.
cd ~/ffmpeg_sources wget http://www.nasm.us/pub/nasm/releasebuilds/2.13.01/nasm-2.13.01.tar.bz2 tar xjvf nasm-2.13.01.tar.bz2 cd nasm-2.13.01 ./autogen.sh PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" make make install
Yasm
An assembler used by some libraries.
If your repository provides yasm version ≥ 1.2.0 then you can install that instead of compiling:
sudo apt-get install yasm
Otherwise you can compile:
cd ~/ffmpeg_sources wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz tar xzvf yasm-1.3.0.tar.gz cd yasm-1.3.0 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" make make install
libx264
H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-gpl --enable-libx264.
If your repository provides libx264-dev version ≥ 118 then you can install that instead of compiling:
sudo apt-get install libx264-dev
Otherwise you can compile:
cd ~/ffmpeg_sources git clone --depth 1 http://git.videolan.org/git/x264 cd x264 PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static PATH="$HOME/bin:$PATH" make make install
libx265
H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.
If your repository provides libx265-dev version ≥ 68 then you can install that instead of compiling:
sudo apt-get install libx265-dev
Otherwise you can compile:
sudo apt-get install -y 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 PATH="$HOME/bin:$PATH" make make install
libfdk-aac
AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-libfdk-aac (and --enable-nonfree if you also included --enable-gpl).
If your repository provides libfdk-aac-dev then you can install that instead of compiling:
sudo apt-get install libfdk-aac-dev
Otherwise you can compile:
cd ~/ffmpeg_sources git clone --depth 1 https://github.com/mstorsjo/fdk-aac cd fdk-aac autoreconf -fiv ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install
libmp3lame
MP3 audio encoder.
Requires ffmpeg to be configured with --enable-libmp3lame.
If your repository provides libmp3lame-dev version ≥ 3.98.3 then you can install that instead of compiling:
sudo apt-get install libmp3lame-dev
Otherwise you can compile:
cd ~/ffmpeg_sources wget http://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz tar xzvf lame-3.100.tar.gz cd lame-3.100 PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm PATH="$HOME/bin:$PATH" make make install
libopus
Opus audio decoder and encoder.
Requires ffmpeg to be configured with --enable-libopus.
If your repository provides libopus-dev version ≥ 1.1 then you can install that instead of compiling:
sudo apt-get install libopus-dev
Otherwise you can compile:
cd ~/ffmpeg_sources wget https://archive.mozilla.org/pub/opus/opus-1.2.tar.gz tar xzvf opus-1.2.tar.gz cd opus-1.2 ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install
libvpx
VP8/VP9 video encoder and decoder. See the VP9 Video Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-libvpx.
If your repository provides libvpx-dev version ≥ 0.9.7 then you can install that instead of compiling:
sudo apt-get install libvpx-dev
Otherwise you can compile:
cd ~/ffmpeg_sources git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git cd libvpx PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm PATH="$HOME/bin:$PATH" make make install
FFmpeg
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" \ --extra-libs="-lpthread -lm" \ --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 hash -r
Compilation is now complete and ffmpeg (also ffprobe, ffserver, lame, and x264) should now be ready to use. The rest of this guide shows how to update or remove FFmpeg.
Tip: Keep the ffmpeg_sources directory and all contents if you intend to update as shown below. Otherwise you can delete this directory.
Usage
There are several methods to use your new ffmpeg.
- Navigate to
~/binand execute the binary:cd ~/bin && ./ffmpeg -i ~/input.mp4 ~/videos/output.mkv(notice the./) - Or use the full path to the binary:
~/bin/ffmpeg -i ../input.mp4 ../videos/output.mkv
If you want the ffmpeg command to just work from anywhere:
- Log in and log out
- Or run
source ~/.profile
Note: ~/bin is included in the standard Ubuntu $PATH by default (via the ~/.profile file), but only when the ~/bin directory actually exists. This is why you must log out then log in or run source ~/.profile if you just created ~/bin. See Ubuntu Wiki: Persistent Environment Variables for more info.
Documentation
If you want to run man ffmpeg to have local access to the documentation:
echo "MANPATH_MAP $HOME/bin $HOME/ffmpeg_build/share/man" >> ~/.manpath
You may then have to log out and then log in for man ffmpeg to work.
HTML formatted documentation is available in ~/ffmpeg_build/share/doc/ffmpeg.
You can also refer to the online FFmpeg documentation, but remember that it is regenerated daily and is meant to be used with the most current ffmpeg (meaning an old build may not be compatible with the online docs).
Updating FFmpeg
Development of FFmpeg is active and an occasional update can give you new features and bug fixes. First you need to delete (or move) the old files:
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffplay,ffserver,x264,x265}
Now just follow the guide from the beginning.
Reverting Changes made by this Guide
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffplay,ffserver,x264,x265,nasm,vsyasm,yasm,ytasm}
sudo apt-get autoremove autoconf automake build-essential cmake git libass-dev libfreetype6-dev \
libmp3lame-dev libopus-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev \
libvorbis-dev libvpx-dev libx264-dev libxcb1-dev libxcb-shm0-dev ibxcb-xfixes0-dev mercurial texinfo zlib1g-dev
sed -i '/ffmpeg_build/c\' ~/.manpath
hash -r
If You Need Help
Feel free to ask your questions at the #ffmpeg IRC channel or the ffmpeg-user mailing list.


