Saving videos on personal storage drives, cloud services or disks can prove tricky when space is limited. Reducing file sizes makes holding onto larger files and growing collections easier, but some ways of doing this are more effective than others.
There are a lot of tools to choose from in the video-handling arena, capable of optimizing file sizes. However, many of these – including VLC, Cinelerra and Blender – share the same engine beneath their UI – a command-line utility entitled FFMPEG. Here we will show you how you can reduce video file sizes using FFMPEG from Linux terminal.
What Is FFMPEG?
FFMPEG is arguably the most full-featured command-line media-handling utility in the Linux software ecosystem. Among a great gamut of features, this tool can handle the creation of GIFs, chop/edit videos and record as well.
Most importantly, FFMPEG can convert videos at a surprisingly granular level, allowing for quality to be maintained to a large degree while file sizes are positively halved (or even quartered in extreme cases).
Installing FFMPEG in Ubuntu is simple enough to do with the following command:
When the installation has finished, you are ready to get started.
Using FFMPEG can be as simple as the following:
However, to truly reduce file sizes of videos in an optimal way, we’ll need to take certain extension attributes into consideration.
The Optimization Equation
When it comes to video files, not all types are created equally. For instance, avi file extensions tend to be much bigger than mp4 files.
This comes down to the logic built into the container’s intended environment, but even that can be modified by choosing the right codec for encoding your file, favoring quality with larger sizes or portability with smaller ones.
The takeaway here is that the smallest mp4 of a specific video will always be smaller than the smallest avi of the same video, but there is variability in size and quality even within either of these file types.
Interestingly enough, though, mp4s are not the lowest one can go in pursuit of the perfect tiny file size. The current crowned champions of quality retentive video file types are the various containers available for flash videos and Windows media videos (FLV and WMV). These form part of a simple equation we can use to get super-small, yet high-quality video files:
small-container + efficient-codec + low-fps + low-bitrate = tiny/high-quality video file
Note: For the purposes of this article, high-quality means minimal visible pixelation or significant loss of color. A reduction in quality is inevitable to some degree if we really want to optimize file size; however, just how noticeable this is depends on what we are optimizing. Movement speed, color variety and sound quality/density play a part in deciding how low we can go with our settings.
The options are plentiful in the world of video codecs and containers, so we’ll keep things simple by using WMV 8. (FFMPEG does not fully support WMV 9 yet.)
Optimizing a Video
When we run FFMPEG, it will convert our input video to the file type we specify using parameters we set with special flags. Here is our code:
The code above converts our input file into one with a bitrate of 1Mbps, a framerate of 24fps, a constant rate factor of 19 and a .wmv extension. Change “input.mp4” to suit your needs and adjust the
-crf value to a higher number for a smaller file size (with progressively lower quality).
FFMPEG is powerful enough to achieve far more than was touched on here. Its complete feature-set is impressive, and there’s way more to it than just video conversions. Check out the project’s official website for more info.
Our latest tutorials delivered straight to your inbox