DEV Community

Monir Uddin
Monir Uddin

Posted on Fully Autonomous

FFmpeg Video Compression: The 5 Settings That Actually Matter

Most "how to compress a video" answers tell you to lower the bitrate and hope for the best. That usually gives you a smaller file that looks noticeably worse.

A better approach is to let the encoder decide how many bits each frame needs. Here are the five settings that make the biggest difference, with copy-paste FFmpeg commands.

1. Pick the right codec

  • H.264 (libx264): plays everywhere, including old phones, browsers and WhatsApp. The safe default.
  • H.265/HEVC (libx265): typically 30 to 50 percent smaller at similar quality, but some older devices and browsers cannot play it.
  • AV1 (libsvtav1): even more efficient, but encoding is slower and support is still uneven.

If you do not know where the file will be played, use H.264.

2. Use constant quality (CRF), not a fixed bitrate

CRF tells the encoder "keep this quality level" and lets the bitrate go up for complex scenes and down for simple ones.

ffmpeg -i input.mp4 -c:v libx264 -crf 22 -preset medium -c:a copy output.mp4
Enter fullscreen mode Exit fullscreen mode

For libx264, the scale is 0 to 51. Lower means better quality and bigger files.

  • 18 to 20: visually close to the source
  • 21 to 24: the sweet spot for most screen recordings and phone videos
  • 26+: visible softening, fine for previews

For libx265, the equivalent values are roughly 4 to 6 higher (start around 26 to 28).

3. Choose a preset

The preset trades encoding time for compression efficiency. Slower presets produce smaller files at the same CRF.

# faster encode, slightly larger file
ffmpeg -i input.mp4 -c:v libx264 -crf 22 -preset veryfast output.mp4

# slower encode, smaller file
ffmpeg -i input.mp4 -c:v libx264 -crf 22 -preset slow output.mp4
Enter fullscreen mode Exit fullscreen mode

medium is a good default. Use veryfast when you are batch-processing a lot of files and time matters more than a few megabytes.

4. Downscale when the viewer does not need the pixels

A 4K screen recording watched on a phone is mostly wasted data. Scaling to 1080p or 720p often has a bigger effect than any other setting.

# scale to 1080p height, keep aspect ratio (-2 keeps width even)
ffmpeg -i input.mp4 -vf "scale=-2:1080" -c:v libx264 -crf 22 -preset medium output.mp4
Enter fullscreen mode Exit fullscreen mode

For tutorials and slide recordings, you can also drop the frame rate:

ffmpeg -i input.mp4 -vf "scale=-2:1080,fps=30" -c:v libx264 -crf 22 output.mp4
Enter fullscreen mode Exit fullscreen mode

Keep the original frame rate for gameplay or sport.

5. Do not forget the audio

Uncompressed or high-bitrate audio can be a surprising share of a small file.

ffmpeg -i input.mp4 -c:v libx264 -crf 22 -preset medium -c:a aac -b:a 128k -movflags +faststart output.mp4
Enter fullscreen mode Exit fullscreen mode

128 kbps AAC is fine for voice. -movflags +faststart moves metadata to the start of the file so it begins playing before it is fully downloaded, which helps on the web.

A complete "good default" command

ffmpeg -i input.mp4 \
  -vf "scale=-2:1080" \
  -c:v libx264 -crf 23 -preset medium \
  -c:a aac -b:a 128k \
  -movflags +faststart \
  output.mp4
Enter fullscreen mode Exit fullscreen mode

Two mistakes to avoid

  1. Re-compressing a compressed file. Every encode loses a little quality. Always start from the original.
  2. Uploading private videos to online compressors. If the recording shows client data, emails or anything internal, compress it locally. FFmpeg and HandBrake both run entirely on your machine.

If you prefer a GUI

  • HandBrake is free and open source. Pick a preset, set RF to about 22, done.
  • Disclosure: I work on Amaar Toolkit, a Windows app from our small team at Amaar Soft that wraps a video compressor and converter, a screen recorder and a PDF editor into one offline app. It is paid, so HandBrake is the better pick if you only need free. Details: https://amaarsoft.com/amaar-toolkit.html

What CRF do you usually use? I would like to hear what works for your type of content.

Top comments (0)