Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.


Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Thread Tools Search this Thread Display Modes
Old 30th April 2022, 14:16   #1  |  Link
Registered User
Join Date: Jan 2020
Posts: 1
CRF algorithm implemented in x264

Hello everyone,
Where I can find CRF algorithm implemented in x264? I want to study the default rate-distortion algorithm in ffmpeg and x264.
I'd appreciate any comment.
aElahi is offline   Reply With Quote
Old 30th April 2022, 21:33   #2  |  Link
Registered User
Join Date: Dec 2013
Location: Berlin, Germany
Posts: 375
CRF is no rate distortion algorithm but a bitrate control mode.

CRF lets you specify a constant picture QP for the whole sequence like constant QP, but in float.

This picture QP is then scaled by the 'complexity' of the local pictures if I remember correctly, someone correct me here please.

the mbtree algorithm and aq mode, which work on a macroblock level, then add to this picture QP to derive a QP for a macroblock.

I think when mbtree is enabled the complexity of a picture is always 1.0, ie no scale, but again I am not so sure about this one.

So I suggest to look at the mbtree, aq mode and bitrate control code.
There is a paper on mbtree here:
https://huyunf.github.io/blogs/2017/...tree paper.pdf
rwill is offline   Reply With Quote
Old 1st May 2022, 01:47   #3  |  Link
Software Developer
LoRd_MuldeR's Avatar
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,249
"CRF" mode without MB-Tree is pretty much just "Quantizer Curve Compression" (qcomp) with a fixed pre-defined scaling factor.

As opposed to the "2-Pass" and "1-Pass ABR" modes, which also are based on the very same "qcomp" algorithm but constantly re-adjust the scaling factor in order to hit a specific target average bitrate.

In "CRF" mode, the fixed scaling factor is computed from the given CRF value, but is not exactly the same as the given CRF value.

The following applies to all RC modes:

Simply put, the "qcomp" algorithm increases the QP for more "complex" frames and lowers the QP for less "complex" frames, where the "complexity" is the estimated bit cost of the frame.

MB-Tree, which is now enabled by default, replaces "qcomp" and extends that idea to the macro-block level. The QP of an individual macro-block now depends on how much that block is going to be referenced in the future.

Adaptive quantization (AQ), which also adjusts the QP's of individual macro-blocks (within the current frame), is kind of "orthogonal" to both, MB-Tree and the traditional "qcomp" algorithm.

See also:
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 1st May 2022 at 02:34.
LoRd_MuldeR is offline   Reply With Quote
Old 2nd May 2022, 12:14   #4  |  Link
Registered User
Join Date: Mar 2011
Posts: 4,852
Was aElahi referring to rate distortion rather than rate control? That is, the psychovisual enhancements (--psy-rd)?
hello_hello is offline   Reply With Quote

crf, rate control, video encoding

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 12:21.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.