FFmpeg -qscale vs -crf: What is the Difference?
When compressing media in FFmpeg, choosing the right rate control
method is crucial for balancing quality and file size. This article
explains the key differences between the -qscale (also
known as -q) and -crf (Constant Rate Factor)
options, detailing how they work, which encoders they apply to, and when
you should use each one to optimize your video and audio encodes.
What is -qscale?
The -qscale (or -q:v for video,
-q:a for audio) option stands for “quality scale.” It
instructs FFmpeg to use a fixed quantization parameter (QP) or quality
level throughout the entire encoding process.
- How it works: It applies a mathematically constant compression level to every frame or audio sample, regardless of how simple or complex the content is.
- Scale range: The scale typically ranges from 1 to 31 (where 1 is the highest quality/largest file size and 31 is the lowest quality), though some encoders use different ranges.
- Best use cases: It is primarily used for older
video encoders (like MPEG-2, MPEG-4 ASP/Xvid, and MJPEG) and specific
audio encoders (such as MP3 via
libmp3lame).
What is -crf?
The -crf option stands for “Constant Rate Factor.” It is
the default and highly recommended quality-setting option for modern
video encoders.
- How it works: Unlike
-qscale, CRF is designed around human visual perception. It dynamically adjusts the quantization level based on the complexity of the scene. It compresses high-motion or highly detailed scenes more aggressively because the human eye cannot easily perceive compression artifacts in fast-moving sequences. Conversely, it allocates more bits to static, simple scenes where compression artifacts would be highly noticeable. - Scale range: For the x264 (H.264) and x265 (H.265) encoders, the scale ranges from 0 to 51. A value of 0 is lossless, while 51 is the worst quality. The default value for x264 is 23, with a visually lossless range usually sitting between 18 and 28.
- Best use cases: It is the standard for modern video
codecs, including H.264 (
libx264), H.265 (libx265), VP9 (libvpx-vp9), and AV1 (libsvtav1).
Key Differences
- Perceptual Optimization:
-crfoptimizes for how humans actually perceive video, allowing it to save significant file size without a noticeable drop in visual quality.-qscaledoes not account for human perception and applies rigid mathematical compression. - Codec Compatibility:
-crfis only supported by modern, advanced video encoders. If you attempt to use-crfwith older encoders like MPEG-4, FFmpeg will return an error or ignore the command. For those older formats and for audio encoding, you must use-qscale. - Efficiency: For video encoding, using
-crfwill almost always result in a smaller file size than-qscalefor the same level of perceived visual quality.