Skip to content
systemcoding.dev
Media

Encode H.264 at constant quality with -crf 23

Encode H.264 with libx264 in FFmpeg 7.1 using -crf 23, the default constant-quality setting, and learn what moving it by six really does to the file.

1 min read
Summarize in AI

-crf asks x264 for a constant perceptual quality instead of a constant bitrate, so the file size floats with how hard the picture is to compress. The range is 0 to 51, lower is better, and 23 is the default when you give no rate control at all.

Shell
ffmpeg -i input.mov -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 160k out.mp4
Text
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))

The x264 encoding guide notes that a change of six in CRF roughly halves or doubles the bitrate, so going from 23 to 17 gives you a much larger file with a difference you may not see on a phone screen. Work in steps of one to three, and compare on the content you ship.

CRF is a quality target, not a size target. If a platform enforces a bitrate ceiling, add -maxrate and -bufsize alongside it, or use a two-pass encode. This is libx264 as built into FFmpeg 7.1; the builds without GPL components do not contain it, so check ffmpeg -encoders | grep 264 if the encoder is missing.

Taggedffmpeg
Share

More snippets

Media

Seek fast by placing -ss before -i

Put -ss before -i so FFmpeg 7.1 jumps straight to the nearest keyframe instead of decoding and discarding every frame up to the start time.

1 min read
Media

List ALSA devices with aplay -l

List the playback cards and devices ALSA sees with aplay -l from alsa-utils 1.2, and turn the output into a hw:card,device name.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.