Rate control (two): CRF detailed

Rate control (two): CRF detailed

In the previous article Rate Control (1): Understanding the Rate Control Mode (x264, x264, vpx) has introduced CRF (Constant Rate Factor), this article further introduces the principle of CRF. CRF is the default rate control mode of x264 and x265, and CRF can also be used in libvpx. The value of CRF is between 0 and 51. The smaller the value, the better the quality, the lower the compression rate, the larger the value, the higher the compression rate, the lower the quality.

CRF does not try to achieve a certain bit rate when performing bit rate control, but to maintain a stable quality. The size of the stream will be determined by the complexity of the source video.

For x264, the recommended value of CRF is between 18 and 28, and the default is 23.

ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4

The default is 28 for x265.

ffmpeg -i input.mp4 -c:v libx265 -crf 28 output.mp4

libvpx does not have a default value, and its CRF ranges from 0 to 63. The recommended value for 1080p video is 31.

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 output.mkv

If you are not sure of the required CRF value, you can start slowly from the default value. If the quality is lower than expected, reduce the CRF, if the file is too large, increase the CRF. Whenever the CRF increases/decreases by 6, the file size will be halved/doubled.

CRF should be used in offline scenarios to achieve optimal results.

How does the bit rate change?

In order to give you an intuitive understanding of the relationship between the bit rate and CRF of videos with different resolutions, the relationship between the average bit rate (MBit/s) and CRF of 4 1-minute videos with different complexity is given below. The encoder is x264.

 

It can be seen that the bit rate and CRF of videos of different resolutions all satisfy the logarithmic relationship.

CRF vs CQP

The CQP mode will keep the QP of each frame unchanged during encoding. For example, if QP=18, the QP of each frame of the entire sequence will be 18 (there will be a QP offset depending on the frame type, but the effect is not significant). The CRF will dynamically adjust the QP of each frame to keep the quality constant. For example, if the encoding is set to CRF=18, the QP may be increased to 20 for frames with more motion, and the QP may be reduced to 16 for frames with less motion.

The figure below shows the change in the number of bits per frame when QP and CRF are equal to 17 and 23.

 

It can be seen that the number of bits of CRF is always less than QP, which means that CRF can save bits while maintaining quality.

Why is sports so important?

Compared with moving objects, human eyes can perceive more details for stationary objects. Therefore, the encoder can use greater compression for moving objects (remove more details) and smaller compression for stationary objects (preserve more details).

The human visual system is distracted by movement, and moving objects stay on the screen for less time, so less distortion can be perceived. The static object stays on the screen for a long time and has enough time to observe and cannot be distracted, so much distortion can be noticed.

What evaluation index is used?

If you compare video quality with simple evaluation indicators such as PSNR, you may find that the quality of CRF is lower than CQP. However, subjective observation of the human eye can find that the quality of CRF is not lower than or even higher than that of CQP. This is because indicators such as PSNR do not consider the perceptual quality and only consider the statistical results of each frame. You can use VQM or VMAF for subjective evaluation.

Translated from: https://slhck.info/video/2017/02/24/crf-guide.html

If you are interested, please follow the WeChat public account Video Coding

 

Guess you like

Origin blog.csdn.net/Dillon2015/article/details/105947341