Log in

View Full Version : x264 Profiles and Features: Opposite of Expected Behavior


Lyle_JP
27th March 2010, 23:17
So, two days ago, I crated a video rip from DVD with x264. I was happy with the result... until I realized that I used settings that would not play nice with all of my hardware playback devices. So I re-encoded. Now, for the record, the exact same AVS script and build of x264 (Komisar's r1471 w/nal-hrd) was used both times.

The first time the CL looked like this:
--profile high --level 4.2 --preset slow --tune film --crf 18.0 --ref 4 --weightp 1 --trellis 2

The second time, I used this:
--profile main --level 3.1 --preset slow --tune film --crf 18.0 --b-pyramid none --ref 4 --weightp 1 --partitions p8x8,b8x8,i4x4 --no-8x8dct --trellis 2

Okay, so the only real differences (besides profile) are the lack of b-pyramid and 8x8dct, so really I expected these encodes to be nearly identical, and if they weren't I expected the second to be slightly larger than the first. But the opposite happened. Actually disabling b-pyramid and 8x8 dct made the file smaller at the same crf. Smaller by 20% in fact! So these so-called advanced features meant to give same quality at smaller file sizes seem instead to bloat file sizes.

So, is there something wrong with x264's crf calculations, or am I just not understanding something?

Dark Shikari
28th March 2010, 00:47
CRF does not mean "constant quality regardless of the settings you use".

LoRd_MuldeR
28th March 2010, 00:59
So, is there something wrong with x264's crf calculations, or am I just not understanding something?

You have to understand that using "slower" settings (e.g. enabling b-pyramid and 8x8dct) will improve the "quality per size" ratio, but it may also alter the total size at a given CRF.

In other words: By using "slower" settings but sticking with the same CRF value, you may get better quality and a bigger file. Both at the same time.

Anyway, since the the "quality per size" ratio has been improved (due to the "slower" settings), a file of the same quality would be even bigger if it had been produced with "faster" settings.

So after you switched to "slower" settings, you can increase the CRF value, until you get roughly(!) the same file size as before - The quality will still be better than before!

However if your goal is to (visually) compare different settings, you should use 2-Pass mode. Only files of the same total size can be compared visually...

Lyle_JP
28th March 2010, 01:44
CRF does not mean "constant quality regardless of the settings you use".

Fair enough. I was just curious why turning off two features that are intended to give better quality at reduced file sizes... ended up reducing the filesize. As I said before, it just seemed counter-intuitive.

So, if I want the file to be visually the same quality as the first file created (yes, I know, that's highly subjective "measuring"), I will need to increase crf for files created with the main profile? As long as you say that's normal, I'm cool with that. I just wanted to make sure nothing was wrong with x264, or more likely, something was wrong with my logic.

LoRd_MuldeR
28th March 2010, 01:50
So, if I want the file to be visually the same quality as the first file created (yes, I know, that's highly subjective "measuring"), I will need to increase crf for files created with the main profile?

The same CRF value only gives the same visual quality (very roughly) for the same settings and the same type of source.

So if you switch from "fast" to "slow" settings (or vice versa), you may need to re-adjust your CRF value...

Lyle_JP
28th March 2010, 02:03
The same CRF value only gives the same visual quality (very roughly) for the same settings and the same type of source.

So if you switch from "fast" to "slow" settings (or vice versa), you may need to re-adjust your CRF value...

Well, I used slow on both. The difference was main profile vs high profile, but I guess the outcome is the same: cfr 18 main profile is not the same as crf 18 high profile, and I will need to adjust crf accordingly.

Dark Shikari
28th March 2010, 02:03
There's no magical way for x264 to figure out in advance what effect a given setting will have on filesize at a given CRF, particularly for some types of settings. It varies wildly from source to source; if there was an easy way to compensate, we would have already done it.

popper
29th March 2010, 16:03
So, two days ago, I crated a video rip from DVD with x264. I was happy with the result... until I realized that I used settings that would not play nice with all of my hardware playback devices. So I re-encoded. Now, for the record, the exact same AVS script and build of x264 (Komisar's r1471 w/nal-hrd) was used both times.

The first time the CL looked like this:
--profile high --level 4.2 --preset slow --tune film --crf 18.0 --ref 4 --weightp 1 --trellis 2

The second time, I used this:
--profile main --level 3.1 --preset slow --tune film --crf 18.0 --b-pyramid none --ref 4 --weightp 1 --partitions p8x8,b8x8,i4x4 --no-8x8dct --trellis 2

Okay, so the only real differences (besides profile) are the lack of b-pyramid and 8x8dct, so really I expected these encodes to be nearly identical, and if they weren't I expected the second to be slightly larger than the first. But the opposite happened. Actually disabling b-pyramid and 8x8 dct made the file smaller at the same crf. Smaller by 20% in fact! So these so-called advanced features meant to give same quality at smaller file sizes seem instead to bloat file sizes.

So, is there something wrong with x264's crf calculations, or am I just not understanding something?

"until I realized that I used settings that would not play nice with all of my hardware playback devices."

it seems clear enough even though you didnt say what these actually devices,or their capabilitys were , using a level 4.2 or above will NOT Play on Many devices as even BR is restricted Upto and no higher than level 4.1 settings should be giving you a major clue stick,so dont even think about manually setting anything above level 4.1 as you did above.

if you really feel you must manually set one, you do not need to with crf as its got tryed and tested code to auto set it for you on by default , just because the manual option exists and allows you to make massive cli lines to change/override the defaults, using a bigger manual Number does not make a better encode, unless you know Exactly what your doing and why your doing it, dont set it manually, the defaults are there, tryed and test for a Very good reason ,so let them be used with the added benefit that your cli lines are a lot smaller.

as for manually setting profile main again that seems Very odd and perhaps you dont understand that many devices today can play high profile fine if you restrict the encode to no higher than the bitrate limits of your devices you wish to play the encode on.

basic rule of thumb, Never manually set a level above level 4.1 anything higher is pointless until 4:4:4 super 2K/4K HD comes along, let x264 use crf = whatever so it can auto choose the level for the content you give it, so you dont have to even think about it or set it manually in a cli line/app, if the final encode is to low a file size for your likeing (although why anyone would actually complain about getting a smaller filesize for a given really good visual quality is beyond me!), then simply use a lower crf value next time, every 3 doubles/halves the encode size roughly, roughly crf 18 transparency through to crf 26 for good enough and smaller filesize, most people are happy with crf 21/22.