When you compress video with FFmpeg, the CRF setting controls the encoder’s quality target. CRF stands for Constant Rate Factor. The value tells the encoder how much compression to apply. The encoder changes how much data it uses for each frame, so the output file size is not fixed.
H.264 and H.265 are video codecs, or methods for compressing video. In FFmpeg, their common encoders are libx264 and libx265. Lower CRF values preserve more detail and produce larger files; higher values produce smaller files with more visible compression.
Start with CRF 23 for H.264 or CRF 28 for H.265, then test the result on your own footage. The numbers use the same scale, but they do not represent equivalent quality across codecs. For making a narrated explainer about video encoding, explainroo uses FFmpeg to assemble the finished MP4; the CRF commands below show how to set encoding quality directly.
What CRF changes
CRF gives the encoder a quality target rather than a bitrate target. Bitrate measures how much data the video uses per second. With CRF, the encoder spends more bits on complex scenes and fewer on simple ones. A calm shot may need less data than a fast, detailed scene, so two videos encoded with the same CRF can have very different file sizes. The FFmpeg CRF overview describes this quality-based approach and the usual starting values.
For libx264 and libx265, the scale runs from 0 to 51. Lower numbers mean higher quality. CRF 0 is lossless mode; the default is 23 for libx264 and 28 for libx265.
| Encoder | Common starting point | Direction to adjust |
|---|---|---|
libx264 |
23 | Lower for more detail; higher for smaller files |
libx265 |
28 | Lower for more detail; higher for smaller files |
These defaults are starting points, not guarantees. A broad reference range is 18–32 for H.264 and 22–36 for H.265, but the right setting depends on the footage and your quality threshold, as noted in Squarebox’s encoding guidance.
Choose a CRF by testing your footage
Start with the default. Encode a short segment that includes the most demanding material in your video, then compare it with the source at the size people will watch it. Lower the CRF if you see distracting blocking or smearing, or if the image loses fine detail. If the image looks good and file size matters more, raise it and compare again.
For sports and other fast-moving footage, a lower CRF is generally needed to avoid visible artifacts. A mostly static screencast may tolerate a higher value, but small text and sharp interface edges still need inspection. Resolution and image detail also affect the result, so one CRF value will not work equally well for every source.
For a video-only H.264 test, use:
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset slow -an output.mp4
For H.265, change the encoder and starting CRF:
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset slow -an output.mp4
The -an option removes audio, which keeps these examples focused on video encoding. Remove it and set an appropriate audio option if the output should include sound.
The -preset setting controls how long the encoder spends compressing the video. Slower presets take longer and generally produce smaller files at the same CRF. They do not set the quality target directly. Keep the preset fixed while comparing CRF values so you can tell which change affected the result.
H.264 and H.265 CRF numbers do not match
A CRF of 23 in H.264 does not produce the same quality as CRF 23 in H.265. The encoders use different compression methods and their CRF scales are codec-specific. Some references treat H.265 CRF 28 as a rough counterpart to H.264 CRF 23, but that is only an approximation, not a reliable conversion rule. A discussion of x264 and x265 settings also emphasizes that the match is not exact.
If you are comparing codecs, encode the same short source segment with each one. Choose each codec’s own starting value, keep other settings as consistent as possible, then compare visible quality, file size, and playback support. Do not choose a codec based on the CRF number alone.
What CRF cannot guarantee
CRF does not promise a particular file size. Complex scenes can require more data, so a fixed CRF may produce unexpectedly large files. If you need a specific file size or bitrate, use bitrate-based encoding rather than relying only on a quality target. Two-pass encoding, for example, aims for a target bitrate while distributing bits according to the video’s complexity.
The same caution applies to published benchmarks. Encoding results depend on the source video, encoder settings, and hardware, so a result for one clip does not predict the size or quality of another. Use tests to judge your footage, not to set universal CRF rules.
Make an explainer video with explainroo
If you want to turn the CRF concepts into a narrated explainer, explainroo is a free, open-source kit that uses a coding agent to create the video. The agent writes the narration and scene descriptions; explainroo handles the voice, timing, visuals, checks, and MP4 assembly with FFmpeg. The documented setup does not specify a CRF control, so use the direct FFmpeg commands above when you need to choose that setting yourself.
To create an explainer, give a coding agent that can run shell commands this prompt, replacing the bracketed topic:
Make me a short explainer video about [how CRF affects H.264 and H.265 video quality]. Use explainroo for it: clone the explainroo repository, read its AGENTS.md and follow the steps.
The agent sets up explainroo and creates the video, then checks it before providing an MP4 file. You can review examples at explainroo’s video gallery or read the project documentation.