FFmpeg Video Compression: CRF vs CBR vs VBR Explained

Bitrate Control: Starting From the Basics

To understand the difference between CRF, CBR, and VBR, we first need to talk about bitrate.

Bitrate is the amount of video data produced per unit of time, usually measured in kbps (kilobits per second) or Mbps (megabits per second). It directly determines the clarity, smoothness, and final file size of a video. With the same resolution, frame rate, and codec, a higher bitrate preserves more detail but produces a larger file, while a lower bitrate shrinks the file at the cost of blur, banding, and blocking artifacts.

So why do we need bitrate control at all? The reason is that the complexity of video frames is constantly changing. Static backgrounds and flat color areas can be reconstructed losslessly with very little data, whereas fast motion, rich textures, and abrupt changes require far more bits to stay sharp. If you force a constant bitrate across the entire video, simple scenes waste storage space, and complex scenes starve for bits and visibly degrade.

The core goal of bitrate control is to allocate bits to each frame intelligently, given a fixed storage or bandwidth budget, and to strike the best balance between quality and size. The three modes, CRF, CBR, and VBR, are essentially three different allocation strategies.

The Three Bitrate Control Modes Explained

CRF (Constant Rate Factor)

The guiding principle of CRF is constant quality. The encoder dynamically allocates bits based on the complexity of each frame: it spends fewer bits on simple scenes and more bits on complex scenes, keeping the perceived quality consistent throughout the video. Whether the frame is a still landscape or an action-packed sequence, the viewer experiences roughly the same visual quality.

CRF is controlled by an integer between 0 and 51 (for the x264 and x265 encoders). A lower value means higher quality and a larger file; a higher value means lower quality and a smaller file. A value of 0 produces lossless encoding, 51 is the lowest quality, and 23 is typically the default visually lossless reference point.

The biggest advantage of CRF is simplicity combined with stable quality. You do not need to set a target bitrate in advance, because the encoder automatically distributes bits according to scene complexity. For this reason, CRF is the preferred mode for most non-real-time tasks such as offline compression, file storage, and web publishing.

CBR (Constant Bitrate)

CBR keeps the bitrate fixed for the entire duration. No matter how complex or simple a scene is, the encoder outputs the same amount of data per second. This means that in simple scenes the allocated bits are redundant or even wasted, while in complex scenes the bits may be insufficient, causing visible artifacts.

The strength of CBR lies in its predictability and buffer friendliness. These properties make it especially suited for live streaming and real-time video transmission, where bandwidth stability is critical. In these scenarios the network bandwidth is often fixed, and large bitrate fluctuations can overflow the buffer or congest the network, causing stutter. CBR sacrifices some quality in exchange for transmission stability.

VBR (Variable Bitrate)

VBR allows the bitrate to fluctuate within a specified range. The encoder weighs scene complexity and a target quality, adjusting the bitrate between a configured minimum and maximum. VBR typically requires setting a target bitrate (or target quality) along with upper and lower bounds, making it more flexible than CBR while adding a bitrate constraint that CRF lacks.

VBR is common in scenarios that need to control overall file size while preserving quality, such as streaming segment encoding. It is worth noting that the x264 encoder also offers a 2-pass VBR mode: the first pass scans the entire video to analyze the complexity distribution, and the second pass allocates bits precisely based on that analysis. This mode controls the target size accurately while optimizing bit distribution, but it takes roughly twice as long as a single-pass encode, making it ideal for offline tasks with strict size requirements.

Comparing Bitrate Fluctuations Across the Three Modes

The chart below visualizes how the three modes behave on the same video. CBR is a flat horizontal line, while CRF and VBR both rise and fall with scene complexity. CRF fluctuates more freely, whereas VBR is bounded by its configured floor and ceiling.

流程图 1

How CRF Value Affects Quality and Size

Choosing the right CRF value is the most important step when using CRF mode. The chart below shows how quality and file size change as the CRF value goes from 18 to 30. A lower CRF means higher quality and a larger file, while a higher CRF means a smaller file at the cost of quality.

流程图 2

FFmpeg Command Examples: Three Common Scenarios

Here are three typical compression scenarios, each addressing a different balance of quality and size.

Scenario 1: Email (H.264 + 720p + CRF 28)

Email attachments usually have size limits, so the video needs to be compressed aggressively. 720p resolution with CRF 28 keeps the file small while remaining watchable.


ffmpeg -i input.mp4 \
  -c:v libx264 -preset medium -crf 28 \
  -vf "scale=-2:720" \
  -c:a aac -b:a 128k \
  output.mp4

Scenario 2: Web Publishing (H.264 + 1080p + CRF 26)

Web video needs to balance clarity with loading speed. 1080p with CRF 26 is a common combination that also offers the widest compatibility.


ffmpeg -i input.mp4 \
  -c:v libx264 -preset medium -crf 26 \
  -vf "scale=-2:1080" \
  -c:a aac -b:a 128k \
  output.mp4

Scenario 3: Archival (H.265 + Original Resolution + CRF 20)

Archival prioritizes quality and compression efficiency. Using the H.265 encoder while keeping the original resolution, CRF 20 achieves near-visually-lossless quality at a smaller size than H.264.


ffmpeg -i input.mp4 \
  -c:v libx265 -preset medium -crf 20 \
  -c:a aac -b:a 192k \
  output.mp4

A quick note on the key parameters: -c:v sets the video codec, where libx264 maps to H.264 and libx265 maps to H.265; -preset trades encoding speed for compression efficiency, where slower presets yield better compression; -crf sets the quality level; -vf "scale=-2:720" scales the height to 720 pixels while computing the width proportionally and keeping it even; and -c:a aac -b:a 128k encodes audio as AAC at 128 kbps.

CRF Value Selection Guide

The table below lists common CRF ranges for quick reference. In practice, start with the middle of the recommended range for your scenario, test-encode a short clip, and fine-tune from there.

CRF RangeQuality LevelFile SizeUse Case
18-22High qualityLargeArchival, source backup, high-quality playback
23-26StandardModerateWeb publishing, on-demand streaming, mobile playback
27-30Extreme compressionSmallEmail, instant messaging, bandwidth-constrained delivery

CRF vs CBR vs VBR Comparison

The table below compares the three modes across quality, size, encoding speed, and use case to help you choose based on your needs.

AspectCRFCBRVBR
Quality stabilityHigh (consistent throughout)Low (artifacts in complex scenes)Medium (bounded by bitrate limits)
File sizeUnpredictablePredictableRoughly predictable (2-pass more precise)
Encoding speedFast (single pass)FastSlower (2-pass about twice as long)
Use caseOffline compression, storage, web publishingLive streaming, real-time transmissionStreaming delivery, size-constrained tasks

Frequently Asked Questions

1. How do I choose the right CRF value?

There is no universally correct CRF value; it depends on your trade-off between quality and size. A good starting point is CRF 23-26. If the quality looks good, gradually increase the value to shrink the file further; if the quality is insufficient, decrease the value. For archival needs, 18-22 works well, and for size-sensitive delivery, 27-30 is appropriate.

2. What should I do if the compressed video looks blurry?

Blur is usually caused by insufficient bitrate or over-aggressive downscaling. Check a few things: first, lower the CRF value, for example from 28 to 24, to give the encoder more bits; second, verify that you have not shrunk the resolution too much, and raise it if needed; third, switch to a slower preset (such as slow or slower) to trade encoding time for better compression quality; fourth, confirm that you have not applied overly strong denoise or deinterlace filters, which can also soften the image when misconfigured.

3. Should I choose H.264 or H.265?

H.264 has the widest compatibility, supported by virtually all modern devices, operating systems, and browsers, making it ideal for broad distribution such as web and mobile playback. H.265 (HEVC) is more efficient, producing files roughly 30%-50% smaller than H.264 at the same quality, but it encodes more slowly and is not supported by some older devices and browsers. If your goal is archival or distribution to modern devices, prefer H.265; if maximum compatibility is the priority, choose H.264.

Summary

Bitrate control is the heart of video compression, and choosing the right mode often matters more than tuning specific parameters. CRF prioritizes constant quality and is the first choice for offline compression and file storage; CBR prioritizes bitrate stability and suits live streaming and real-time transmission; VBR strikes a balance between the two and fits distribution scenarios with overall size constraints.

In practice, mastering three points covers most needs: choose the bitrate control mode that matches your scenario, pick a sensible CRF value and fine-tune after a test encode, and select between H.264 and H.265 based on compatibility requirements. Combined with the preset knob for trading speed against efficiency, FFmpeg lets you produce videos that balance quality and size across any scenario.

Related Reading: