FFmpeg: everything you need for multimedia conversion, compression, analysis and more

December 17, 2020 read
FFmpeg: everything you need for multimedia conversion, compression, analysis and more
Computer Programming
Data Science
Media

FFmpeg, is the most powerful tool for multimedia compression, conversion, analysis, and many many more, I believe. For those who are not familiar with the command line interface, FFmpeg could seem daunting initially. But once they overcome that hurdle, FFmpeg becomes their lifelong friend for all multimedia manipulations for its versatility and performance.

In this article, I will scratch the surface of FFmpeg and its related tools (FFprobe and FFplay) by demonstrating how to download, install, compress, convert, play and extract media duration.

Installation:

FFmpeg works on all operating systems. The download page has executable packages for MacOS, Windows and the various Linux distributions. 

There are also static builds (stand-alone executables with all dependencies packaged) for the different operating systems. 

For starters, I suggest downloading a standard executable for your operating system. This will install FFmpeg and all related tools such as FFprobe and FFplay.

To start using the toolset, you need to open a command line interface within the Operating system you use. On MacOS and Linux, you can search for terminal and on Windows, search for CMD.

Convert a multimedia file to another format

FFmpeg can convert between different multimedia file formats. The command below illustrate a simple conversion of a video file from MKV to MP4.

ffmpeg -i example_file_input.mkv -c copy example_file_output.mp4

Replace “example_file_input.mkv” and “example_file_output.mp4” with your input and desired output file names.

Compress a multimedia file

FFmpeg can significantly reduce the size of media files while retaining quality at an incredible level. I have seen over 86% reduction in video files sizes while video quality remained intact.

The sample command below will compress an MP4 input file:

ffmpeg -i example_input.mp4 -vcodec libx264 -crf 20 example_output.mp4

Replace “example_input.mp4” and “example_output.mp4” with your input and desired output file names

Play a multimedia file

FFplay can easily play all types of multimedia files using a very simple command:

ffplay input_file

Replace “input_file” with the multimedia file you want to play.

Advanced use case: Get duration of multimedia file without loading and playing file

In advanced applications such as YouTube and other multimedia content platforms, the length of an audio or video file is indicated on thumbnails or in previews, to provide information about multimedia content before one even interacts with them. This extraction of multimedia length can easily be done with FFprobe. 

 

The command below demonstrates this:

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal input_file

Replace “input_file” with your file name.

To understand the different options used, read the detailed FFMPEG documentation online.

Conclusion

I believe you been introduced to FFmpeg and its related tools. You have also been provided with a few very useful commands to start leveraging this versatile toolset for multimedia manipulations.

If you have any questions and comments, please leave them below and I will be glad to reply to them.

User profile image

Created by

Evans Boateng Owusu

Evans is a Computer Engineer and cloud technology enthusiast. He has a Masters degree in Embedded Systems (focusing on Software design) from the Technical University of Eindhoven (The Netherlands) and a Bachelor of Science in Electronic and Computer Engineering from the Polytechnic University of Turin (Italy). In addition, he has worked for the high-tech industry in the the Netherlands and other large corporations for over seven years.


© Copyright 2024, The BoesK Partnership