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.
Let’s check if the installation was successful. First, test the FFmpeg version using the following command:
Don’t forget to check the available encoders and decoders. To do this, enter the following command:
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:
Now your system should be ready to get Snap packages from the Snapcraft store and install them. Check out FFmpeg on Snapcraft.
Test the installation of FFmpeg by entering the following command:
$ 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:
Now prepare a special directory for storing the source code and the compiled binary files.
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.
- libx264: The H.264 video encoder.
- libx265: The H.265 video encoder (also known as HEVC).
- libvpx: The VP8 / VP9 video encoder / decoder.
- libfdk-aac: The AAC audio encoder.
- libmp3lame: The MP3 audio encoder.
- libopus: The Opus audio encoder / decoder.
- 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.
You can now start building FFmpeg from source. Get the source code by printing:
$ wget -Ö ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/Publications/ffmpeg-snapshot.tar.bz2
Update the PATH environment variable and run the configuration script.
$ –Prefix=“$ HOME/ ffmpeg_build “
$ –extra-clags=“-I$ HOME/ ffmpeg_build / include “
$ –extra-ldflags=“-L$ HOME/ ffmpeg_build / lib “
$ –extra-libs=“-lpthread -lm”
$ –overlay=“$ HOME/Container”
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:
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.
You can now install the FFmpeg version you just created from the source using the following command:
Reload the bash shell to recognize the new FFmpeg binary location.
Test the FFmpeg installation using the following commands:
$ ffmpeg -Decoder
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.
Now let’s take a look at converting audio files. Convert an MP3 file to 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.
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 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.