Tool /

Compressing Video with FFmpeg

Large video files are a common reason for slow web pages, especially on mobile. They increase bandwidth usage, delay page loading, hurt user experience, and may cause users to leave.

Using FFmpeg to compress video can significantly reduce file size while keeping acceptable visual quality. This improves loading speed, lowers bandwidth costs, supports mobile playback, and works in mainstream browsers without plugins.

What Is FFmpeg?

FFmpeg is an open-source cross-platform audio and video toolkit. It supports recording, converting, streaming, and compressing almost all common audio and video formats.

Install FFmpeg

On Windows, download a static build from ffmpeg.org, unzip it, and add the bin directory to your PATH.

On macOS, install with Homebrew: brew install ffmpeg.

On Debian or Ubuntu, run sudo apt update and sudo apt install ffmpeg. On RHEL or CentOS, run sudo yum install ffmpeg ffmpeg-devel.

Basic Compression

Compress while keeping the original resolution:

ffmpeg -i input.mp4 -vcodec libx264 -crf 23 -preset medium output.mp4

crf controls quality. Lower values mean higher quality. preset balances speed and quality.

Resize to 1080p:

ffmpeg -i input.mp4 -vf "scale=1920:1080" -vcodec libx264 -crf 23 output.mp4

For stronger compression, use a higher CRF and slower preset:

ffmpeg -i input.mp4 -vcodec libx264 -crf 28 -preset slow -tune film output.mp4

Best Practices

For most web videos, 1080p with CRF 24 provides a good balance between quality and file size:

ffmpeg -i input.mp4 -vf "scale=1920:1080" -vcodec libx264 -crf 24 output.mp4

Test with a short clip before processing the full video. If file size is critical, try CRF 28. Prefer 1080p with a tuned CRF over reducing resolution too far, because very low resolution can look blurry.

FAQ

If quality drops too much, lower the CRF value or use a slower preset. To batch-compress files on Linux or macOS, use a shell loop. If compression is too slow, use a faster preset or hardware acceleration.

Render diagnostics