How to Compress a Video File using FFmpeg

30 October 2022 | 2 min read
Casper Kloppenburg


FFmpeg is a free and open-source video editing tool capable of trimming, cropping, concatenating, muxing, and transcoding almost any type of media file you throw at it.

It's also a very robust solution for implementing video automation, as we use it extensively in our own video editing API. For this tutorial we'll use FFmpeg 5.1.2, but any recent version will do.

Use a higher compression rate

To shrink the size of a video file, it can be re-encoded with a higher CRF:

$ ffmpeg -i input.mp4 -crf 28 -preset veryslow -c:a copy output.mp4
  • The -crf 28 argument is the Constant Rate Factor. Higher values result in smaller files, but poorer video quality. It's usually a good idea to leave it at 23, but if that makes the file too large, try a higher value like 28.
  • The -preset veryslow argument tells FFmpeg to take a lot longer to compress the video. This results in a better quality/size ratio.
  • The -c:a copy argument tells FFmpeg to simply copy the audio track. The audio track is only a small part of the file, so compressing it more is usually not worth it.

If you want to compress the audio track as well, you can do it like this: $ ffmpeg -i input.mp4 -crf 28 -preset veryslow -c:a aac -b:a 128k output.mp4 With -c:a aac -b:a 128k, the audio is re-encoded as AAC with a bitrate of 128 kbit/s.

Resizing the video

If you want to reduce the size of a video even further, you can also reduce its resolution. Here's how to convert the video to 720p:

$ ffmpeg -i input.mp4 -vf "scale=-2:720" -crf 28 -preset veryslow -c:a copy output.mp4

Reducing the frame rate

Video shot at a high frame rate, like 60 frames per second, can also be compressed by reducing the frame rate:

$ ffmpeg -i input.mp4 -vf "fps=25" -crf 28 -preset veryslow -c:a copy output.mp4

All put together

All the above can be done in a single pass by doing the following:

$ ffmpeg -i input.mp4 -vf "fps=25, scale=-2:720" -crf 28 -preset veryslow -c:a aac -b:a 128k output.mp4

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free