Compress video on Mac, the better way

Jiahao Chen
Nov 3 · 2 min read

You want to reduce the size of a video without loss in quality. If you google ffmpeg compress video, the top answers are

1. StackExchange: Calculate the bitrate by dividing 1 GB by the video length in second, then useffmpeg -i input.mp4 -b .... output.mp4

2. ffmpeg wiki: Choose a CRF value, then a preset, and a tune,then ffmpeg -i input.avi -c:v libx264 -preset ... -crf ... -c:a copy output.mkv

What? Do you have to do math and make hard choices just to compress a video? You don’t. In fact, these commands are slow, and probably won’t give you the output you wanted.

Here’s a simpler, faster way:

  1. ffmpeg -i [FILE].mp4 Put in the filename. In the result, first look for Steam #0 Videothen, in your video stream, look for a data that have the unitkb/s . This is the bitrate of your video stream. It’s completely fine if you don’t know what bitrate means. Just copy down this number.
  2. ffmpeg -i [FILE].mp4 -c:v h264_videotoolbox -b:v [BIT RATE] -c:a aac output.mp4 Put in your filename and bit rate obtained from step 1.
  3. That’s it! Enjoy fast & good quality compression

Explanation:

  1. -i gives you the information of the video
  2. -c:v -c:a -b:v c: codec, b: bitrate, v: video, a: audio
  3. h264_videotoolboxa codec that utilizes macOS hardware acceleration, which make encoding superfast and you won’t be burning your CPU.
  4. But, h264_videotoolbox doesn’t work well with CRF values. Even if you do-crf 0you would still get unacceptably bad quality. That’s why we have to specify the bit rate.
  5. aac offers better quality than mp3 at the same bitrate

Example

Left: Good quality video, compressed with -b:v 3000k. Right: Bad quality video, compressed with -crf 0

Neat! Tips & Tricks

tips about macOS, programming, command-line, and more

Jiahao Chen

Written by

I wish I know the heptapod language…

Neat! Tips & Tricks

tips about macOS, programming, command-line, and more

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade