Video Streaming with Capped CRF

October 29, 2024
10 Min
Video Education
Jump to
Share
This is some text inside of a div block.

Video compression may not sound exciting until it saves your stream from buffering hell. That's where capped CRF comes in, the solution to smooth playback. This isn’t just another acronym in video tech. It’s the key that lets you stream 4K content without melting your router.

Instead of using the same quality for every frame, Capped CRF adjusts video quality and file size frame by frame. Netflix and YouTube are already using this method, and for good reason. It's changing how we send video over the internet, making sure you get the best picture possible without excessive bandwidth.

What is capped CRF?

Capped CRF (constant rate factor) is a technique used in video encoding to balance video quality and file size. It’s like regular CRF, where the encoder targets a specific quality level throughout the video. However, “capped” CRF introduces a bit rate ceiling to prevent quality fluctuations from causing huge bit rates in complex scenes.

By capping the CRF, the encoder applies a maximum limit on the bit rate, ensuring that even the most demanding scenes don’t overconsume bandwidth or storage. This is useful in scenarios with limited bandwidth, like in streaming platforms, as it keeps video sizes predictable while maintaining consistent visual quality.  

How does capped CRF affect video quality?

Capped CRF keeps the video quality consistent. During video streaming, capped CRF ensures that high-complexity scenes (e.g., explosions, fast movement) won’t spike in bit rate. Without the cap, traditional CRF could allow certain scenes to consume a lot more bandwidth to preserve quality, but in streaming, this can lead to buffering issues or unpredictable data usage.

With capped CRF, the video quality can drop slightly during complex scenes (because of the bit rate limit), but this drop is often controlled and gradual. Essentially, the capped approach helps manage resources while balancing quality, creating a smooth experience for users across varying connection speeds and device types.

CRF values for video streaming

In capped CRF, values range from 0 to 51, where each number represents a different quality level.

  • CRF 0: The video is virtually lossless at this level, meaning there is almost no compression. The bit rate will be high, and the file size will be large because it’s trying to retain the original quality of the content as much as possible. This setting is rarely used in streaming since it consumes significant resources.
  • CRF 51: At the highest value, 51 represents the lowest possible quality. The video becomes highly compressed, with significant loss of detail, making it blurry and filled with artifacts. This value is also impractical for most streaming applications since the quality would be noticeably degraded.

CRF values and video quality

Most encoders use a CRF value between 18 and 28, where lower numbers offer better quality but larger file sizes. For example, CRF 18 is considered visually lossless, meaning it’s hard for the human eye to detect quality loss compared to the source, while CRF 28 gives a more compressed video, suitable for environments where bandwidth is a major constraint.

For example, setting CRF at 23 with a cap might target a medium-high quality while preventing any bit rate spikes during complex scenes, keeping bandwidth and storage predictable.

How FastPix uses VPUs with capped CRF

At FastPix, we’re not just handling video processing; we’re optimizing it. By utilizing Netint’s Quadra video processing units (VPUs), we’ve fine-tuned our video API for both on-demand and live-streaming services.

The Quadra VPUs are designed for performance, with dedicated cores that handle H.264/HEVC encoding, allowing us to move processing tasks off CPUs. This means we can deliver high-resolution video without overloading resources.

Capped CRF provides an ideal balance for large-scale content distribution, effectively managing quality, file size, and bandwidth consumption. At FastPix, we implement this approach across a vast volume of streaming content daily, ensuring consistent video quality while optimizing resources for both VOD and live-streaming platforms.

Optimal CRF values for different video content

When selecting the best CRF values for various video types, it’s important to consider how content complexity affects compression.

For high-motion content like sports, action films, or gaming footage, a lower CRF value (around 18-22) is recommended. These values help maintain clarity during fast-moving scenes without sacrificing too much detail. Since such content is more prone to compression artifacts, keeping the CRF on the lower end ensures a balance between visual quality and reasonable file sizes.

On the other hand, low-motion content such as interviews, vlogs, or talking-head videos can tolerate higher CRF values (around 23-28) because these scenes have fewer visual changes. Higher CRF values work well here as they allow for smaller file sizes while still retaining acceptable visual quality.

For animations or CGI content, CRF values often need to be tweaked further. Because animations can have highly defined lines and uniform color areas, a CRF around 18-21 ensures the video retains its crisp edges and vibrant details, avoiding the kind of artifacts that may be more noticeable in animated or computer-generated scenes.

CRF values for different video resolutions

When encoding videos like Big Buck Bunny, El Fuente, Meridian, and Tears of Steel at various resolutions (240p, 480p, 720p, 1080p, and 2160p), the choice of CRF values becomes critical for maintaining visual quality while optimizing file size.

For lower resolutions, such as 240p and 480p, higher CRF values (around 23-28) can be effectively used without significant quality loss due to the reduced pixel density.

As resolution increases to 720p and above, a lower CRF value (around 18-22) is recommended to preserve detail and clarity in high-motion scenes. This is particularly important for complex animations or fast-paced content where artifacts can become more pronounced.

A graph of different colored linesDescription automatically generated

CRF values and bitrate for different codec

CRF values and bitrate are crucial in determining video quality across different codecs. Each codec, like H.264 or HEVC, has its efficiency in handling CRF settings, impacting the resulting bitrate.  

The relationship between CRF and bitrate varies significantly based on content complexity; fast-motion scenes require tighter CRF values to maintain clarity, while static scenes can tolerate higher values without noticeable degradation.

CRF and bitrate cap for H.264

The table below shows the bitrate and VMAF quality of six files encoded with the H.264 codec using the CRF values with a 6 Mbps cap and using CBR encoding with a 6 Mbps cap.

CRF 19 delivers top-quality video (above 95 VMAF) but uses more bandwidth than necessary for most viewers. For premium services, CRF 21-23 is ideal, balancing high quality (around 95 VMAF) with bandwidth savings.  

Streaming platforms might opt for CRF 25-27 for lower quality but better bandwidth efficiency. This is preferring cost-effectiveness and efficiency over high-end, premium quality.

Video CBR CRF 19 CRF 21 CRF 23 CRF 25
Easy to encode Bitrate VMAF Bitrate VMAF Bitrate VMAF Bitrate VMAF Bitrate VMAF
Big buck bunny 5,245 97.10 3,805 96.55 3,265 96.06 2,802 95.33 2,407 94.24
Talking head 5,390 97.50 3,118 96.94 1,923 96.15 1,277 95.15 895 93.81
Tutorial 3,123 96.77 910 96.83 731 96.38 596 95.30 491 93.37
Hard to encode Bitrate VMAF Bitrate VMAF Bitrate VMAF Bitrate VMAF Bitrate VMAF
Soccer 5,586 93.94 6,013 94.74 6,011 94.74 5,900 94.73 5,608 94.53
Sintel 5,510 96.98 5,416 97.10 4,920 96.70 4,238 95.65 3,522 93.94
Zoo 5,203 96.93 5,885 97.51 5,443 97.28 4,896 96.77 4,265 95.59

How does capped CRF work?

The encoder starts with a target CRF value, say 23. As it processes each frame, it calculates the ideal bitrate to maintain that quality level. But unlike standard CRF, it checks this bitrate against a predefined cap.

If the calculated bitrate exceeds the cap, the encoder dynamically adjusts the CRF value upward for that frame. This increases compression, reducing bitrate while minimizing perceptual quality loss.

The rate control algorithm manages this dynamic adjustment. It's a set of rules that decides how to allocate bits across frames. There are three types of rate control algorithms in video encoding: constant bit rate (CBR), variable bit rate (VBR), and constant rate factor (CRF), with capped CRF as a variation of CRF.

  • CBR: Maintains a constant bitrate throughout the video.
  • VBR: Adjusts the bitrate based on the complexity of the video content.
  • CRF: Focuses on maintaining a consistent quality level without a fixed bitrate.

The algorithm balances moment-to-moment quality decisions with overall bitrate targets. It might allow brief spikes above the cap for complex scenes, then compensate in simpler frames.

The PID (Proportional-Integral-Derivative) controller acts as the core feedback mechanism within the rate control algorithm, continuously fine-tuning the CRF value based on historical, current, and predicted bitrate trends to maintain the optimal quality-to-size ratio.

How does the PID controller improve video quality?

A PID controller continuously calculates an error value, which is the difference between a desired setpoint and the current process variable. In video encoding, the setpoint is the target quality level, while the process variable is the actual quality that viewers receive.  

The PID controller uses three components:

  1. Proportional (P): The proportional component reacts to current deviations in video quality. When there’s a difference between the target and actual quality, it makes immediate adjustments based on the size of the error. The larger the error, the bigger the correction in video quality.
  2. Integral (I): The integral component looks at past errors, gradually adjusting to fix any long-standing quality differences over time.
  3. Derivative (D): Lastly, the derivative component predicts future quality issues by monitoring how quickly the error is changing, helping smooth out sudden shifts, and preventing instability in video quality.

How does CRF allocate bitrate for video quality?

A Group of Pictures (GOP) is a sequence of video frames that organizes how they are encoded for compression. The capping mechanism works with the GOP structure to distribute bitrate across different types of frames within a GOP, which includes I-frames (intra-coded), P-frames (predicted), and B-frames (bi-predicted). An I-frame contains the complete image data of the frame, while P-frames and B-frames reference the I-frame to encode only the differences in pixel data.

Since I-frames contain more information, they naturally demand a higher bitrate. The capping mechanism ensures that these I-frames don’t consume an excessive portion of the available bitrate, which could negatively impact the quality of P- and B-frames that follow.

Capped CRF vs. traditional encoding methods

Capped CRF differs from traditional encoding methods like CBR and VBR. In CBR encoding, the bit rate stays fixed, meaning video quality fluctuates based on the content This often results in wasted bandwidth on simpler scenes and reduced video quality in more complex scenes.  

VBR encoding, on the other hand, allows the bit rate to vary based on scene complexity, allocating more data for high-motion parts and less for simpler segments. However, VBR can lead to unpredictable file sizes and higher bandwidth consumption.

Capped CRF improves on VBR by introducing a cap. It dynamically adjusts the bit rate based on scene complexity (like VBR) but ensures that the rate doesn’t exceed a defined threshold, which makes it more bandwidth-efficient and prevents resource overuse.  

Capped CRF with FFmpeg

Let’s get started with FFmpeg, the old reliable for video processing and capped CRF, using the well-known Sintel film produced by the Blender Foundation. This open-source short film is a perfect benchmark for our encoding experiment. Sintel as both detailed stills and wild action scenes. It's a great test for seeing how Capped CRF handles video of varying complexity.

You can download the latest version of FFmpeg from the official site here: FFmpeg download. It’s free and open source, and it supports a wide range of formats and codecs.

You can download the Sintel film from its official site. All production files are available for free with a Creative Commons license.

In your terminal, use the following command to begin the process:

1ffmpeg -I Sintel.mp4 -c:v libx264 -crf 23 -maxrate 2M -bufsize 4M -preset medium Sintel_CRF23_2M.mp4 

Overview

  • -crf 23: CRF sets the quality target. In this case, CRF 23 offers a good balance between quality and file size. Lower CRF values (e.g., 18-21) will improve quality but increase file size.
  • -maxrate 2M: This caps the bitrate at 2 Mbps, ensuring the output won’t exceed this rate.
  • -bufsize 4M: This is the buffer size that controls how much data is temporarily stored before FFmpeg adjusts the bitrate.
  • -preset: Use the preset option to adjust encoding speed and compression. The “medium” preset is a good starting point, but if you need faster results, try the “fast” or “veryfast” presets.

The final output, Sintel_CRF23_2M.mp4, will be a video file encoded with a CRF value of 23 and a maximum bitrate of 2 Mbps.

How do we analyze encoding statistics in FFmpeg and FFprobe?

To see the encoding process in action, add -stats to the command to monitor the bit rate fluctuations. This will give you valuable insights into how the encoding adjusts as it processes different scenes.

ffmpeg -i Sintel.mp4 -c:v libx264 -crf 23 -maxrate 2M -bufsize 4M -preset medium -stats -f null –

  • -stats: Enables statistics during processing.
  • -f null -: This tells FFmpeg to output to a null format, meaning it won't create a new file. Instead, it will just process the input and display statistics.

If you are interested in detailed encoding specifics, you can use FFprobe. FFprobe is a command-line tool that is part of the FFmpeg framework, developed for analyzing and inspecting multimedia files.

ffprobe -v quiet -print_format json -show_format -show_streams Sintel_CRF23_2M.mp4

Execute this command in your terminal, which gives you an overview of the encoding details for our output file Sintel_CRF23_2M.mp4.


Streaming with FastPix

As the demand for efficient video streaming increases, FastPix is ready to deliver. Our video API supports on-demand and live streaming, utilizing a CDN across over 50 locations to ensure smooth playback and low latency for your audience.  

With capped CRF technology integrated into our encoding process, you can achieve optimal video quality without excessive bandwidth consumption. Combined with built-in video data metrics and in-video AI, optimizing your content strategy has never been easier. Let’s elevate your video experience together.

Sign up for free today!

Frequently asked questions

What is capped CRF in video streaming?

Capped CRF (Constant Rate Factor) is a video encoding technique that balances video quality and file size. Unlike traditional CRF, which allows for variable bit rates, capped CRF sets a maximum bit rate limit to prevent excessive bandwidth usage during complex scenes. This ensures smooth playback without compromising visual quality, making it ideal for streaming high-resolution content.

How does capped CRF improve streaming quality?

Capped CRF enhances streaming quality by maintaining consistent video quality across all scenes. It limits the bit rate during high-complexity scenes, preventing spikes that can lead to buffering and interruptions. This dynamic adjustment allows viewers to enjoy a seamless experience, regardless of their internet connection speed.

What are the benefits of using capped CRF for video encoding?

The benefits of using capped CRF for video encoding include improved streaming performance, reduced buffering, and efficient bandwidth management. By capping the bit rate, content providers can deliver high-quality video without overwhelming network resources, making it an excellent choice for both on-demand and live-streaming applications.

Which CRF values are recommended for streaming?

For optimal streaming quality, CRF values between 18 and 28 are recommended. Lower values, such as 18-22, are ideal for high-motion content like sports and action films, while higher values (23-28) suit low-motion content like interviews and vlogs. This range balances quality and file size, catering to various streaming needs.

How does capped CRF compare to other encoding methods?

Capped CRF differs from traditional encoding methods like Constant Bit Rate (CBR) and Variable Bit Rate (VBR). While CBR maintains a fixed bit rate and VBR varies based on scene complexity, capped CRF combines the benefits of both, ensuring efficient bandwidth usage while maintaining consistent video quality.

Start Live Streaming for free

Enjoyed reading? You might also like

Try FastPix today!

FastPix grows with you – from startups to growth stage and beyond.