Log in

View Full Version : calculation of CRF in x264


taeuber
25th July 2009, 18:54
Good evening!

Today I have a question regarding the calculation of visual quality for a given CRF.
I'm not sure how to express my question exactly so I make an example:

Say you have a film in FullHD resolution and a scaled down version in 640x360.
Both files are encoded with crf=20.
How can I compare the quality of a randomly choosen frame between both files?
To understand this I asked myself about how the crf is used to calculate the visual degradation while encoding.

1. version:
The average visual difference of every macroblock compared to the encoding source is the same in both files.

2. version:
The sum of visual differences of all macroblocks in a frame is below a certain value for each frame?

3. version:
A different kind of calculation without taking macroblock into account.

The resulting question is:
Should files with higher resolution (more macroblocks) be encoded with a smaller rate factor?

Thanks
Lars

Dark Shikari
25th July 2009, 18:58
If you will be watching all video files on the same screen, you can generally get away with higher CRF for higher resolution, because the lower resolution ones will be upscaled to the full screen size, and thus the artifacts will be more visible to the eye.

CRF is not a measure of quality; it is a command to ratecontrol. Different settings and sources at the same CRF are not guaranteed to give the same visual quality.

taeuber
25th July 2009, 19:16
Ok,

to be sure how to understand your answer let me ask again with a second different example:

There is a FullHD film and a second film containing only the upper left quarter of this FullHD film.
The second file then has a resolution of 960x540.

Lets assume I only display the upper left quarter of the FullHD x264 encoded file and the full resolution of the second x264 encoded file on the same display.

How are the ratefactors in relation to get the same visual quality with both files?

Is there somewhere a good explanation of ratefactor in the net?

Thanks again
Lars

LoRd_MuldeR
25th July 2009, 19:24
Ok,

to be sure how to understand your answer let me ask again with a second different example:

There is a FullHD film and a second film containing only the upper left quarter of this FullHD film.
The second file then has a resolution of 960x540.

Lets assume I only display the upper left quarter of the FullHD x264 encoded file and the full resolution of the second x264 encoded file on the same display.

How are the ratefactors in relation to get the same visual quality with both files?

If you display 960x540 version on the HD screen, it will be upscaled (by the screen or by the player) to fill the entire screen.
This upscaling will make compression artifacts more visible! That's why we usually need a lower CRF (less loss) value for that version.

If you display the "full" 1080p version, it won't be upscaled. It will be displayed "as-is" and still fill the screen.
That's why the 1080p version usually can get away with a higher CRF value (more loss). Simply because the "loss" is less visible.

Note that this applies when we assume that both versions are watched in "full screen" mode on a HD screen ;)

Anyway, there is no easy way to recommend a CRF value. You need to find the highest possible CRF value that still satisfies your eyes!
But once you found that CRF value, you can use it for all your future encodes and get pretty similar (but not identical!) results.

Still be ware that you will need to find "your" CRF for any type of source (e.g. Film -vs- Anime) and for any resolution (SD -vs- HD).
You probably won't find the one CRF value that gives satisfactory results for any kind of footage you throw at it...

Is there somewhere a good explanation of ratefactor in the net?

The "Rate Factor" is specific to x264. So the best explanation would be the x264 source code ;)

x264 sources:
http://git.videolan.org/gitweb.cgi?p=x264.git;a=tree

About x264 ratecontrol:
http://git.videolan.org/gitweb.cgi?p=x264.git;a=blob;f=doc/ratecontrol.txt;h=2d05603a19d5a75904a88b6b1cc765fb54fdbf30;hb=HEAD
(That last sentence is obsolete, x264 has AQ now)

ACoolie
25th July 2009, 19:29
If you display 960x540 version on the HD screen, it will be upscaled (by the screen or by the player) to fill the entire screen.
This upscaling will make compression artifacts more visible! That's why we need a lower CRF (less loss) value for that version.

If you display the "full" 1080p version, it won't upscaled. It will be displayed "as-is" and still fill the screen.
That's why the 1080p version usually can get away with a higher CRF value (more loss). Simply because the "loss" is less visible.

Note that this applies when we assume that both versions are watched in "full screen" mode on a HD screen.

I think he means to display both videos on a 960x540 screen (or a 960x540 portion of a regular screen). Instead of downscaling the HD video, he would crop the right and bottom to match the smaller video.

taeuber
25th July 2009, 19:35
Yes,

ACoolie is right.

The upper left quarter of the FullHD film and the file only containing this visual part are displayed on the same screen with the same visual dimensions.
So all displayed pixels of both films are represented by the same account of pixels on the screen.

Lars

taeuber
26th July 2009, 13:54
Ok,

one more question to be sure to get right.

Would it be correct to use the same crf for both files (FullHD and smaller file with upper left quarter cropped) to get the same visual quality?

Thanks
Lars

Audionut
26th July 2009, 14:17
CRF is not a measure of quality; it is a command to ratecontrol. Different settings and sources at the same CRF are not guaranteed to give the same visual quality.

http://forum.doom9.org/showthread.php?p=1308412#post1308412

taeuber
26th July 2009, 14:42
Hi Audionut,

you're right. But that's not _exactly_ the point.
I don't want to be bit exact or want to get something guaranteed.
I want to understand what it means.

Both displayd versions should have as much the same quality as possible. And my question is how are the crf to use in relation.

Maybe it is like this:
In the smaller file there is only a quarter of information to encode and therefore could use a value four times higher than for the FullHD version?

Thanks
Lars

Keiyakusha
26th July 2009, 14:47
I want to understand what it means.

It means you can't compare quality of the different content when using CRF. If you take 1/4 of the frame, you should think of it like about different content. And the same CRF value maybe will be good, but maybe need to be adjusted a bit.