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. |
11th September 2012, 17:44 | #1 | Link |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
Getting aligned GOPs in different profiles in x264
When encoding for adaptive streaming, it is critical that all bitrates have IDRs aligned, to enable seamless stream switching.
The typical way to do this is to set each stream to an identical fixed, non-adaptive GOP size. Having adaptive GOPs synchronized between bitstreams has obvious advantages, but isn't supported by all formats and players, unfortunately. And isn't supported in off-the-shelf encoders either (except for the Smooth Streaming VC-1 SDK from Microsoft). The simple way to handle this in x264 is simply setting --keyint and --min-keyint to the same value. And I've confirmed this works fine if all the bitstreams are the same Profile@Level. However, IDRs are not aligned when I make High 3.1 and Main 3.0 encodes from the same source. For example, (using Simple x264 launcher, so Mode, Preset, and Tuning are all set in the GUI), I use these settings: Main Profile 3.0: Code:
2-Pass, preset veryslow, tuning film --level 3.0 --keyint 48 --min-keyint 48 --bframes 3 --b-pyramid strict --ref 4 --slices 1 --vbv-bufsize 10000 --vbv-maxrate 2000 --rc-lookahead 48 --aq-mode 2 --aq-strength 1.2 --no-fast-pskip --nal-hrd vbr --non-deterministic --colorprim bt709 --transfer bt709 --colormatrix bt709 [HTML]2-Pass, preset veryslow, tuning film --level 3.1 --keyint 48 --min-keyint 48 --bframes 3 --b-pyramid strict --ref 4 --slices 1 --vbv-bufsize 17500 --vbv-maxrate 2500 --rc-lookahead 48 --aq-mode 2 --aq-strength 1.1 --nr 250 --no-fast-pskip --nal-hrd vbr --non-deterministic --colorprim bt709 --transfer bt709 --colormatrix bt709[/HTML] The resulting files won't package in IIS Transform Manager, warning that there isn't IDR alignment. Jumping into them with the Tektronix MTSE4A stream analyzer, I see the IDRs wind up in different locations. Main Profile Level 3.0 starts with these IDR frames.
And High Profile Level 3.1 has these:
I'm attaching the log files from a test as well. Anyone have any idea what's happening here? Any suggestions? The best workaround I've thought of is to read the I frames out of the log file and then force those as I in a QPfile. But this seems like a bug to me. |
11th September 2012, 17:54 | #3 | Link | |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
Quote:
Why do you think that might make a difference? The Main/High switch between 1st and 2nd passes? Hmmm. I should try 1 pass as well... |
|
11th September 2012, 18:01 | #4 | Link |
Registered User
Join Date: Sep 2007
Posts: 5,377
|
There are differences as well, you are using --nr 250 in the high encodes, but not in the main, also different aq strenghts, vbv values. It might cause x264 to choose different frametype placements and gop sizes
It might be as simple as different settings causing x264 to choose frametype placements |
11th September 2012, 18:26 | #5 | Link |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
I stripped the encode down to 1 pass and JUST-- level, --keyint, and --min-keyint. And it actually made alignment worse!
It seems like x264 isn't honoring my --min-keyint for some reason, making it slightly (but disastrously) different in these different modes. High Profile seems worse. Hopefully forcing them in the qpfile will work, but hopefully one of the devs can look into this. |
11th September 2012, 18:39 | #6 | Link |
Derek Prestegard IRL
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,989
|
So you're saying that x264 doesn't seem to produce files with fixed GOP structure across different bitrates?
I'm not sure what's happening there, it definitely seems odd. Have you thought about using adaptive GOP, but consistent across all bitrates? My understanding is that x264's frametype decision should be consistent for the same content across multiple bitrates. The differences come into play when the resolution changes. So, to make (adaptive) GOP structure consistent across multiple bitrates, re-use the stats file from the first pass on each of the different bitrates. I've found starting at the top resolution / bitrate and working down seems to work the best. Also.. at one point, mbtree interfered with mixed resolutions and matched GOPs. I'm not sure if this is still the case.
__________________
These are all my personal statements, not those of my employer :) |
11th September 2012, 18:41 | #7 | Link |
Derek Prestegard IRL
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,989
|
Oh... what about adaptive b-frames? That wouldn't change IDR placement, right? It would only affect P/B choice?
Also... tried setting --no-scenecut?
__________________
These are all my personal statements, not those of my employer :) |
11th September 2012, 18:43 | #8 | Link | |||
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
Quote:
I should try High 3.0 v. 3.1 and High 3.0 v. Main 3.0 to see if it's Profile or Level or what. Quote:
Adaptive streaming needs to be able to have the same GOP structure in different frame sizes as well as bitrates. Quote:
|
|||
11th September 2012, 18:46 | #9 | Link | |
Derek Prestegard IRL
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,989
|
I've been whining in #x264. You need to disable scenecut if you want constant GOP structure.
Also Quote:
__________________
These are all my personal statements, not those of my employer :) |
|
11th September 2012, 18:48 | #10 | Link | |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
min-keyint is capped at keyint/2+1
Try disabling scenechange detection, as suggested by Blue-MiSfit. (--no-scenecut) Quote:
http://git.videolan.org/gitweb.cgi?p...43d63cde8bb836 Using a qpfile or re-using the complete stats file (to save time) should be better than fixed GOPs, though. As you can see from the git log comment, the penalty for re-using the stats can be very low. Last edited by sneaker_ger; 11th September 2012 at 18:56. |
|
11th September 2012, 20:31 | #11 | Link | ||
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
Quote:
Also, if this isn't what --min-keyint does, what does it do ? Quote:
|
||
11th September 2012, 20:48 | #12 | Link | |
Guest
Posts: n/a
|
Quote:
Code:
if( h->param.i_keyint_min == X264_KEYINT_MIN_AUTO ) h->param.i_keyint_min = X264_MIN( h->param.i_keyint_max / 10, fps ); h->param.i_keyint_min = x264_clip3( h->param.i_keyint_min, 1, h->param.i_keyint_max/2+1 ); Last edited by SassBot; 11th September 2012 at 21:09. |
|
12th September 2012, 08:33 | #13 | Link |
Derek Prestegard IRL
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,989
|
@Ben:
http://mirror01.x264.nl/x264/changelog.txt It looks like the mb-tree fix was pushed on June 8th, in rev 2205. I'm assuming you typo'd 2008 and meant 2208, in which case yes you should have that fix. If not, time to update Derek
__________________
These are all my personal statements, not those of my employer :) |
12th September 2012, 19:23 | #15 | Link | |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
Quote:
I'm working on my big .bat file to test all this right now. |
|
12th September 2012, 19:34 | #16 | Link |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
I am, and they were really informative, thanks!
Related to your info, if I wanted totally fixed cadence, I'd need to do that with a qpfile, right? Basically one where every 48th frame (for 24p @ 2sec) is specified I, and no other information. I imagine I should also use --open-gop to let the mid-chunk I-frames be not IDR. Some muxers get confused if there are extra IDRs. Getting devices to not require fixed GOP sizes would be preferable, of course. |
12th September 2012, 20:14 | #17 | Link |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
A qpfile alone setting the IDR-frames is not sufficient, as the scenecut detection can throw in additional IDR-frames. You have to turn the scenecut detection off - a qpfile is not needed. But I really suggest you leave it on and re-use the stats file instead as suggested by Blue_MiSfit.
I don't know what container you are using, but the last time I looked, open-gop was not recommended in an mp4 container. Seeking to non-IDR I-frames for example does not work. Last edited by sneaker_ger; 12th September 2012 at 20:20. |
12th September 2012, 21:13 | #19 | Link | |
Moderator
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,771
|
Quote:
Allowing variable GOP is preferable, but there may be platforms that require a strictly fixed IDR pattern. |
|
12th September 2012, 21:37 | #20 | Link | |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
You could of course combine the two to save some time while still retaining a fixed pattern. |
|
Tags |
adaptive streaming, smooth streaming |
|
|