Chapter Sync and Chapter Name Fixes/Support
Forum rules
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.
*******************************
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.
*******************************
Chapter Sync and Chapter Name Fixes/Support
Okay, I finally have something ready to show. The patch is a bit large, so I am having to link to it rather than just drop it in.
http://homepage.mac.com/cyander/Files/ChapterWork.zip
It includes 3 diffs (one against libhb, one against the CLI, one against the OS X UI), and MainMenu.nib.
MainMenu.nib will be the joy, since I managed to get out of sync with dynaflash's tweaks and so on.
The work is pretty extensive, since it adds a new marker in hb_buffer_t used to track chapter breaks as they worm their way through the pipeline, as well as all the supporting code to track chapter breaks, and adjust for DVD behavior. As well as better muxing behavior for chapter samples, and better creation of those text samples.
It also adds a new tab, plus supporting code for it in the OS X UI. Allowing for naming of chapters using UTF8
The CLI can now read CSV (comma-separated values) files for chapter naming information (and it supports UTF8). It is a quick, simple way to parse a text file for data, and can be used elsewhere if needed. Not sure exactly why, but the diff for test.c touched everything in the file, when only maybe about 20 lines are different. Not sure what I can do about that to make the diff easier.
http://homepage.mac.com/cyander/Files/ChapterWork.zip
It includes 3 diffs (one against libhb, one against the CLI, one against the OS X UI), and MainMenu.nib.
MainMenu.nib will be the joy, since I managed to get out of sync with dynaflash's tweaks and so on.
The work is pretty extensive, since it adds a new marker in hb_buffer_t used to track chapter breaks as they worm their way through the pipeline, as well as all the supporting code to track chapter breaks, and adjust for DVD behavior. As well as better muxing behavior for chapter samples, and better creation of those text samples.
It also adds a new tab, plus supporting code for it in the OS X UI. Allowing for naming of chapters using UTF8
The CLI can now read CSV (comma-separated values) files for chapter naming information (and it supports UTF8). It is a quick, simple way to parse a text file for data, and can be used elsewhere if needed. Not sure exactly why, but the diff for test.c touched everything in the file, when only maybe about 20 lines are different. Not sure what I can do about that to make the diff easier.
I'm sure you're fed up of chapter times now, and having tested your work they seem almost spot on (thanks!) - but there's still a tiny issue with timings - I think.
Matching playback with DVD Player for a full-length rip I tried (haven't tested thoroughly with part-rips), there was a consistent gap of 4 frames delay in chapter times for HB's output versus what DVD Player thought - apart from two chapters: chapter 2 (the first chapter mark after the start) was 5 frames late, and the final chapter mark (36 in this case) was only 1 frame late. Weird eh?
Goodness knows if DVD Player's chapter tracking is frame-perfect anyway; certainly one or two looked the odd frame out of place judging by the scene cuts. Then again, HB's weren't right by the scene cuts either - so that could be sloppy editing of the DVD. Too many variables!
Either way, it's close enough. Much closer than the random offsets there were before. This is a great feature to have!
[edit] Having said that, I didn't do anything about MainMenu.nib - I assume that wouldn't make a difference though
Matching playback with DVD Player for a full-length rip I tried (haven't tested thoroughly with part-rips), there was a consistent gap of 4 frames delay in chapter times for HB's output versus what DVD Player thought - apart from two chapters: chapter 2 (the first chapter mark after the start) was 5 frames late, and the final chapter mark (36 in this case) was only 1 frame late. Weird eh?
Goodness knows if DVD Player's chapter tracking is frame-perfect anyway; certainly one or two looked the odd frame out of place judging by the scene cuts. Then again, HB's weren't right by the scene cuts either - so that could be sloppy editing of the DVD. Too many variables!
Either way, it's close enough. Much closer than the random offsets there were before. This is a great feature to have!
[edit] Having said that, I didn't do anything about MainMenu.nib - I assume that wouldn't make a difference though
I know of the issues with chapter sync, and have improved it even further. There are some oddities with how mpeg2dec handles GOPs near chapter breaks, and passes that state back. I have addressed some of these issues, and also addressed an issue where if the last chapter only had one cell... the last chapter marker would be left out of the text track.
So, in the build I have (which is newer), the 'rule' is:
- Find Cell start for the chapter
- Find first GOP in the chapter (GOPs can spill over from a previous chapter's cells)
- Find first I-frame in the stream after the GOP marker.
This seems to be the most accurate way. It might still be different for a couple DVDs, but the logic is now consistent with over a dozen MPAA releases I have been able to try, and Handbrake's logic for finding the first frame in a chapter.
I don't think there is a way to make it any more accurate than this without the original masters.
So, in the build I have (which is newer), the 'rule' is:
- Find Cell start for the chapter
- Find first GOP in the chapter (GOPs can spill over from a previous chapter's cells)
- Find first I-frame in the stream after the GOP marker.
This seems to be the most accurate way. It might still be different for a couple DVDs, but the logic is now consistent with over a dozen MPAA releases I have been able to try, and Handbrake's logic for finding the first frame in a chapter.
I don't think there is a way to make it any more accurate than this without the original masters.
The closest thing to perfection is to imitate the logic of the DVD player.
The problem with doing this is that DVDs are authored in a such a way to depend on complicated logic to make sure that the right frame is the one used for the chapter entry.
So what I was seeing was the following:
Now, the number of P frames that spill can be variable, and to make matters worse... mpeg2dec would return the GOP header when it found it in the stream, not when it was about to decode the first I frame in the group.
This is kinda why you saw the problems, is that my previous logic wound up assuming that there were 2 P frames (not intentionally) between the GOP header being found, and the eventual I frame being decoded. Now I actually check for the I frame specifically, which makes it much more robust.
The problem with doing this is that DVDs are authored in a such a way to depend on complicated logic to make sure that the right frame is the one used for the chapter entry.
So what I was seeing was the following:
Code: Select all
Cell 1 |Cell 2
IPPPPPPPPPPP|PPIPPPPPPPPP
^ ^- First Frame displayed when skipping to cell 2
|- Chapter break as authored to the DVD
This is kinda why you saw the problems, is that my previous logic wound up assuming that there were 2 P frames (not intentionally) between the GOP header being found, and the eventual I frame being decoded. Now I actually check for the I frame specifically, which makes it much more robust.
I agree this is starting to split hairs, but if you (the collective "you", not necessarily you) wanted to verify if it was an authoring error as opposed to something else, would myDVDEdit tell you? http://www.mydvdedit.com/
After all, it claims to be "a tool which allows you to understand and even to modify the content of a DVD, at the deepest level."
After all, it claims to be "a tool which allows you to understand and even to modify the content of a DVD, at the deepest level."
Well, it is always good to verify with a second app sometimes when debugging (and I do).
I think I might be unclear though. DVDs are authored in 'cells', not 'frames'. So a chapter break is aligned to a cell, and the cell's first frame is right there, but you have no way of knowing if that first frame in the cell is the right frame until you check what type of frame it is.
Authors depend on this behavior to get chapters to start when they want them to, since you cannot always encode a DVD in such a way that a group of frames ends perfectly at the end of a cell (A group of frames starts with an I-frame, and continues to the next I-frame). But, by making a chapter's opening frame be the first I-frame in a cell, chapters will work the way the author intends.
So, since there is no frame-accurate data on the DVD itself, the best we could ever hope to accomplish is mimicing a DVD player, which we already do (just not with the diff as posted yet).
I think I might be unclear though. DVDs are authored in 'cells', not 'frames'. So a chapter break is aligned to a cell, and the cell's first frame is right there, but you have no way of knowing if that first frame in the cell is the right frame until you check what type of frame it is.
Code: Select all
Common Example:
Cell 1 | Cell 2 | Cell 3
IPPPPIPPPPIP|PPPIPPPPIPPP|PP... and so on
^ | ^- 3) I-Frame found, start rendering frames from here
| \- 2) DVD player skips these 3 frames, since it can't render them without an I-Frame
\- 1) DVD Player jumps to chapter break, resets rendering
So, since there is no frame-accurate data on the DVD itself, the best we could ever hope to accomplish is mimicing a DVD player, which we already do (just not with the diff as posted yet).
Why is this not in svn?
Is there a good reason why cyander's patches have not been applied to the repository yet?
That is very unsual, I will look into it...
I explicitly svn updated to 545, and resolving test.c by hand before making the diff. The test.c diff in particular shrunk by a ton because of 545 and my version both using the same sort of line breaks.
It should be a single diff "Final.diff"... this is what you are getting?
I explicitly svn updated to 545, and resolving test.c by hand before making the diff. The test.c diff in particular shrunk by a ton because of 545 and my version both using the same sort of line breaks.
It should be a single diff "Final.diff"... this is what you are getting?
Hmm...I'm getting an odd crash when I launch a patched build:
I tried trashing all my preferences, but it didn't help.
Code: Select all
Version: 0.8.5b1 (2007042401)
PID: 9833
Thread: 0
Exception: EXC_BREAKPOINT (0x0006)
Code[0]: 0x00000001
Code[1]: 0x9297c120
Thread 0 Crashed:
0 com.apple.Foundation 0x9297c120 _NSRaiseError + 264
1 com.apple.Foundation 0x9297be5c +[NSException raise:format:] + 40
2 com.apple.Foundation 0x92954f4c -[NSObject(NSForwardInvocation) forward::] + 176
3 libobjc.A.dylib 0x90a440b0 _objc_msgForward + 176
4 org.m0k.handbrake 0x00013b2c -[PrefsController awakeFromNib] + 4268 (PrefsController.m:251)
5 com.apple.Foundation 0x9296b668 -[NSSet makeObjectsPerformSelector:] + 164
6 com.apple.AppKit 0x93726a70 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 864
7 com.apple.AppKit 0x93712c9c loadNib + 240
8 com.apple.AppKit 0x937126f4 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 716
9 com.apple.AppKit 0x93769bc4 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 156
10 com.apple.AppKit 0x937f9a70 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 344
11 com.apple.AppKit 0x937f9810 NSApplicationMain + 344
12 org.m0k.handbrake 0x000069bc _start + 760
13 org.m0k.handbrake 0x000066c0 start + 48
Thread 1:
0 libSystem.B.dylib 0x9000ab48 mach_msg_trap + 8
1 libSystem.B.dylib 0x9000aa9c mach_msg + 60
2 com.unsanity.ape 0xc0001b14 __ape_agent + 296
3 libSystem.B.dylib 0x9002b508 _pthread_body + 96
Thread 0 crashed with PPC Thread State 64:
srr0: 0x000000009297c120 srr1: 0x100000000002f030 vrsave: 0x0000000000000000
cr: 0x28000442 xer: 0x0000000000000000 lr: 0x000000009297c0f8 ctr: 0x000000009293df1c
r0: 0x0000000000000000 r1: 0x00000000bffff4b0 r2: 0x00000000a293b508 r3: 0x00000000bffff060
r4: 0x0000000000000000 r5: 0x000000009293d844 r6: 0x00000000bffff0e4 r7: 0x00000000000000ff
r8: 0x00000000bffff0d0 r9: 0x000000000135d9b0 r10: 0x0000000090a3d628 r11: 0x0000000028000442
r12: 0x000000009293df1c r13: 0x0000000000500000 r14: 0x0000000000500000 r15: 0x00000000004fe50c
r16: 0x00000000004fe4fc r17: 0x000000000137fa10 r18: 0x00000000004fe4ec r19: 0x00000000004fe5fc
r20: 0x00000000004fe5dc r21: 0x00000000004fe5ac r22: 0x00000000004fe58c r23: 0x000000000064720c
r24: 0x0000000001371e10 r25: 0x00000000bffff628 r26: 0x0000000001371e10 r27: 0x00000000a2954adc
r28: 0x000000000136df60 r29: 0x00000000a2940808 r30: 0x0000000001308fc0 r31: 0x000000009297c028
I think there is something very odd about that crash, and I am surprised you didn't see it too: EXC_BREAKPOINT. (nevermind... Apple is intentionally throwing this exception for debuggers... durrrrrr)
That said... I am seeing it too... and wondering why. This didn't happen until I sync'd to 545.
EDIT: I looked quickly, and it sounds suspiciously like the NIB hasn't yet been merged... I did mention I haven't done that yet. I would use dynaflash's NIB from 545, and use mine as a template on what to add to dynaflash's.
If you revert the changes to the mac GUI, you can probably confirm this. The NIB will need to be merged before the code patch can be used on the mac GUI.
That said... I am seeing it too... and wondering why. This didn't happen until I sync'd to 545.
EDIT: I looked quickly, and it sounds suspiciously like the NIB hasn't yet been merged... I did mention I haven't done that yet. I would use dynaflash's NIB from 545, and use mine as a template on what to add to dynaflash's.
If you revert the changes to the mac GUI, you can probably confirm this. The NIB will need to be merged before the code patch can be used on the mac GUI.
My bad--I thought by hand-merging you just meant I had to substitute your .nib for the svn's.Cyander wrote:EDIT: I looked quickly, and it sounds suspiciously like the NIB hasn't yet been merged... I did mention I haven't done that yet. I would use dynaflash's NIB from 545, and use mine as a template on what to add to dynaflash's.