How to Install and Use Ffmpeg on Ubuntu 18.04

How to Install and Use Ffmpeg on Ubuntu 18.04

How to Install and Use 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

In order to be able to add new repositories and install packages on your Ubuntu system, you must be logged in as a user with sudo privileges.

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

  1. Next, install FFmpeg by typing the following command:

sudo apt install ffmpeg

  1. To validate that the package is installed properly use the ffmpeg -version command which will print the FFmpeg version:

ffmpeg -version

  1. 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)

  1. 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

In this section we will provide a step by step instructions about how to install FFmpeg version 4.x on Ubuntu 18.04.

The FFmpeg version 4.0 adds a number of new filters, encoders, and decoders. This version is available from the Jonathon F’s PPA.

The steps below describe how to install FFmpeg 4.x on Ubuntu 18.04:

  1. Start by adding the jonathonf/ffmpeg-4 PPA:

sudo add-apt-repository ppa:jonathonf/ffmpeg-4

If you get an error message saying add-apt-repository command not found, install thesoftware-properties-common package.

  1. Once the PPA is added to your system install the FFmpeg package by typing:

sudo apt install ffmpeg

  1. Verify the FFmpeg installation by running the ffmpeg -version command:

ffmpeg -version

The output should look something like this:

ffmpeg version 4.0.3-1~18.04.york0 Copyright (c) 2000-2018 the FFmpeg developers

built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)

FFmpeg 4 is now installed on your system and ready to be used.

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 which simply copies the input stream.

*Convert a video file from mp4 to webm using the libvpx video codec and libvorbisaudio 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