How to Use FFmpeg Commands for Audio and Video Processing on Linux

Almost anyone who deals with videos may have heard of FFmpeg before. For those who are unfamiliar, FFmpeg is a free and open-source program that can convert any video format to another and alter its codecs.

FFmpeg supports nearly all audio/video codecs (H.264, H.265, VP8, VP9, AAC, OPUS, and more), file formats (MP4, FLV, MKV, TS, WEBM, MP3, etc.), and even streaming protocols (HTTP, RTMP, RTSP, HLS, etc.).

4

Here’s how you may install and use FFmpeg to process audio and video files on Linux.

FFmpeg Installation on Linux

FFmpeg is a free and open-source tool available in the default repositories of almost every major Linux distribution. You can alsoget its source codefor free if you wish to compile it yourself.

If everything goes well during installation, you should be able to see the FFmpeg version when you use the-versionargument.

Dell monitor showing Windows 10 desktop

Getting Video Information With FFmpeg

It is possible to see the information of a video that you want to edit with FFmpeg using the-iflag:

Here, the-hide_bannerparameter’s job is to hide unnecessary information. you may remove this parameter and see the difference in the output.

MacBook and a Dell laptop running ZorinOS next to each other

As you can see, it is possible to get a lot of informationsuch as video codec type, creation date, metadata, and encoder structure of the sample video.

Converting Video or Audio Files to Another Format

One of the most useful features of FFmpeg is that it can convert a video or audio to another format. You can do this with simple one-liners.

MOV to MP4 With FFmpeg

it’s possible to convert your MOV format video file to MP4 with FFmpeg using the command below:

First, use the-iparameter, which stands for input video. Then, enter the file you want to convert. Finally, enter the format you want to convert it to. you could give your output any name you want.

firefox logo with yellow warning symbol

While FFmpeg is running, it will show you the changes it has made on the command screen. Your output file will be stored in your present working directory.

WAV to MP3 With FFmpeg

Similar to videos, you may do the same conversions for audio files. For example, you can convert a WAV audio file to MP3 as follows:

This command has more parameters than the video conversion method, but they are not difficult to understand. To explain these:

video-sound-edit-with-ffmpeg-for-linux

Audio Operations With FFmpeg

FFmpeg can also separate audio from videos. For this, it is sufficient to use the-vnparameter:

If you managed to separate the audio from the video, you can now try to remove the audio from the videos. The difference here is the-anparameter. You should keep this parameter in mind if you want to disable any sound in a video:

Video Size Processing With FFmpeg

Video sizes can be pretty annoying sometimes, especially when you want to upload them somewhere. You no longer need to download programs to trim them as FFmpeg can do this for you. There are some parameters you need to know for this, though:

you may derive many examples using these parameters. For example, if you want to trim a video, you can use something like:

It is also possible to crop only the image inside the video and not the whole video. For this, you may resort to something like:

Here are the parameters used in the aforementioned command:

Editing Videos on Linux With FFmpeg

Editing videos doesn’t end with just trimming and cutting. Sometimes you also need to change the scale of the video. The following command will resize the video to a size you want:

FFmpeg also allows you to combine multiple videos. Imagine you have multiple clips encoded with the same codec. Enter the list of videos you want to merge into a.txtfile. Then, run the following command:

Theconcatparameter here combines your files. It is also possible to rotate videos with FFmpeg:

To rotate videos 180 degrees clockwise, you need to specify the transpose parameter twice:

FPS and GOP Operations

As you know, FPS meansframes per second. GOP (group of pictures) is the distance between two keyframes. FFmpeg is also useful for changing some parameters, including FPS and GOP. If you use the command below, FFmpeg will change the original FPS to the value you set:

For GOP, you can use the-gparameter and set its value to whatever you want. Note that forcing too many keyframes can be harmful to some encoders' forward algorithms.

Create Animated GIFs With FFmpeg

FFmpeg is also ideal forconverting a video to animated GIFs. You can use a simple convert command to do this:

But sometimes, you may want to customize the GIF. You can use the various parameters discussed above to achieve this:

The-rparameter here means the frame rate. As you can see, many different customizations are possible in a single line command.

Extracting Frames From a Video With FFmpeg

Apart from converting one or many images to video, you’re able to also extract frames from a video. The following command will extract one frame every second from your input video. Also, these extracted images will have two-digit names like01.jpeg,02.jpeg, etc. If you wish, you can also add other parameters you have learned.

you may also use other formats such as PNG and BMP for the extracted images.

Why Should You Use FFmpeg on Linux?

As it’s possible to see, FFmpeg is very advantageous in many ways. You do not need to have any technical knowledge or professional Linux experience for this. You can perform various media-processing functions with just a few parameters. If you are going to make edits that are not very long, you do not need expensive computer programs and online premium memberships. Moreover, FFmpeg works very well even on low-end devices.

Also, the features of FFmpeg are not limited to the above. When you read the documentation and user manual, you can see how powerful the software actually is. Even using the–helpparameter and themancommand, you can get more detailed information about using FFmpeg. There are also other great converters for Linux to rival FFmpeg.

Want to bulk convert videos on Linux? Install one of these eight free video converter apps to get the job done.

My iPhone does it all, but I still need my dumb phone.

It saves me hours and keeps my sanity intact.

OneDrive is one of the best, but it has a catch.

Flagship price, mid-range phone.

These plugins will make you wonder why you used Photoshop in the first place.

Technology Explained

PC & Mobile