H.264 Basics : CRF Guide
Posted By : Oodles Admin | 05-Nov-2015
Let’s briefly learn about Rate Control and it’s modes. The rate control is a method which decides how many bits will be used in each frame. Further, which results in determining the size of the file and how the quality is distributed. A rate control algorithm dynamically adjusts encoder parameters to achieve a target bitrate.
Generally, two rate control modes are used i.e. Constant Rate Factor and Two-Pass ABR (Adaptive Bit-Rate).
CRF permit you to reach a certain "quality"
Two-Pass permit you to reach a certain "File Size"
Constant Rate Factor (CRF)
The best single pass encoding, CRF is the default quality setting for the x264 encoder. This method is highly used when we are aware that the size of the file is of less importance. CRF allows the encoder to achieve a certain desired output quality for the whole file. In order to keep the requested quality level, each frame of the file get the needed bitrate. The downside is that with CRF method can’t go over a specific size or a bitrate.
CRF values matter
Starting from 0 over the scale, the quantizer scale reaches 51 where
0 is lossless (Lower the value, higher is the quality)
23 is default with same range as 18-28
51 is Worst Video quality
Image with CRF Value: 0
Image with CRF Value: 23
Image with CRF Value: 51
Confused while choosing CRF value?
In the beginning, let’s start with the default value i.e. 23 and change it as per the output requirement.
If the output is not of good quality then set a lower CRF
If the output file size is at higher end then set a higher CRF
It is very important to note that there is a trade off between quality and the file size. So, choose as per your requirement.
The range is exponential, so increasing the CRF value +6 is roughly half the bitrate/filesize while -6 is roughly twice the bitrate/filesize.
0 ← 18← 23 → 28 → 51
Best Quality Standard Worst Video
with max file size Quality Quality with min size
Preset is used to set an encoding speed to the compression ratio. A preset is a collection of options that will provide a certain encoding speed. Slower the preset, better the compression. So, while targeting on a certain file size of constant bit rate, with slower preset you can achieve better quality. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset.
It is advisable to use the slowest preset.
Current presets in descending order of speed are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo.
The default preset is medium.
Make use of Two-Pass when you are targeting on a specific output file size where the Quality of the file doesn’t matter. This method helps you to focus on file size and frame to frame quality becomes of less importance.
Example: Your video is of 5 minutes (5*60=300 seconds) long and an output of 20 MB is desired.
Bitrate = file size in KiloBits / duration in seconds:
20MB*8192 (1024 Kilobyte * 8 bits)/300 = ~546 KiloBits/s total bitrate
546-146(Desired audio bitrate)= 400k video bitrate