Objective

The objective is to Install FFmpeg on Ubuntu 18.04 Bionic Beaver Linux.

This guide will provide you with an information on how to install FFmpeg on Ubuntu 18.04 from a standard Ubuntu repository as well as how to install latest FFmpeg by compiling it from a source.

Operating System and Software Versions

  • Operating System: - Ubuntu 18.04 Bionic Beaver

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Difficulty

EASY

Conventions

  • # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - requires given linux commands to be executed as a regular non-privileged user

Instructions

Install FFmpeg from Ubuntu Repository

The easiest way to install FFmpeg on Ubuntu is to use the apt command, open up terminal and enter:
$ sudo apt install ffmpeg
In most cases you do not need to go any further. To check for a installed ffmpeg version run:
$ ffmpeg -version
ffmpeg version 3.4.2-1build1 Copyright (c) 2000-2018 the FFmpeg developers
To see all available FFmpeg's encoders and decoders execute:
$ ffmpeg -encoders
$ ffmpeg -decoders


Install FFmpeg from source

This FFmpeg installation will yield the highest possible FFmpeg and codes versions.

Prerequisites

The following linux command will install all FFmpeg compilation prerequisites for Ubuntu 18.04:
 $ sudo apt install -y libopus-dev libmp3lame-dev libfdk-aac-dev libvpx-dev libx264-dev yasm libass-dev libtheora-dev libvorbis-dev mercurial cmake
We will also need libx265-dev development library. However, the version of x256 from Ubuntu's libx265-dev package is lower than expected by latest FFmpeg source code.

You may try to install libx265-dev using $ sudo apt install libx265-dev and fast forward to compilation. However, if you see ERROR: x265 not found using pkg-confg you will need to compile the x256 library from source using the below commands:
$ mkdir ~/ffmpeg; cd ~/ffmpeg
$ hg clone https://bitbucket.org/multicoreware/x265
$ cd 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

Compile and Install FFmpeg

Once we have all the prerequisites installed we are now ready to compile FFmpeg.

First download the latest FFmpeg source code:
$ if [ -d ~/ffmpeg ]; then cd ~/ffmpeg; else mkdir ~/ffmpeg && cd ~/ffmpeg; fi
$ wget -O- http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 | tar xj
Navigate to the newly extracted ffmpeg directory:
$ cd ~/ffmpeg/ffmpeg
Next, compile and install FFmpeg by coping the below text into your terminal and hitting the ENTER key. Be patient as this may take some time:

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
If successful, your should now have the ffmpeg command available on your Ubuntu system:
$ ffmpeg -version
ffmpeg version N-90268-g9fe61b6 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-5ubuntu1)
For additional information on how to remove and update your FFmpeg installation visit https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME or create a JOB ALERT on LinuxCareers.com job portal.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.