How to Install and Use FFmpeg on Ubuntu

FFmpeg is open-source and cross-platform that handles a variety of multimedia files. It holds several audio and video libraries such as libavdevice, libavformat, libswscale, and many more. It is an easy stream analyzer for multimedia. Besides being a popular developer tool, it offers a powerful command-line interface for multimedia tasks. This free computer software was developed in 2000. Youtube, Trell, Mux, VLC Media Player, and many popular websites and multimedia platforms use FFmpeg.

This guide will help you to install FFmpeg on Ubuntu 22.04 and Ubuntu 20.04 and shows you how to perform video and audio file conversion using FFmpeg.

Prerequisites

To install FFmpeg, your device must fulfill the following requirements:

  • Ubuntu is installed on your device.
  • Make sure to run as a root user or by Sudo command.

Installing FFmpeg on Ubuntu

FFmpeg resides in the repository of ubuntu. It can be installed using apt–manager. After every six months, a new version is released, whereas the repository contains the previous version concerning the latest version.

It is better to update and upgrade your package list before installing FFmpeg. Type the following code on the terminal to update your package list:

$ sudo apt-get update

Output:

Update Ubuntu

Proceed with the following code to upgrade:

$ sudo apt-get dist-upgrade

Output:

Upgrade Ubuntu

Now install FFmpeg with the following command:

$ sudo apt-get install ffmpeg

Output:

Install FFMpeg

Verification of FFmpeg installation

Type the following command to verify the installation of FFmpeg. The version number will show that FFmpeg is installed.

$ ffmpeg - version

Output:

FFmpeg successfully installed

Installing Encoders and Decoders for FFmpeg

To check whether all encoders and decoders are installed with FFmpeg type the following commands

$ ffmpeg -encoders

Output:

List installed FFmpeg encoders

$ ffmpeg -decoders

Output:

List installed FFmpeg decoders

The above outputs demonstrate that FFmpeg is installed, and you can start working on it.

Common ffmpeg libraries

Here are some known libraries of ffmpeg listed with their usage, which you should know at the initial stage:

Libraries Usage
  1. libavcodec
Contains decoders and encoders for audio/video.
  1. libavdevice
Contains input and output devices.
  1. libavfilter
Contains media filters.
  1. libavutil
Contains functions for simplifying programming.
  1. libavformat
Containing demuxers and muxers.

Usage of FFmpeg

Let’s try out some basic commands of FFmpeg to convert video files, extract audio files, convert any audio file into an Ogg file, convert a video file into an image, edit a video file, extract an audio and video file information, and many more simple tasks:

Conversion of video files with FFmpeg

In the given examples “test” represents the input video file in avi format.

Extract video file information

To know the complete detail of a video file, you use the command given below:

$ ffmpeg -i source_video.avi

Output:

Convert video files with FFmpeg

Conversion of video file into an image

You can easily create an image from a video file using the following code

$ ffmpeg -i source_video.avi image%d.jpg

Output:

Create image from video file using FFmpeg

Here %d represents the number of images created with names such as image1, image2, image3. JPG represents the file extension. You can create images with different file extensions such “as PNG, JPEG, JPG, TIFF, GIF, and more.

Converting a video file into a different format

FFmpeg allows one to convert a video file into a different format such as in mp4, WebM,avi. Try out the given code to convert a video file into mp4 format.

$ ffmpeg -i source_video.avi output.mp4

Output:

Convert avi to mp4 using FFmpeg

Trimming a video file

Ffmpeg allows you to trim the part of the video you want through this command.

$ ffmpeg -ss 00:21 -i source_video.avi -t 00:06 -vcodec copy -acodec copy newfile.mp4

Output:

Trim Video file

In the code given above

  • -ss 00:21 represents the starting time, from which you must start trimming the video from the actual file.
  • -t 00:06 shows the duration of the video file.

Resizing a video file

Ffmpeg offers to resize a video file according to the desired size using -vf scale filter.

$ ffmpeg -i source_video.avi -vf scale=320:240 output.avi

Output:

Resize video

Conversion of Audio files with FFmpeg

In the given examples “sample” represents the input audio file in mp3 format.

Conversion of audio file into Ogg

You can easily convert an mp3 audio file into Ogg using the following code:

$ ffmpeg -i source_audio.mp3 new.ogg

Output:

Convert mp3 to ogg

 

Extract audio file information

To know the complete detail of an audio file, you can use the command given below:

$ ffmpeg -i source_audio.mp3

Output:

Get audio file info with FFmpeg

Extracting audio from a video file

FFmpeg offers an amazing option to extract sound from a video file and save it in mp3 format.

$ ffmpeg -i source_video.avi -vn audio.ogg

Output:

Get audio file info

Conclusion

Using this guide, you can easily install FFmpeg on Linux and learn how to convert media files using FFmpeg.