Skip to content

Compress video on Mac, the better way

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.mp42. 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