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:

<img alt="Update Ubuntu" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-1.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="612" src="data:image/svg xml,” width=”832″>

Proceed with the following code to upgrade:

$ sudo apt-get dist-upgrade

Output:

<img alt="Upgrade Ubuntu" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-2.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="372" loading="lazy" src="data:image/svg xml,” width=”828″>

Now install FFmpeg with the following command:

$ sudo apt-get install ffmpeg

Output:

<img alt="Install FFMpeg" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-3.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="469" loading="lazy" src="data:image/svg xml,” width=”838″>

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:

<img alt="FFmpeg successfully installed" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-4.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="604" loading="lazy" src="data:image/svg xml,” width=”828″>

Installing Encoders and Decoders for FFmpeg

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

$ ffmpeg -encoders

Output:

<img alt="List installed FFmpeg encoders" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-5.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="459" loading="lazy" src="data:image/svg xml,” width=”847″>

$ ffmpeg -decoders

Output:

<img alt="List installed FFmpeg decoders" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-6.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="481" loading="lazy" src="data:image/svg xml,” width=”846″>

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:

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:

<img alt="Convert video files with FFmpeg" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-7.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="514" loading="lazy" src="data:image/svg xml,” width=”733″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-8.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="145" loading="lazy" src="data:image/svg xml,” width=”741″>

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:

<img alt="Create image from video file using FFmpeg" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-9.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="514" loading="lazy" src="data:image/svg xml,” width=”724″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-10.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="387" loading="lazy" src="data:image/svg xml,” width=”721″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-11.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="531" loading="lazy" src="data:image/svg xml,” width=”720″>

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:

<img alt="Convert avi to mp4 using FFmpeg" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-12.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="529" loading="lazy" src="data:image/svg xml,” width=”727″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-13.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="513" loading="lazy" src="data:image/svg xml,” width=”723″>

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:

<img alt="Trim Video file" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-14.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="517" loading="lazy" src="data:image/svg xml,” width=”724″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-15.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="511" loading="lazy" src="data:image/svg xml,” width=”727″>

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:

<img alt="Resize video" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-16.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="526" loading="lazy" src="data:image/svg xml,” width=”718″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-17.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="424" loading="lazy" src="data:image/svg xml,” width=”724″>

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:

<img alt="Convert mp3 to ogg" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-18.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="436" loading="lazy" src="data:image/svg xml,” width=”727″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-19.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="349" loading="lazy" src="data:image/svg xml,” width=”727″>

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:

<img alt="Get audio file info with FFmpeg" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-20.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="520" loading="lazy" src="data:image/svg xml,” width=”729″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-21.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="135" loading="lazy" src="data:image/svg xml,” width=”730″>

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:

<img alt="Get audio file info" data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-22.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="534" loading="lazy" src="data:image/svg xml,” width=”736″>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2023/03/echo/word-image-19742-23.png" data-ez decoding="async" ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="361" loading="lazy" src="data:image/svg xml,” width=”730″>

Conclusion

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