Install and Use FFmpeg on Ubuntu

How to Install and Use FFmpeg on Ubuntu

FFmpeg is an open-source project for handling media files, and you can easily install it on Ubuntu. It is an open-source core-command line tool for video and audio-related processing. Several Linux-based media editors use FFmpeg as a base underneath the GUI.

Several media editors such as VLC, YoutTube, and iTunes use FFmpeg as their foundation. Linux users can also use this framework on Ubuntu to accomplish audio and video editing tasks more easily. It not only offers simple operations such as recording, converting, and streaming files but complex editing workflows too.

In this article, you will learn how to install and use FFmpeg on Ubuntu. We will also cover its different uses and a few complex options. So let’s get started.

Syntax

The syntax for the command looks something like this:

ffmpeg [options] input_url

1. Install FFmpeg on Ubuntu

In this step, we will focus on how to install FFmpeg on Ubuntu. We will use the apt package manager for Ubuntu to install this utility. The first step is to update the APT repository in the Ubuntu system and then install the required package.

Update the System

Firstly, update the current repository and packages in your system. In this case, open the Terminal using the shortcut key. The shortcut key for the Terminal is “Ctrl + Alt + T”, then use the update command with the required repository. For example:

sudo apt update && sudo apt upgrade

The output should look something like this:

install and use ffmpeg on Ubuntu

Install the FFmpeg Package on Linux

Secondly, install the ffprobe package in your updated system. In this case, you will have to install the FFmpeg package first. Then you can install the ffprobe library. Execute the command given below: 

sudo apt install ffmpeg

You should get a similar output:

install and use ffmpeg on Ubuntu

Wait for the installation to complete. 

Verify the FFmpeg Installation on Ubuntu

Now that the installation is complete, you can now verify it using the following command: 

ffmpeg -version

Alternatively, you can also type in the FFmpeg command. For instance:

ffmpeg

2. Use FFmpeg on Ubuntu

Now that you have installed the FFmpeg utility, let’s look at a few examples of how you can use it to stream, edit and convert audio/video files.

Convert Video Format to a Different Destination

FFmpeg supports several video and audio formats such as .mp3, .mp4, .mkv, .acc and many others. To convert a video format, use the -i flag. For example:

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

Make sure to replace the video.mp4 with the name of the video that actually exists in the system. Also, replace video.mkv with the name you want to save the file with.

The following command illustrates that:

install and use ffmpeg on Ubuntu

First, mention the source file name, the destination filename, and the extension. Also, this format creates a separate video and preserves the source file.

Convert Video Format Without Preserving the Source File

If you prefer to keep the source file intact, simply remove the -c flag from the FFmpeg command. For instance, type: 

ffmpeg -i video.mp4 video.mkv –hide_banner

Transcode With an Encoder

FFmpeg offers a variety of encoders and decoders for media processing. To view the complete list, type: 

ffmpeg -encoders –hide_banner
ffmpeg -decoders –hide_banner

The output should look something like this:

install and use ffmpeg on Ubuntu

To transcode a video with a specific encoder format, let’s say you want to transcode the video with libx25 encoder and its audio with aac encoder, type: 

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

-c:v represents the video encoder and -c: a indicates the audio encoder. 

Stream a Media from the Web

To stream any media from the internet, convert it and save it to the computer, we can use the FFmpeg command. Use the -i flag for this step. For example:

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

The output should look something like this:

Stream a Media from the Web

Here the command fetches the video from the given URL and converts it into lib265 format and audio in the opus scheme. After that, the video is saved as stream.mp4.

The task does not take that long if the video is short and smaller in size. If the videos are lengthy, you might need a GPU-based processor to transcode the data in real-time. 

However, there is also a way around avoiding straining the CPU processing power. Save the video first and then transcode it later. For this step, modify the command as shown below:

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

Fetch File Information

Apart from that, you can also fetch media information from any video or audio file. For this type: 

ffmpeg -i video.mp4

As you can see, there is a list of information that is not useful. To hide this, use the -hide_banner flag. For instance, type:

ffmpeg -i video.mp4 –hide_banner

And there you go. You can see all sorts of information related to the particular media file. 

Extract Audio from a Video File

You can also separate audio from any video file using this specific command. 

Input:

ffmpeg -i video_file.mp4 -vn audio_file.mp3 -hide_banner

Make sure to replace the videomp4 and audio.mp3 with the names of your file. 

The command illustrates the following output:

Extract Audio from a Video File

And that’s a wrap! The FFmpeg is a powerful utility for media editing and conversion tasks. What we have covered in the article is just the tip of the iceberg. To learn more about this command, visit their official website. In conclusion, you can extract plenty of information by combining it with different format specifiers. 

We hope you found this article to be helpful. If you have any handy examples on FFmpeg, please let us know in the comments section, and we’ll try to answer them in the next articles. Also, be sure to check out the ffprobe guide!

If this guide helped you, please share it.

Leave a Reply
Previous Article
How to Install Flutter on Linux

How to Install Flutter on Linux

Next Article
How to Use Mkfs Command on Linux

How to Use mkfs Command on Linux

Related Posts