Harnessing the Power of FFmpeg: A Guide to Video Compression

Reading Time: 2 minutes
Learn how to use fmpeg command options to change video quality, brightness, frame rate, and more in this in-depth guide.
An example of video compression using FFmpeg

Table of Contents

Introduction: The Necessity of Video Compression

As online streaming and data consumption continue to surge, video compression is now an essential skill. Among a host of tools, FFmpeg stands out for its potent capabilities and flexibility. Ready for a video compression deep dive with FFmpeg?

Explore FFmpeg Command Options

FFmpeg is a magic script, capable of transforming video data with just a single line of command. The power of FFmpeg, however, lies in its vast set of options, aimed at refining and enhancing video compression.

Enhancing Video Compression with FFmpeg

Let’s delve into some of FFmpeg‘s command options that provide the optimal video compression:

  • Resolution upgrade: Scale your video to 720p using -s 1280×720 to enhance the video’s resolution. Here’s an example code for a 720p quality video:
				
					ffmpeg -i input_file.mts -s 1280x720 -c:a copy -c:v h264 -tune output_file.mkv
				
			
  • Increased Compression: By employing the -preset veryslow command, you can highly increase the compression rate. The serialized command would look like this:
				
					ffmpeg -i input_file.mts -preset veryslow -c:a copy -c:v h264 -tune output_file.mkv
				
			
  • Bitrate and Quality Control: You can control the bitrate using -b:v 4000k, and regulate quality with -crf 20 commands. The command would appear thus:
				
					ffmpeg -i input_file.mts -b:v 4000k -crf 20 -c:a copy -c:v h264 -tune output_file.mkv
				
			
  • Frame Rate Adjustment: Adjusting the frame rate is possible by using -r 25, enabling you to alter the video’s frame rate. For example,
				
					ffmpeg -i input_file.mts -r 25 -c:a copy -c:v h264 -tune output_file.mkv
				
			
  • Image Brightening: Brighten your video using -vf “lutyuv=y=val*1.3” or -filter:v lutyuv=”y=gammaval(0.8)” to adjust the brightness of your video:
				
					ffmpeg -i input_file.mts -vf "lutyuv=y=val*1.3" -c:a copy -c:v h264 -tune output_file.mkv
ffmpeg -i input_file.mts -filter:v lutyuv="y=gammaval(0.8)" -c:a copy -c:v h264 -tune output_file.mkv
				
			
  • Two-pass Encoding: Two-pass encoding scans your video twice before finalizing the compression, ensuring superior video quality with the following command:
				
					ffmpeg -i input_file.mts -b:v 4000k -pass 1 -f mkv /dev/null
ffmpeg -i input_file.mts -b:v 4000k -pass 2 output_file.mkv
				
			

Don’t forget to replace input_file.mts and output_file.mkv with your original video file names in all these commands.

Real-world Scenario: Video Compression to the Rescue

In a scenario where startups like Mei’s need to share high-quality videos with investors remotely, FFmpeg comes in handy. By running efficient video compression using FFmpeg, they ensure smooth streaming during online presentations.

Examples

Reduce a video to 64M to send it on WhatsApp

				
					ffmpeg -i input.mp4 -fs 64M -vcodec libx264 -crf 24 output.mp4

				
			

Extract audio from an MP4 file to MP3 without quality loss

				
					ffmpeg -i input.mp4 -vn -q:a 0 output.mp3

				
			

Convert wav to mp3

				
					ffmpeg -i input.wav -acodec mp3 -ab 256k output.mp3


				
			

Conclusion: The Power of FFMpeg

Becoming an FFmpeg pro allows you to control video quality and data handling effectively. The right command options can bring about significant improvements in video compression.

If you have more questions or need additional guidance, Book a Free Consultation with me. Let’s debunk the complexities of video compression together!

Share it on:

Twitter
LinkedIn
Facebook
WhatsApp

About the Author

Gary Gitton
Hello, I'm Gary Gitton - an accomplished Software Engineer, Tech Lead, specializing in PHP, API Engineering, DevOps, and Cloud Management. Throughout my career, I've had the privilege to enhance multiple software solutions with my expertise in multiple languages and platforms. I bring my unique blend of technical and business acumen to every project, ensuring efficient, scalable, and innovative outcomes. I'm also passionate about fostering a culture of continuous learning, mentoring developers, and leading projects with agile methodologies. Whether concocting a bespoke API or orchestrating cloud environments, I'm committed to delivering quality and excellence. Let's connect and transform your vision into a digital reality.

You might also like