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.).

Here’s how you can 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 also get its source code for 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 -version argument.

Getting Video Information With FFmpeg

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

Here, the -hide_banner parameter’s job is to hide unnecessary information. You can remove this parameter and see the difference in the output.

As you can see, it is possible to get a lot of information such 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

You can convert your MOV format video file to MP4 with FFmpeg using the command below:

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

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 can 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:

-vn: Sometimes the audio files you listen to have pictures. These images usually originate from videos. If you do not want such images in the output, you can use this parameter. -ar: This parameter allows you to set the audio frequency of the audio file you want to convert. You can adjust the sound quality and frequency with values such as 8kHz, 44. 1kHz, or 48kHz. -ac: You may have heard the terms mono and stereo before. This parameter can help you set the number of audio channels. -b:a: This parameter allows you to set the audio bitrate per second. The higher the kilobit, the higher the sound quality.

Audio Operations With FFmpeg

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

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 -an parameter. 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:

-ss: Use this parameter to set the start time of the clip -to: Allows you to specify the end time of the clip -c: Set the codec of your clip using this parameter -t: Use this parameter to set the duration of the clip

You can 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 can resort to something like:

Here are the parameters used in the aforementioned command:

-filter:v: This parameter specifies the filtering process you will apply to the video crop: This parameter is for specifying that a clipping operation will be performed w:h:x:y: As you might’ve guessed already, the w, h, x, and y variables denote width, height, and position of the crop box, respectively

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:

-vf: This parameter works the same as the -filter:v argument seen above scale: You can specify the scale sizes you want in your output with this parameter

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 .txt file. Then, run the following command:

The concat parameter here combines your files. It is also possible to rotate videos with FFmpeg:

transpose=0: Flip vertically (default) transpose=1: Rotate 90 degrees clockwise transpose=2: Rotate 90 degrees counterclockwise transpose=3: Flip vertically

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

FPS and GOP Operations

As you know, FPS means frames 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 -g parameter 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 for converting 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 -r parameter 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 can 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 like 01.jpeg, 02.jpeg, etc. If you wish, you can also add other parameters you have learned.

You can also use other formats such as PNG and BMP for the extracted images.

Why Should You Use FFmpeg on Linux?

As you can 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 –help parameter and the man command, you can get more detailed information about using FFmpeg. There are also other great converters for Linux to rival FFmpeg.