How to Decrease Video Sizes Using FFmpeg in Linux
Decreasing video sizes becomes necessary when space is limited in cloud services, disks, or personal storage drives. You can easily hold onto larger files by chopping them down to a lower size.
The world of open-source video editing tools is huge. So, choosing one can be tricky. This article explains how you can efficiently decrease video sizes using FFmpeg in Linux.
What is FFmpeg?
So, what is FFmpeg? FFmpeg is a free and open-source command-line utility used in handling audio, video, other multimedia files, and streams in Linux. It has widespread use in video scaling, format transcoding, basic editing, standards compliance, and video post-production effects.
It can create GIFs, edit videos, and record also. You can convert videos at up to a minuscule level while maintaining the quality to a great extent.
MPEG video standards group brought inspiration in defining the name of this media handling software project, while “FF” stands for “Fast Forward”. FFmpeg functions as a backbone of several software projects and renowned media players – YouTube, Blender, VLC, and iTunes, to name a few.
How to Install FFmpeg
Want to get hands-on with it? Let’s install FFmpeg.
Basically, you have to use the following codes for Ubuntu, Arch Linux, and Fedora respectively.
# Debian/Ubuntu sudo apt-get install ffmpeg # Arch Linux sudo pacman -S ffmpeg #REHL/CentOS/Fedora sudo dnf install ffmpeg sudo rpm install ffmpeg sudo yum install ffmpeg
And FFmpeg will be in your Linux distro.
Basic Usage of FFmpeg
To convert a media file using the default settings of FFmpeg, type:
ffmpeg -i inputfile.video outputfile.video
The above command will change the specified format into the output format given.
How to Decrease Video Sizes Using FFmpeg
Going to the basics: Not all video files are created following the same procedure. Hence, file sizes tend to be different. For example, the avi video file extensions are larger than mp4 files.
Takeaway? The smallest mp4 file of a video will be smaller than the smallest avi file of the same video. However, the quality will vary with each of these varied file sizes. Mp4s are not the smallest size you can expect. Various containers for Windows media videos and flash videos (FLV and WMV) are the winners.
Note: The video quality suffers to some degree when we optimize video file size. But, if there’d be a noticeable change or not, that depends on the video we’re optimizing. Color variety, movement speed, and sound quality decide how much trimming is possible for a particular video.
Prerequisites
So, in case you want to decrease file sizes efficiently, you need 4 things.
- Small container
- Excellent codec
- Low bitrate
- Low fps
The x265 codec is an ideal free library for video encoding into H.254/MPEG-H HEVC compression format. So, we’ll be using the x265 codec.
CRF should be between 0 and 51. This is the most compatible with x265 codecs.
Note: The CRF stands for Constant Rate Factor. It’s a default setting for x265 and x264 encoding. The higher the CRF, the higher will be the video compression. Low CRF will produce a high bitrate resulting in high-quality videos.
Decreasing Size of a Video
Let’s make things clear with big_buck_bunny.y4m file of 7GB. We’re going to use FFmpeg to decrease the size of this file. So, the command would be:
ffmpeg -i big_buck_bunny.y4m -vcodec libx265 -crf 28 fps-fps=30 big_buck_bunny.mp4
You’ll see the file size has been reduced to a considerably smaller one, once the file compression is done. In this case, FFmpeg decreases the file size from 7 GB to 26 MB.
Using custom compression you can get good results, but, sometimes the default FFmpeg works better. FFmpeg is more powerful than just being of help for video conversions. The entire set of features is pretty impressive. Visit FFmpeg’s site to discover more about FFmpeg.
The Conclusion
We have reached the end of the tutorial. Today you learned about FFmpeg, the basic usage, and finally, how to use it to decrease video file sizes. Now experiment to determine what works for you.