How to Read Encoder Settings — What CRF, Presets, and 2-Pass Actually Change
The flags in an ffmpeg command — -crf 23, -preset slow, -pass 2 — each answer a different question: what to hold constant (CRF), how hard to search (preset), and whether to read the whole video first (2-pass). We derive why each knob works from the quantization-step formula and rate-distortion optimization, then land on copy-paste-ready commands and the mistakes that bite in production.
An Analogy: Three Instructions for a Moving Company
Video encoder settings map surprisingly well onto instructions you might give a moving company.
The first instruction: do you fix the budget, or fix the outcome? If you book two trucks' worth of budget, the cost is fixed no matter how much stuff you own. That is a bitrate target. If instead you say "don't break a single dish — use as many trucks as it takes," the outcome is fixed and the cost floats. That is CRF (a quality target).
The second: how carefully do the movers pack? Given more time, they pack boxes with no wasted space, and the same outcome needs fewer boxes. That is the preset. Fast presets pack sloppily; slow presets pack tightly.
The third: do they walk through the house before packing? Scouting the whole place first lets them plan — big boxes for the bookshelf, small ones for the bathroom. That is 2-pass encoding.
These are three independent knobs. Most confusion about encoder settings comes from mixing them up, so let's open each one.
Intuition: Three Knobs, Three Different Questions
Take a command you'll see everywhere and split it into the questions it answers:
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset slow -c:a copy output.mp4
-crf 23— what stays constant? → quality stays constant; file size is whatever it turns out to be-preset slow— how thoroughly do we search the options? → spend more time to hit the same quality with fewer bits- (absent here)
-pass 1/2— do we read the whole video before spending bits? → only needed when you must hit an exact size
A widespread misconception is "a slower preset gives you better quality." Under CRF that's half wrong: the correct statement is quality stays roughly the same and the file gets smaller. The preset is not a quality knob; it's a knob for how much it costs to reach that quality.
The Root of Everything: QP, or "How Coarsely Do We Round?"
To understand what the three knobs do, you need the single number sitting underneath them all: the quantization parameter (QP).
As covered in video compression from scratch, an encoder splits frames into blocks, transforms them into frequency coefficients, and throws information away by dividing and rounding those coefficients. The divisor — the quantization step — is set in H.264 by an integer QP from 0 to 51, through this relation:
In plain words: every time QP goes up by 6, the rounding gets twice as coarse. Here is the divisor (larger means more information discarded), and is the integer the encoder picks scene by scene. A small QP keeps the coefficients nearly intact — high quality, big file. A large QP flattens most of them to zero — low quality, small file. Every quality/size trade in video encoding is, at bottom, a tug-of-war over this one number.
You can feel what coarse rounding does to a picture right here — this demo is still images, but the principle is identical:
Comments
Sign in to comment