How to Install and Use FFmpeg in Ubuntu 22.04

ffmpeg and ubuntu logos on a black/green gradient background

FFmpeg is an open source software to manipulate multimedia files. It can play, record, convert, and stream video and audio files. It comes packaged with leading audio and video codecs.

Many enterprises use FFmpeg in their core processing of their applications. Many consumer applications use FFmpeg as well.

In this tutorial we will install FFmpeg on Ubuntu 22.04 and use a few of its most frequently used features.

[powerkit_alert type=”success” dismissible=”false” multiline=”false”]
If you’d like to learn more about how to use FFmpeg, check out are accompanying in-depth tutorial on FFmpeg which has many more examples to use and details about how it all functions and it’s terminologies.
[/powerkit_alert]

Installing FFmpeg on Ubuntu 22.04

To install FFmpeg on our computer we can use the official Ubuntu package manager apt. Ubuntu’s package manager fetches all the installation files necessary from their own repository. We can do that with the following commands.

First we run the update command to refresh the list of available packages.

sudo apt update

Next we can install FFmpeg on our Ubuntu 22.04 machine:

sudo apt install ffmpeg

We can verify if everything installed correctly, including all the dependency libraries, with the following command.

ffmpeg -version

The output of this command should be something similar to this.

Output
ffmpeg version 4.4-6ubuntu5 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-7ubuntu1)
configuration: --prefix=/usr --extra-version=6ubuntu5 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100

When there’s a new version available you can update with Ubuntu’s Software Update tool.

FFmpeg Usage Examples

Convert Videos with FFmpeg

We can easily convert a video type to another with FFmpeg. We can convert videos between .mp4, .mkv, .mov, .webm and many others including from audio to audio formats, such as .mp3 to .acc.

To do this we run the ffmpeg command on the Ubuntu terminal command line. ffmpeg always needs to specify a file to work with, we always specify the working file with the -i option.

ffmpeg -i video.mp4 -c copy video.mkv

This command simply converts the video from an .mp4 video file to a .mkv video file by simply copying the video data stream and just changing the container.

If we want to transcode the video instead of simply copying it we use the same command minus the -c copy option.

ffmpeg -i video.mp4 video.mkv

Transcoding With a Specific Encoder

FFmpeg has a long list of encoders and transcoders to use. We can take a look at all of them with the following commands.

ffmpeg -encoders
ffmpeg -decoders

We can run the first one to look at all the encoders and the second one to look at all the decoders.

To transcode a video with a specific encoder we run the following command.

ffmpeg -i video.mp4 -c:v libx265 -c:a aac video.mp4

The -c:v option is to specify the video encoder to use and the -c:a option is to specify the audio encoder to use. In our example we are transcoding the video stream with the libx265 encoder and the audio stream with the aac encoder.

Stream a Video from The Web

We can also stream a video from the internet, transcode it and save it on our computer with FFmpeg.

Specifying a URL of a stream on the internet with the -i option, ffmpeg can stream it and process it.

ffmpeg -i https://example.com/stream.m3u8 -c:v libx265 -c:a opus stream.mp4

Here ffmpeg is taking a stream in HLS format, processing it and converting its video stream to the h265 specification, its audio to the opus specification and saving it to a .mp4 video file container.

Depending on the workload we give it, ffmpeg might need a powerful computer as the transcoding tasks are usually CPU intensive. To process the file in real-time like in our example, it’s even more demanding.

A workaround to this is to save the file from the internet and later on do the transcoding process. To do that we modify the command above and use the copy encoder.

ffmpeg -i https://example.com/stream.m3u8 -c copy stream.mp4

The copy encoder option will save the video file without transcoding it.

Fetch Video Information

Sometime we would like to know with what encoder a video or audio file was encoded with. To get that and other information from a file we can use ffmpeg to fetch that info.

ffmpeg -i video.mp4 -hide_banner

word image 81

This command will output us all sort of data such as the encoder used, bitrate, frames per second, pixel format, video resolution and much more.

Conclusion

FFmpeg is a software suite that is available for free on Ubuntu systems. We have shown you how to install it on Ubuntu 22.04.

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

0 Comments
Inline Feedbacks
View all comments
You May Also Like