Transcoding with FFmpeg: CRF vs Bitrate, Codecs & Presets

Thu Apr 25 2024

Choose the right rate control and codec: CRF, 2‑pass, VBV, and how presets impact quality and speed.

Picking the right settings is the difference between blurry or bloated outputs. This guide explains CRF vs bitrate, presets, and VBV constraints so you can dial in quality and size.

Rate Control Modes

  • CRF (Constant Rate Factor): choose a quality target; bitrate varies per scene.
  • 2‑pass VBR: target a specific average bitrate; better for strict size limits.
  • CBR: constant bitrate; mainly for legacy hardware or specific broadcast requirements.

Presets and Codecs

Presets trade encoding time for compression efficiency. For x264, ultrafastplacebo. A typical starting point is -preset medium.

Codec choices:

  • H.264 (AVC): great compatibility; solid quality.
  • H.265 (HEVC), VP9, AV1: better compression; slower or less compatible.

Practical Examples

# CRF (x264): quality-first ffmpeg -i in.mp4 -c:v libx264 -preset medium -crf 22 -c:a aac -b:a 128k out.mp4 # 2-pass target bitrate (x264) ffmpeg -y -i in.mp4 -c:v libx264 -b:v 3000k -pass 1 -an -f mp4 /dev/null ffmpeg -i in.mp4 -c:v libx264 -b:v 3000k -pass 2 -c:a aac -b:a 128k out.mp4 # VBV for streaming-like constraints ffmpeg -i in.mp4 -c:v libx264 -preset veryfast -crf 22 -maxrate 5M -bufsize 10M -c:a aac -b:a 160k out_stream.mp4

Pitfalls

  • Don’t set CRF and a fixed -b:v together unless you know why — they compete.
  • Overly tight VBV can cause visible quality pumping.

Start with CRF + preset; switch to 2‑pass only when you must hit a file size or data rate.