Log in

View Full Version : Understanding the h.264 encoder level


TECK
13th May 2021, 03:21
I'm encoding a movie with h.264 (x264) to 720p 23.976 fps. Level 3.1 should be fine, based on documentation. What would happen to the movie quality if I use level 4.1 instead, which is recommended for 1080p?

Thank you helping me understand.

Selur
13th May 2021, 07:05
First be aware that just using level xy in x264 doesn't do more than set a flag, unless you also set the vbv values reflecting that level the level flag itself it not really useful.
Using a higher level (+vbv) than the minimum requires only helps if before the vbv restrictions restricted the rate control. So unless the bit rate (/quantizer) choice of the rate control is limited due to the rate control nothing happens.

Cu Selur

Asmodian
13th May 2021, 12:21
It will also limit the refs, and things like that. At level 3.1 720p is limited to 5 refs, level 4.0 can use up to 9 ref for 1280x720. You also need level 4.0 or higher for 1080p (limited to 4 references). Using more references is slower to encode but allows more quality per bit, though the difference from using 9 references instead of 5 will not be that significant with most content. Level 4.1 is standard for 1080p (blurays use level 4.1), allowing higher VBV limits but the same number of references as level 4.0.

It is only the VBV that is not set by the level flag in x264. This is often not an issue, but I would still set it if targeting an older limited player or creating content that needs to abide by the level limits.

Selur
13th May 2021, 13:47
Correct, for further info about max ref see: https://forum.doom9.org/showthread.php?t=142758

TECK
13th May 2021, 14:36
My settings:

4.1: x264 Unparse: level=4.1:8x8dct=0:vbv-bufsize=62500:vbv-maxrate=50000
3.1: x264 Unparse: level=3.1:8x8dct=0:vbv-bufsize=14000:vbv-maxrate=14000

Like I said, I always encode my movies to 720p. I'm wondering if I made a mistake all these years for choosing level 4.1 for all my encodings.

benwaggoner
13th May 2021, 18:32
My settings:

4.1: x264 Unparse: level=4.1:8x8dct=0:vbv-bufsize=62500:vbv-maxrate=50000
3.1: x264 Unparse: level=3.1:8x8dct=0:vbv-bufsize=14000:vbv-maxrate=14000

Like I said, I always encode my movies to 720p. I'm wondering if I made a mistake all these years for choosing level 4.1 for all my encodings.
These days, probably not. I can't think of any recent devices with decoders that don't support up to 4.1. If you were going to have compatibility problems, you probably would have hit them years ago way more than now.

TECK
14th May 2021, 00:10
Thanks, from your perspective, is it a good practice to continue this path, or should I just encode the 720p to 3.1, to follow the standards. Will the 720p 4.1 produce a "better" video, presuming the streaming device is compatible up to 5.2 level?

benwaggoner
14th May 2021, 01:18
Thanks, from your perspective, is it a good practice to continue this path, or should I just encode the 720p to 3.1, to follow the standards. Will the 720p 4.1 produce a "better" video, presuming the streaming device is compatible up to 5.2 level?
A higher level's higher VBV options will only make a difference if you were hitting the VBV caps in 3.1. Even then, going to level 3.2 would probably be sufficient unless you have super challenging content or are using a poor quality encoder. For 720p24-30, at --preset slower you're unlikely to see any visible difference between level 3.1 and 6.2

Raising the number of ref frames won't ever hurt anything but encode times, but as said above, isn't likely to yield visible improvements with most content. If you see an improvement, it'd be with low bitrates with low-noise content, like digital anime or motion graphics. More likely your ABR would go down 1-2%. Generally more ref frames don't help with content that's hitting the VBV cap as that's pretty much by definition full of entropy.

The old school compressionist in me always defaults to using the lowest level that's compatible with my frame size and frame rate. But that's and old habit coming from years of sweating compatibility with old devices.

If you want to know if it would help for you, at this point you really need to do an A/B test with your own content and scenario. But that would be mainly for curiosity. If what you've been doing has been working for you all along, it'll keep working for you until AVC decoding gets dropped from moderns chipsets sometime 2050+. The patents are expiring rapidly, so licensing costs won't be a factor much longer.

TECK
31st May 2021, 23:28
Thank you for the useful explanation. Is there a tool that will allow me to see the encoding level used in a .mkv file?

FranceBB
1st June 2021, 11:07
Is there a tool that will allow me to see the encoding level used in a .mkv file?

Mediainfo in the HTML visualization?

It will say something like:

Format profile : Baseline@L4

that "L" stands for "Level".