FFmpeg Video Compression Guide

Learn FFmpeg video compression with CRF, codecs, presets, resolution, bitrate, and FFHub API examples for cloud processing.

This guide explains how to compress videos using FFmpeg, with detailed explanations of each parameter.

Understanding the Basic Command

ffmpeg -i input.mp4 -b:v 1M output.mp4

Let's break down each part:

ParameterMeaning
ffmpegThe program we're running
-i input.mp4-i means "input", followed by your source file
-b:v 1M-b:v means "video bitrate", 1M = 1 Megabit per second
output.mp4The output filename (always comes last)

What is bitrate? It's how much data is used per second of video. Higher bitrate = better quality but larger file. Lower bitrate = smaller file but lower quality.

Method 1: CRF (Recommended for Beginners)

CRF (Constant Rate Factor) is the easiest way to compress video. You just pick a quality level:

ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4
ParameterMeaning
-c:v libx264-c:v means "video codec", libx264 is the H.264 encoder
-crf 23Quality level (0-51). Lower = better quality, larger file

CRF Value Guide

CRFQualityWhen to Use
18Excellent (nearly lossless)Archive important videos
23Good (default)General use
28OKShare online, social media
33LowPreviews, drafts

Tip: Start with CRF 23. If the file is too big, try 28. If quality is too low, try 20.

Method 2: Target File Size

If you need a specific file size, use bitrate mode:

ffmpeg -i input.mp4 -c:v libx264 -b:v 2M output.mp4

Common bitrate values:

  • 500K = 500 Kilobits/second (small file, lower quality)
  • 1M = 1 Megabit/second (medium)
  • 2M = 2 Megabits/second (good quality)
  • 5M = 5 Megabits/second (high quality)

Encoding Speed: Presets

The -preset option controls how fast FFmpeg encodes:

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset fast output.mp4
PresetSpeedFile Size
ultrafastVery fastLargest
fastFastLarger
mediumNormal (default)Normal
slowSlowSmaller
veryslowVery slowSmallest

Tip: Use fast for quick results, slow for final delivery.

Reduce Resolution

Smaller resolution = much smaller file:

ffmpeg -i input.mp4 -vf scale=-2:720 -c:v libx264 -crf 23 output.mp4
ParameterMeaning
-vf scale=-2:720-vf means "video filter", scale resizes the video
-2Auto-calculate width to keep aspect ratio
720Target height in pixels (720p)

Common resolutions:

  • scale=-2:2160 → 4K
  • scale=-2:1080 → 1080p (Full HD)
  • scale=-2:720 → 720p (HD)
  • scale=-2:480 → 480p (SD)

Compress Audio Too

Add audio compression to reduce file size further:

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac -b:a 128k output.mp4
ParameterMeaning
-c:a aac-c:a means "audio codec", aac is a common audio format
-b:a 128kAudio bitrate: 128 Kilobits/second

Audio bitrate guide:

  • 320k → High quality music
  • 192k → Good quality
  • 128k → Standard (recommended)
  • 96k → OK for speech

Complete Examples

Best Balance (Recommended)

Good quality, reasonable file size:

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4

Smallest File Size

For sharing online when quality is less important:

ffmpeg -i input.mp4 -vf scale=-2:720 -c:v libx264 -crf 28 -preset slow -c:a aac -b:a 96k output.mp4

Best Quality

For archiving when you want to preserve quality:

ffmpeg -i input.mp4 -c:v libx264 -crf 18 -preset slow -c:a aac -b:a 192k output.mp4

Using FFHub API

Send your command to FFHub to process in the cloud:

curl -X POST https://api.ffhub.io/v1/tasks \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "ffmpeg -i https://your-storage.com/input.mp4 -c:v libx264 -crf 23 -c:a aac -b:a 128k output.mp4"
  }'

Note: Replace the input URL with your actual video URL. FFHub will process it and give you a download link for the result.

Quick Reference

GoalCommand
Basic compressionffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4
Smaller fileffmpeg -i input.mp4 -c:v libx264 -crf 28 output.mp4
Higher qualityffmpeg -i input.mp4 -c:v libx264 -crf 18 output.mp4
Resize to 720pffmpeg -i input.mp4 -vf scale=-2:720 -c:v libx264 -crf 23 output.mp4
With audioffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac -b:a 128k output.mp4
FFmpeg Video Compression Guide — FFHub Docs