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. |
10th October 2014, 21:43 | #1 | Link |
Registered User
Join Date: Sep 2011
Posts: 241
|
H.264 Profiles and Levels discussion
Hi, I was wondering how your program chooses the correct Profile when setting it to Auto? Does it always choose the correct profile?
Also is there a way I can choose the exact level such as High 3.2 instead of just setting "High" and then the program chooses which level to set? Here's the clip I'm converting to 576i Impact 2014 Sep 24 Source Clip. 544 x 576i MPEG2 clip copied directly from my satellite box . I'm using a script to resize to 720 x 576i. There are the settings I use: CRF 17, VeryFast, Tuning None --tff --sar 64:45 --bluray-compat --slices 1 --vbv-bufsize 15000 --vbv-maxrate 15000 --keyint 250 |
10th October 2014, 22:28 | #2 | Link | ||
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Quote:
Quote:
Profiles are restrictions of what features of H.264 you are allowed to use. By default, if "--profile" is not used, x264 will pick the Profile that covers all features you are using in your stream (but not a higher one, since that would be pointless). Consequently, you can enforce a lower Profile than what would be used by default, which will simply turn off those features that are not allowed in the enforced Profile. Enforcing a higher Profile than what would be used by default doesn't make any sense though! What feature should x264 turn on to make your file require the higher Profile? Should it pick a random one? Instead, if you want your stream to be "High" Profile, then simply use at least one "High" Profile feature and that's it! Levels are quite similar to Profiles, in the sense that they also are restrictions. Though Levels restrict other things, such as the maximum resolution, the maximum frame rate, the maximum number of reference frames, and so on. x264 will set the Level that is suitable for your stream (and not a higher one, since that would be pointless). And what Level your stream needs is defined by your input file! You can use "--level" to overwrite the Level. However, if you enforce a Level that is lower than what x264 would have set by default, x264 cannot do much about this, except for showing a warning message that your stream does not actually comply to the Level you have set. And enforcing a Level that is higher than what x264 would have set by default only restricts the compatibility of your stream for zero benefit! To make a long story short: Setting "--profile" can make sense in specific cases, but setting "--level" manually is almost always a bad idea. Simply let x264 do its job...
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 10th October 2014 at 22:48. |
||
10th October 2014, 23:17 | #3 | Link |
Registered User
Join Date: Sep 2011
Posts: 241
|
I understand all that but I'm trying to make a compliant Bluray. For example I'm trying to convert a 1080i PAL HDTV h264 video to 720p 50fps. If you look at the profiles table here: http://forum.doom9.org/showthread.php?t=154533 (under 1.2.1 Primary Video Rules) it shows 720p must have a 4.0 Level. Yet I chose the auto setting and it came out as High Level 3.2.
I was using these settings: --bluray-compat --vbv-maxrate 15000 --vbv-bufsize 15000 --keyint 250 --slices 1 --sar 1:1 So I'm just wondering why it doesn't come out as 4.0 because from what I've seen in the table, it should come out as 4.0? |
10th October 2014, 23:35 | #4 | Link |
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
First of all, when it comes to Levels, a decoder/player that supports Level X actually supports Levels up to X. Feeding the player with a stream that has a lower Level than the player's max. supported Level should never be an issue.
Or in other words: A video stream that complies to Level X also complies to any Level higher than X, tough it may not comply to Levels below X. Since the BluRay standard is a subset of the H.264 standard, i.e. it only supports certain H.264 Profiles and H.264 Levels but there are even more restrictions on top of that, I don't know if supplying a stream that also complies to lower Levels than 4.0 would be acceptable. Anyway, if you look at the Levels Table, you'll notice that Level 3.2 supports 1280x720 video with up to 60 fps and 5 ref frames, so there's simply no need for Level 4.0 if you are dealing with 720p video at 50 fps. To give a car analogy: You are demanding a speed limit of 120 km/h instead of 100 km/h despite your car's maximum speed is only 80 km/h anyway See also: http://www.x264bluray.com/home/720p-encoding
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 10th October 2014 at 23:53. |
11th October 2014, 09:48 | #5 | Link |
PgcEdit daemon
Join Date: Jul 2003
Posts: 7,469
|
I'm not sure I understand that profile and level concepts correctly. I did some tests with different presets (CRF 23, profile auto and level not defined), of course always with the same input file, and obviously the profile and levels depend of the input file, that's right, but also of the preset. For example, I got the Baseline profile when I have encoded the video with the Ultrafast preset, and profile high level 5.1 when the same video has been encoded with the Placebo preset, without any other change. Since my TV refuses to display level 5.0 or higher, I NEED to specify --level 4.1 if I use a slow preset.
Therefore, if I can agree that the characteristics of the input file are important to determine the profile and level used by default by x264, I notice that the preset is at least as important, and I must disagree when you say that "setting --level manually is almost always a bad idea". IMO, setting level to 4.1 (or max 4.2) is essential if you need a good compatibility with most hardware players, and you want to encode with a slow preset. (I wonder if it make sense to use a very slow preset like Placebo and in the same time limit the encoder with --profile high --level 4.1, but it's another question.)
__________________
r0lZ PgcEdit homepage (hosted by VideoHelp) BD3D2MK3D A tool to convert 3D blu-rays to SBS, T&B or FS MKV Last edited by r0lZ; 11th October 2014 at 09:56. |
11th October 2014, 13:48 | #6 | Link |
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Again, the Profile defines which features of H.264 you are allowed to use. See this table for details or look into the H.264 specs (Annex A.2). Which Profile your stream comes out shouldn't depend on the input file at all. Instead it depends on what H.264 features you enable (or not enable). Of course features that influence the required Profile can be enabled/disabled either directly, by the corresponding switch, or indirectly, by the "--preset" switch.
Consequently, your stream will come out at the lowest possible Profile that covers all the features you were using. It cannot come out at an even lower Profile, because that's obviously not allowed by the specs. And it also doesn't come out at an even higher Profile, because that would be totally pointless - your stream doesn't need the even higher Profile, so why should an even higher Profile be indicated? It would only limit the compatibility of the stream - for exactly zero benefit! It's simply the wrong idea to "want" a certain Profile. Instead, the target Profile is given by your intended playback device! If, for example, you playback device only supports "Main" Profile, you need to restrict your settings to "Main" Profile features. And, if your playback device supports "High" Profile, you can use "High" Profile features. Last but not least, if you are allowed to use "High" Profile features and if you actually do enable at least one "High" Profile feature, your stream will come out as "High" Profile automatically. The "--profile" switch is not intended to force a higher Profile; it is intended to enforce at most the specified Profile. Therefore, "--profile X" will turn off all features not allowed in Profile X. And that's it. The Level restricts other things, like the max. resolution, the max. frame rate, the max. number of reference frames, the max. bitrate and so on. So what Level your stream requires partly depends on the input file (resolution, frame rate, etc) and also partly on your encoder settings (number of reference frames, bitrate, etc). By default, if you do not use the "--level" switch, x264 will set the lowest possible Level that your stream complies to. And that's the right thing to do! The reason why I said that using "--level" is almost always a bad idea is because x264 will already set the "correct" Level, if you do not use that switch. Let's assume x264 would set Level X by default. Why would you want to enforce a lower Level than X, i.e. a Level that your stream actually doesn't comply to? It would result in a corrupted stream, because the stream actually requires Level X, but it has been tagged as some Level lower than X. Similarly, why would you want to set a Level higher than X? Your stream complies to Level X, so tagging it as some Level higher than X is pointless. You would restrict the compatibility of your stream for zero benefit! The only reason to use "--level" is when x264 somehow got the Level wrong.
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 11th October 2014 at 14:16. |
11th October 2014, 14:19 | #7 | Link |
Registered User
Join Date: Aug 2009
Posts: 463
|
Well, I know one use for --level. If you encode FHD video with preset placebo it will end up as level 5.1. But, if you use --level 4.1 --preset placebo video will end up as level 4.1 because --level 4.1 will reduce number of reference frames from 16 to 4.
|
11th October 2014, 14:34 | #8 | Link | |
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Quote:
Using the "--level" switch does not reduce the number of reference frames. Instead, x264 will print out a warning, telling you that the selected number of reference frames violates the selected Level: Code:
> x264_8bit_x64.exe --crf 18.0 --preset slower --ref 16 ffms [info]: 1920x1080p 0:1 @ 24000/1001 fps (vfr) x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle x264 [info]: profile High, level 5.1 Code:
> x264_8bit_x64.exe --crf 18.0 --preset slower --ref 16 --level 4.2 ffms [info]: 1920x1080p 0:1 @ 24000/1001 fps (vfr) x264 [warning]: DPB size (16 frames, 130560 mbs) > level limit (4 frames, 34816 mbs) x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle x264 [info]: profile High, level 4.2
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 11th October 2014 at 14:39. |
|
11th October 2014, 14:34 | #9 | Link |
PgcEdit daemon
Join Date: Jul 2003
Posts: 7,469
|
There is no need to explain that again. Re-read what I have written. I understand perfectly that the --profile and --level options are the UPPER LIMITS. And I don't "want" high@L4.1. I haven't said that. I just want to limit x264 so that it creates a stream that my TV can play (and for the precise example of my TV, the limit is high@L4.2).
What I mean is that if you use a very slow PRESET (without limiting x264 to a certain profile or level), then the profile and/or level may be higher than what you expect, and therefore it might be NECESSARY to use the --profile and --level options. In the past, I used your GUI without specifying the level, but one time I did an encode and my TV has rejected it. That was because it was a very short clip, and for that reason, I've used for the first time a very slow preset. After verification, I came to the conclusion that the profile and level really used by x264 depend of the preset. That's what I have explained above, and it's a verified fact. Since then, I have added --level 4.1 in the user options, and my TV has never rejected any encoding any more. I understand perfectly that my TV can accepts lower presets or levels, and that x264 can produce them, even if I have specified high@L4.1. What I mean is that it is incorrect to consider the level option as not important. In many case, it is an absolute necessity to specify it. I don't want to create videos that my TV rejects, and therefore I need to specify the --level option (at least when I use a slow preset). Again, it's a fact. (Of course, I could also not specify --level, but specify a lot of other options, that together have globally the same effect than using --level 4.1, but that's not the point.) It's why I don't understand why the level option is not present in your GUI, and you have to type it explicitly. It's a very important setting that should be set to 4.1 by default IMO, because (almost) all recent players can decode that level, but currently very few hardware players accept level 5.0 or higher. IMO, NOT specifying the level IS the bad idea, because you may end up with files that are rejected by many players.
__________________
r0lZ PgcEdit homepage (hosted by VideoHelp) BD3D2MK3D A tool to convert 3D blu-rays to SBS, T&B or FS MKV Last edited by r0lZ; 11th October 2014 at 14:45. |
11th October 2014, 14:49 | #10 | Link | |
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Quote:
You can't modify Profiles, because they are predefined by the H.264 standard. All H.264 Profiles that x264 recognizes should be selectable from the "Profile" combobox.
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 11th October 2014 at 14:53. |
|
11th October 2014, 15:31 | #11 | Link | ||||
PgcEdit daemon
Join Date: Jul 2003
Posts: 7,469
|
Quote:
Quote:
Quote:
Quote:
However, I agree that specifying --ref 16 AND the --level 4.1 at the same time is incompatible and will trigger warnings. Of course, if you limit x264 to a certain level AND you force it to use some characteristics from a higher level, it will not be able to do what you want without violating one of the parameters. And in that case, it may write level 4.1 in the header, even if it's not true. In my tests, I specify ONLY the level, without other incompatible options, and in that case, I'm sure x264 produces really a stream compatible with level 4.1.
__________________
r0lZ PgcEdit homepage (hosted by VideoHelp) BD3D2MK3D A tool to convert 3D blu-rays to SBS, T&B or FS MKV Last edited by r0lZ; 11th October 2014 at 15:34. |
||||
11th October 2014, 15:48 | #12 | Link | ||
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Quote:
Or in other words: If you use lossless mode, it will set "High 4:4:4" Profile. If you do not use lossless mode, but you have any "High" Profile features enabled, it will set "High" Profile. If you have no "High" Profile features enabled, but some "Main" Profile features are enabled, it will set "Main Profile". Otherwise, if only "Baseline" Profile features are used, it will set "Baseline" Profile. The "--profile X" option can be used to enforce a lower profile, because it will simply disable all the features that are not allowed in Profile X (if any of those were enabled before). Quote:
And you can test this easily: Set a large number of reference frames via "--ref" switch and force a Level that doesn't actually allow that many reference frames (due to DPB size limit) via "--level" switch. Will x264 lower the number of reference frames for you, to make your stream actually comply to the enforced Level? No it doesn't! It only prints a warning message that your stream violates the Level! Does it still still set the enforced Level, despite your stream is violating the Level? Yes. See also example here: https://forum.doom9.org/showpost.php...postcount=1395
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 11th October 2014 at 16:03. |
||
11th October 2014, 16:25 | #13 | Link |
PgcEdit daemon
Join Date: Jul 2003
Posts: 7,469
|
Consider this example:
I encode my clip without any parameter, except --preset ultrafast. The encoder uses the baseline profile. (I don't think the level is relevant for the baseline profile, but I may be wrong.) Then, I encode the same clip with --preset placebo. The encoder uses the high profile and level 5.1. That means that my clip complies to all profiles between baseline and high, and to all levels currently implemented (up to 5.1). When it has enough time, x264 selects the "best" profile and level automatically. For me, and obviously for x264, "best" is synonym with "highest" and not "lowest". Am I wrong? Your example with the --ref and --level is perfect to prove that it is possible to specify incompatible options. I have agreed with that in the last paragraph of my previous post. Now, if you want to encode the clip of the example above and be compatible with my TV WITHOUT SPECIFYING FANCY OPTIONS, you have 3 possibilities. 1. You can use a fast preset, but the result is unpredictable, and it is a pity to waste disc space. 2. You can specify --level 4.1, and everything is perfect, regardless of the preset you use (but as long as you don't specify incompatible options at the same time). 3. You can omit --level, but specify a bunch of other options so that in practice, you obtain also level 4.1. Since many options are somewhat obscure, and you can always make a mistake, my preferred solution is, by far, point 2. It's why IMO it is a pity to not have that level option in your GUI. Most users do not understand the complex options of x264, and should use only the main options: the mode, quantizer or bitrate and the preset, profile and level. More knowledgeable peoples may prefer to specify a lot of more specific options, but they should be smart enough to disable the profile and level options if they are incompatible.
__________________
r0lZ PgcEdit homepage (hosted by VideoHelp) BD3D2MK3D A tool to convert 3D blu-rays to SBS, T&B or FS MKV Last edited by r0lZ; 11th October 2014 at 16:30. |
11th October 2014, 16:47 | #14 | Link | |||
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Quote:
Quote:
For the last time: The Profile specifies witch features of H.264 you are allowed to use (or not). And x264 will select the lowest possible Profile that your stream compiles to. Always. No exceptions So if you enable any "High" Profile features (e.g. "8x8 vs. 4x4 Transform Adaptivity"), as is the case with most of the slower presets (including "Placebo" preset), then your stream requires "High" Profile and that is exactly what x264 will set! If, on the other hand, you only use "Baseline" Profile features, as is the case with "ultrafast" preset (since it disables pretty much everything that can be disabled), you obviously can get away with "Baseline" Profile. And that will be set. Quote:
Only reason the use "--profile X" is when you explicitly want to apply the restrictions of Profile X to your x264 settings, because you know that the highest Profile supported by your playback device is X. However, the "--level" option can not be used in that way. It just overwrites the Level that your stream will be tagged with - whether your stream actually conforms to that Level or not
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 11th October 2014 at 17:12. |
|||
11th October 2014, 16:51 | #15 | Link | ||
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
Quote:
Using --level without --ref is handy because you don't have to calculate yourself, x264 does all the work. Last edited by sneaker_ger; 11th October 2014 at 16:57. |
||
11th October 2014, 17:13 | #16 | Link | |||
PgcEdit daemon
Join Date: Jul 2003
Posts: 7,469
|
Quote:
In my understanding, that means that if it has enough time to compute, say, profile high, it does it. I did not know that it is forced to use it, unless you specify a lower profile. And same thing for the level. But I understand that I did a mistake. Quote:
Quote:
__________________
r0lZ PgcEdit homepage (hosted by VideoHelp) BD3D2MK3D A tool to convert 3D blu-rays to SBS, T&B or FS MKV |
|||
11th October 2014, 17:47 | #18 | Link | |
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Quote:
In other words: If we want to create a H.264 stream that works with all "High" Profile decoders out there, then we must configure our encoder to use only "High" Profile features. If we want to create a H.264 stream that works with all "Main" Profile decoders out there, then we must configure our encoder to use only "Main" Profile features. And if we want to create a H.264 stream that works with all "Baseline" Profile decoders out there, then we must configure our encoder to use only "Baseline" Profile features. Note that the "Main" Profile features are a subset of the "High" Profile features. And that the "Baseline" Profile features are a subset of the "Main" Profile features - at least as far as the feature supported by x264 are concerned. Once again I suggest to look at this table: http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC#Profiles
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 11th October 2014 at 17:53. |
|
11th October 2014, 18:49 | #19 | Link | |
Registered User
Join Date: Aug 2009
Posts: 463
|
Quote:
Edit: Sneaker_ger already mentioned that, didn't see. Sorry. Last edited by detmek; 11th October 2014 at 21:21. |
|
12th October 2014, 00:31 | #20 | Link | |
PgcEdit daemon
Join Date: Jul 2003
Posts: 7,469
|
Quote:
The rest of your post above is well known and doesn't need to be repeated. You just use "feature" when I use "algorithm". The real difficulty is to understand HOW to configure the encoder to obtain a specific profile and level. As I understand now, it's normally NOT via the profile and level options, but mainly via the preset option, at least when the encoder is x264. It's not really intuitive. In the wiki article, they explain the profile and level concepts, but there is nothing about the presets. It's normal, since the article is about h264 and not about the syntax of x264, but that doesn't help me. I have perfectly understood the profile and level concepts, and I know now that the preset is something made to simplify the selection of the profile and level. I want to understand now how the presets determine specific profiles and levels (if the input file supports them). Currently, I am forced to use a preset without knowing what will be the profile and level used by the encoder, and therefore I can't be sure that my TV will support it. It's why I have usually specified also the profile and the level. Now, if I don't specify them any more, what profile I must use remains a mystery. I will certainly find the solution on the internet, since now I know what I must search. Thanks for having clarified that point.
__________________
r0lZ PgcEdit homepage (hosted by VideoHelp) BD3D2MK3D A tool to convert 3D blu-rays to SBS, T&B or FS MKV Last edited by r0lZ; 12th October 2014 at 00:41. |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|