How to reduce video file size with FFMPEG from Linux Terminal

Reduce the file size to help store larger files, and continue to increase the number of files in the collection easier. Some methods of doing this are more effective than others.

Saving videos on personal storage, cloud services, or drives can be difficult when space is limited. Reduce the file size to help store larger files, and continue to increase the number of files in the collection easier. Some methods of doing this are more effective than others.

There are many tools to choose from in the field of video processing, capable of optimizing file size. However, many of these options - including VLC, Cinelerra and Blender - share the same tool behind the user interface - a command-line utility called FFMPEG. Today's article will show you how you can reduce the video file size with FFMPEG from the Linux terminal.

What is FFMPEG?

FFMPEG is arguably the most fully featured command line utility in the Linux software ecosystem. Among a host of great features, this tool can handle creating GIFs, cutting / editing and recording videos.

Most importantly, FFMPEG can convert videos at a surprising rate, allowing quality to be maintained at a high level, while file size is halved (or even a quarter of a few). case).

Setting

Installing FFMPEG in Ubuntu is very simple. Please execute the following command:

 sudo apt install ffmpeg 

How to reduce video file size with FFMPEG from Linux Terminal Picture 1How to reduce video file size with FFMPEG from Linux Terminal Picture 1

When the installation process finishes, you are ready to begin.

Use

Using FFMPEG is also very simple as follows:

 ffmpeg -i input.video output.video 

How to reduce video file size with FFMPEG from Linux Terminal Picture 2How to reduce video file size with FFMPEG from Linux Terminal Picture 2

However, to really reduce the size of the video file in an optimal way, you need to consider the properties of certain file extensions.

Equation optimization

When it comes to video files, not all are created equal. For example, avi file extensions tend to be much larger than mp4 files .

This leads to the logic built into the intended container environment, but can be modified by choosing the appropriate codec to encode files, prioritizing quality at large sizes, or portability with smaller sizes. .

It is worth mentioning that the size of a particular video in mp4 format will always be smaller than the avi format of the same video, but there is a change in size and quality between these file types.

Interestingly, though, mp4 is not the most perfect small file format. The current 'champions' of quality video file types are different containers, available for Flash Video and Windows Media Video (FLV and WMV). Here is part of the simple equation that we can use to get very small but high quality video files:

Small container + Effective Codec + Low Fps + Low Bitrate = Small / high quality video file

Note : For the purposes of this article, "high quality" means discoloration or pixelation (created by displaying a bitmap or part of a bitmap in such a large size that it is visible. the individual pixels, the single colored small square display elements including the bitmap) are at least visible.

Loss of quality is inevitable to some extent, if you really want to optimize the file size. However, how this affects depends on what you are optimizing. Movement speed, color diversity and audio quality / density play a part in determining the level of action for the settings.

The options are rich in the video and container codec world, so we'll keep things simple using WMV 8. (FFMPEG doesn't fully support WMV 9).

Optimize videos

When running FFMPEG, it will convert your input video to the specified file type, using parameters set with special flags. Here is the example code:

 ffmpeg -i input.mp4 -b 1000k -vcodec wmv2 -acodec wmav2 -crf 19 -filter:v fps=fps=24 output.wmv 

How to reduce video file size with FFMPEG from Linux Terminal Picture 3How to reduce video file size with FFMPEG from Linux Terminal Picture 3

How to reduce video file size with FFMPEG from Linux Terminal Picture 4How to reduce video file size with FFMPEG from Linux Terminal Picture 4

The above code converts the example input file into a file with a bit rate of 1Mbps, a frame rate of 24fps, CRF (Constant Rate Factor) of 19 and the extension .wmv. Change 'input.mp4' to suit your needs and adjust the -crf value to a higher number for smaller file sizes (with lower gradual quality).

FFMPEG is powerful enough to do much more than the things mentioned here. Its complete set of features is impressive and there are many ways other than video conversion. Check the project's official website for more information at:

 https://ffmpeg.org/ 
4 ★ | 50 Vote