Install and use FFmpeg on Ubuntu 20.04

FFmpeg is a powerful tool for transcoding multimedia files. It is an open source CLI tool that is available for all major platforms. This program supports a wide range of audio and video libraries, including libavformat, libavutil, libavcodec, etc. FFmpeg can convert audio and video to various formats, resize and configure sample rates, and much more.

This guide will show you how to install and use FFmpeg in Ubuntu 20.04.

Install FFmpeg in Ubuntu

There are two official ways to install FFmpeg on Ubuntu: from the Ubuntu repo (v7.x) and from the snap (v4.x). Depending on your needs, you should choose the most suitable method for you.

It is also possible to compile and install FFmpeg from source code. However, this method is a bit complex and it is recommended that you not follow this method unless you have a specific reason to do so.

Install FFmpeg from Ubuntu Repo

This is the standard method for installing FFmpeg. All you have to do is tell APT to get the program from the standard Ubuntu software repository and install it.

Start a terminal, update the APT cache and install FFmpeg.

$ sudo apt update

$ sudo suitable To install ffmpeg

Let’s check if the installation was successful. First, test the FFmpeg version using the following command:

$ ffmpeg -v

Don’t forget to check the available encoders and decoders. To do this, enter the following command:

$ ffmpeg Encoder

$ ffmpeg -Decoder

Install FFmpeg from snap

FFmpeg is also available as a snap package. If you haven’t configured Snap, you can install it right away by running the following command:

$ sudo apt update && sudo suitable To install snapped -and

$ sudo snap To install Core core20 && sudo systemctl restart snapd

Now your system should be ready to get Snap packages from the Snapcraft store and install them. Check out FFmpeg on Snapcraft.

$ sudo snap To install ffmpeg

Test the installation of FFmpeg by entering the following command:

$ ffmpeg -Execution

$ ffmpeg Encoder
$ ffmpeg -Decoder

Install FFmpeg from source

FFmpeg is an open source tool. It is therefore possible to create this program manually from the source code. This method is only recommended when you are ready to do a custom build, try the latest version, or test for a bug. Instead, for general usage, follow the other methods to install this program. Check out the FFmpeg Official Compilation Guide for Ubuntu.

Building FFmpeg from source requires several dependencies. Enter the following commands to download the dependencies:

$ sudo apt update

$ sudo suitable To install
$ autoconf
$ autom
$ build-essential
$ cmake
$ git-core
$ libass-dev
$ libfreetype6-dev
$ libgnutls28-dev
$ libsdl2-dev
$ libtool
$ libva-dev
$ libvdpau-dev
$ libvorbis-dev
$ libxcb1-dev
$ libxcb-shm0-dev
$ libxcb-xfixes0-dev
$ pkg-config
$ texinfo
$ wget
$ yasm
$ zlib1g-dev

Now prepare a special directory for storing the source code and the compiled binary files.

$ mkdir -pv ~/ffmpeg_source ~/container

Now is the time to prepare some third party libraries. These are the most commonly used with FFmpeg. If you do not need one or more of these libraries, skip the relevant part and ignore the associated one ./configure Opportunity.

  • NASM: An assembler that some libraries rely on.
$ sudo suitable To install nasm

  • libx264: The H.264 video encoder.
$ sudo suitable To install -and libx264-dev

  • libx265: The H.265 video encoder (also known as HEVC).
$ sudo suitable To install -and libx265-dev libnuma-dev

  • libvpx: The VP8 / VP9 video encoder / decoder.
$ sudo suitable To install -and libvpx-dev

  • libfdk-aac: The AAC audio encoder.
$ sudo suitable To install -and libfdk-aac-dev

  • libmp3lame: The MP3 audio encoder.
$ sudo suitable To install libmp3lame-dev
  • libopus: The Opus audio encoder / decoder.
$ sudo suitable To install libopus-dev
  • libaom: The AV1 video encoder / decoder. Note that compilation may fail if you use this. According to the official FFmpeg wiki, this package doesn’t seem to have a stable API yet. It is recommended to avoid these.
$ sudo suitable To install -and libaom-dev

You can now start building FFmpeg from source. Get the source code by printing:

$ CD ~/ffmpeg_source
$ wget ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/Publications/ffmpeg-snapshot.tar.bz2

$ tar -xvf ffmpeg-snapshot.tar.bz2

$ CD ffmpeg

Update the PATH environment variable and run the configuration script.

$ PATH=$ HOME/Container:$ PATH PKG_CONFIG_PATH=$ HOME/ ffmpeg_build / lib / pkgconfig “ ./configure
$ –Prefix=$ HOME/ ffmpeg_build “
$ –pkg-config-flags=“–static”
$ –extra-clags=“-I$ HOME/ ffmpeg_build / include “
$ –extra-ldflags=“-L$ HOME/ ffmpeg_build / lib “
$ –extra-libs=“-lpthread -lm”
$ –overlay=$ HOME/Container”
$ –enable-gpl
$ –enable-gnutls
$ –enable-libaom
$ –enable-libass
$ –enable-libfdk-aac
$ –enable-libfreetype
$ –enable-libmp3lame
$ –enable-libopus
$ –enable-libvorbis
$ –enable-libvpx
$ –enable-libx264
$ –enable-libx265
$ –enable-nonfree

During this process the error “gnutls not found using pkg-config” can occur. To solve this problem, a specific package must be present in the system. You can install the appropriate package and fix this error by running the following command:

$ sudo suitable To install -and libunistring-dev

Now run the configuration script again.

Run the do Command to start compiling FFmpeg. Use the -j flag to run parallel compilation to speed up the process.

$ PATH=$ HOME/Container:$ PATH do -j4

You can now install the FFmpeg version you just created from the source using the following command:

$ sudo do To install

$ hash -R

Reload the bash shell to recognize the new FFmpeg binary location.

$ source ~/.Profile

Test the FFmpeg installation using the following commands:

$ ffmpeg -Execution

$ ffmpeg Encoder
$ ffmpeg -Decoder

Using FFmpeg

After following the steps above, you have now successfully installed FFmpeg. It’s time to learn how to use it. This section shows you some of the most common uses of this tool.

First, convert a video file from MP4 to WebM format. The nice thing about FFmpeg is that you don’t have to specify the input and output formats. FFmpeg automatically detects the source and target format and reacts accordingly. The “-hide_banner” flag is used here to deactivate the configuration information that FFmpeg reports with each run.

$ ffmpeg -hide_banner -I <entry> <exit>

Now let’s take a look at converting audio files. Convert an MP3 file to OGG.

$ ffmpeg -hide_banner -I demo.mp3 demo.ogg

When converting files, it is also possible to specify the codec. Use the “-c” flag followed by the name of a supported encoder / decoder or a copy of a special value. For example, you can convert an MP4 file to WebM format using the video codec libvpx and the audio codec libvorbis.

$ ffmpeg -hide_banner -I demo.mp4 -c: v libvpx -c: a libvorbis demo.webm

It is also possible to convert the audio format with a specific codec. For example, you can convert an MP3 file to OGG by editing the libopus Codec.

$ ffmpeg -hide_banner -I demo.mp3 -c: a Libopus demo.ogg

Final thoughts

FFmpeg is a powerful tool for working with media files. There are many tutorials on various features of FFmpeg and how to use it. Feel free to learn more about this amazing tool. Grab some demo media files and practice mastering FFmpeg with them. Check out this interesting tutorial on how to convert multiple images into one video file.
Enjoy!

Related Posts