FFmpeg is an open-source collection of libraries and tools used to process audio, video, and other multimedia-related files. It can be used to compress video size on almost all platforms.
It works great for compression but isn’t limited to it. Some of its applications are format transcoding, video editing, video scaling, etc.
The tool is very useful if you need to send large media files via the internet. Sometimes, large file sizes aren’t feasible for people who are low on storage or who have to frequently send media files over the internet. Compression helps reduce the size of a file takes while preserving the file content.
Using FFmpeg might be challenging to some users, but it is not that complicated. Since it is a command line utility, you can just follow the steps mentioned in this article and reduce your video size.
MPEG, which stands for Moving Picture Experts Group, is a video file saved in digital format. FF in FFmpeg stands for Fast Forward. FFmpeg is the backbone for many software projects and various popular media players like VLC, YouTube, and iTunes.
How to Install FFmpeg on Linux?
Installing FFmpeg on any Linux distribution is fairly easy. Following are the commands you need to execute to install FFmpeg. Please follow the code given for your distribution.
sudo apt-get install ffmpeg
sudo dnf install ffmpeg sudo rpm install ffmpeg sudo yum install ffmpeg
For Arch Linux:
sudo pacman -S ffmpeg
Once you execute the command and enter your password, it will ask for your permission to install the package. Press
Y, and the installation will begin, and FFmpeg will be installed on your Linux machine.
Use FFmpeg to Reduce Video Size (Compress)
To compress videos, we apply a basic technique. We select a small-sized container with a good codec to encode the video, low fps, and low bitrate.
We’ll use the
x265 codec because it is a free library for encoding videos into the
H.254/MPEG-H HEVC compression type. The
x265 codec does the job brilliantly.
We’ll keep the CRF between 0 and 51. CRF stands for Constant Rate Factor. The CRF value of 0 to 51 is ideal with x265 codecs. Higher CRF results in higher video compression. Lower CRF results in high-quality videos as it produces a high bitrate.
CRF 0 doesn’t lose quality at all, while
CRF 51 is the worst quality.
CRF 17-18 is recommended value as the range is visually lossless. If you increase the value of CRF by 6, the video size will be reduced to half. Tweaking with the CRF value can help you get a balance between the required video size and the required video quality using FFmpeg.
In this article, we will take a video file media.y4m and compress it. The initial size of our file is 1.7 GB.
Let’s reduce the size of this video. The command to do that is given below. Execute the command replacing the video file you want to compress.
ffmpeg -i media.y4m -vcodec libx265 -crf 28 media.mp4
-i flag denotes the input file, media.y4m,
-vcodec denotes the video codec,
-crf is the Constant Rate Factor, and media.mp4 is the output file.
A process should start which looks like this:
Once the process is completed, you’ll be shown info regarding the new file size.
We can see that the original video, which was 1.7 GB in size, has been reduced to 2264 kB, which is just around 2.3 MB.
This was a general way of reducing or compressing video size with FFmpeg. There is a drastic size reduction. Naturally, one would think that if the size has decreased so much, the quality must be decreased to unwatchable.
But open the new file, and you’ll be shocked to see not much visual difference. Well, there will be a difference, but that’s worth the size. Our original video, which would take minutes (or hours depending on the internet connection) to upload in a drive or whichever app supports such big media, can be sent now through a simple email or a general messenger.
In this article, we learned how to reduce video size(compress) with FFmpeg. We installed FFmpeg on our machine and used it to compress a video file of 1.7 GB to a significantly smaller size of 2.3 MB.