How to Install and Use FFmpeg on Ubuntu 18.04

Updated on

3 min read

Install FFmpeg on Ubuntu 18.04

FFmpeg is a free and open-source command-line tool for transcoding multimedia files. It contains a set of shared audio and video libraries such as libavcodec, libavformat, and libavutil. With FFmpeg, you can convert between various video and audio formats, set sample rates, and resize videos.

This tutorial covers the steps required to install FFmpeg on Ubuntu 18.04. We will show you how to install the distro stable version and the latest version of FFmpeg.

The same instructions apply for Ubuntu 16.04 and any Ubuntu-based distribution, including Linux Mint and Elementary OS.

Prerequisites

You need to be logged in as root or user with sudo privileges to complete the installation.

Installing FFmpeg 3.x on Ubuntu

The official Ubuntu repositories contain FFmpeg packages that can be installed with the apt package manager. This is the easiest way to install FFmpeg on Ubuntu. However, the version included in the repositories may lag behind the latest version of FFmpeg.

At the time of writing this article, the current version of FFmpeg available in the Ubuntu 18.04 repositories is 3.4.4.

Perform the steps below to install FFmpeg 3.x on Ubuntu 18.04:

  1. Start by updating the packages list:

    sudo apt update
  2. Next, install FFmpeg by typing the following command:

    sudo apt install ffmpeg
  3. To validate that the package is installed properly use the ffmpeg -version command which prints the FFmpeg version:

    ffmpeg -version

    The output should look something like this:

    ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
    built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)

    To print all available FFmpeg’s encoders and decoders type:

    ffmpeg -encodersffmpeg -decoders

That’s it. FFmpeg 3 is now installed on your system, and you can start using it.

Installing FFmpeg 4.x on Ubuntu

The FFmpeg version 4.x adds a number of new filters, encoders, and decoders.

The easiest way is to install FFmpeg 4.x on Ubuntu 18.04 is by using the snappy packaging system.

Open your terminal by pressing Ctrl+Alt+T and install the FFmpeg snap package, by typing:

sudo snap install ffmpeg

The download may take some time depending on the speed of your connection.

Once done, verify the FFmpeg installation by running the ffmpeg -version command:

ffmpeg -version

The output should look something like this:

ffmpeg version n4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

That’s it! FFmpeg has been installed on your system and ready to be used.

FFmpeg 4 is also available from the Rob Savoury’s PPA .

FFmpeg Examples

In this section, we will look at some basic examples on how to use the ffmpeg utility.

Basic conversion

When converting audio and video files with ffmpeg, you do not have to specify the input and output formats. The input file format is auto-detected, and the output format is guessed from the file extension.

  • Convert a video file from mp4 to webm:

    ffmpeg -i input.mp4 output.webm
  • Convert an audio file from mp3 to ogg:

    ffmpeg -i input.mp3 output.ogg

Specifying codecs

When converting files, you can specify the codecs you want to use with the -c option. The codec can be the name of any supported decoder/encoder or a special value copy that simply copies the input stream.

  • Convert a video file from mp4 to webm using the libvpx video codec and libvorbis audio codec:

    ffmpeg -i input.mp4 -c:v libvpx -c:a libvorbis output.webm
  • Convert an audio file from mp3 to ogg encoded with the libopus codec.

    ffmpeg -i input.mp3 -c:a libopus output.ogg

Conclusion

You have successfully installed FFmpeg on your Ubuntu 18.04. You can now visit the official FFmpeg Documentation page and learn how to use FFmpeg to convert and your video and audio files.

If you hit a problem or have feedback, leave a comment below.