C.W.K.
Stream
Lesson 03 of 10 · published

Quality Control — CRF, Bitrate, and the Tradeoff

~12 min · crf, bitrate, quality, libx264

Level 0Viewer
0 XP0/73 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Two ways to ask for quality

Software video encoders accept two different quality controls, and you have to know which one to use:

  • CRF (Constant Rate Factor) — "keep this quality, file size is whatever it ends up." Lower number = better quality. Ranges 0 (lossless) to 51 (terrible). For libx264 the sweet spot is 18–23. For libx265 use 22–28 (HEVC's CRF scale is offset). For libsvtav1 try 25–35.
  • Bitrate (-b:v) — "give me this many bits per second." Quality is whatever fits. Used when you have a target file size or are streaming under a network cap. Hardware encoders (videotoolbox, nvenc) usually require bitrate mode; they ignore CRF.

Default to CRF

For 95% of one-off jobs (uploading to YouTube, archiving, sending to a friend), use CRF. You ask for a quality and let the encoder figure out the bitrate. For libx264, CRF 18 looks visually transparent; CRF 23 is fine for casual viewing.

Use bitrate when you must (live streaming bandwidth caps, hardware encoders) or for two-pass encoding (Track 3 lesson 6) where you want a precise final file size.

Code

CRF — quality target·bash
# Visually transparent, larger file (libx264)
ffmpeg -i in.mp4 -c:v libx264 -crf 18 -preset slow -c:a copy out_quality.mp4

# Web-friendly, ~half the size (libx264 default)
ffmpeg -i in.mp4 -c:v libx264 -crf 23 -preset slow -c:a copy out_web.mp4

# Same idea for HEVC — note the higher CRF for similar perceptual quality
ffmpeg -i in.mp4 -c:v libx265 -crf 24 -preset slow -tag:v hvc1 -c:a copy out_h265.mp4

# AV1 (slow encoder, smaller files)
ffmpeg -i in.mp4 -c:v libsvtav1 -crf 32 -preset 6 -c:a copy out_av1.mp4
Bitrate — file-size target·bash
# Single-pass, target ~5 Mbps video
ffmpeg -i in.mp4 -c:v libx264 -b:v 5M -maxrate 5M -bufsize 10M -c:a copy out_5mbps.mp4

# Hardware encoders use bitrate by design
ffmpeg -i in.mp4 -c:v h264_videotoolbox -b:v 8M -c:a aac -b:a 192k out_hw.mp4

External links

Exercise

Take one 60-second 1080p clip. Encode it three ways with libx264 -preset slow: CRF 18, CRF 23, CRF 28. Note the file sizes (should roughly halve each time you go up 6 CRF points). Watch all three full-screen. At what CRF does compression become visible to you?

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.