PDA

View Full Version : AVCHD Chapters


aaar9800
28th May 2009, 04:36
I've been making pretty simple transfers of my HF100 AVCHD footage to either DVDs or a 720p x264. What I wanted to be able to do was to add chapter points at the file cuts. I wrote a pretty simple command line program to extract chapters from a .dga file generated by DGAVCIndex. Here is my workflow:

First, I combine all of the .MTS files with eac3to, using:


eac3to.exe "file_1.MTS" + "file_2.MTS" + ... + "file_n.MTS" -demux


The above command line creates a raw h264 file and an ac3 file. As discussed before in DGAVCDec thread, audio and video have different frame sizes (time wise), which results in different lengths of the tracks, with audio usually being slightly longer. eac3to removes those overlaps and simplifies the whole procedure.

Then, I index the file with DGAVCIndex. Then I run my program and input the file targets:


D:\temp>avchd_chapters.exe
Enter Full Path for *.dga: e:\avchd\flash_4\f4.dg
Enter Full Path for *.txt: e:\avchd\flash_4\f4_chapters.txt


It will then ask you as to which format you want the chapter list to be in. I reckon OGM will be the more popular choice.

If the .dga reports a frame rate that is 29.97, 30, 59.94 or 60, the program will prompt you:


(1) - Assume Original Frame Rate
(2) - Apply Inverse Telecine
Sellect Chapter Timing:


This option will have an effect on the frames, but not the timing (not so much, at least). The IVTC implementation is very primitive - the frame numbers are multiplied by 0.8, just like the frame rate. Since the DGAVCDec does not decode first two frames, this "causes" a slight inaccuracy in timings within my program. The HF100's GOP is 15 frames long, which should effectively become 12 frames after IVTC. Because of the missing two first frames, after the mod 15 frames are IVTC'ed the resultant frames become 0.4 of a frame off in timing (the first GOP will be decoded to be 13 frames long). In either case, the IVTC option is unlikely to be useful, since if you are authoring a DVD in IfoEdit, you will still have to apply pulldown to the encoded file, which would require you to use the 30000/1001 frames anyway. And when making a reencoded AVCHD, you can just use the original timings.

Also, if you use the above method for extracting video and audio out the series of files, then eac3to will not take into account the missing two frames and will not adjust the delay. For that reason, when muxing the final video and audio tracks, I add -66 ms delay (30000/1001) to the audio.

Another feature that the program has is that it can "decimate" the chapters to an approximate separation in frames. If you have files that are on the smaller side, it doesn't make sense to have a chapter for all of your 130 files. Especially so, since a DVD can have only 99 chapters. I usually use something like 8991, which is close to 5 minutes for 30000/1001 content. Before you enter your desired value, the program will tell you the minimum decimation value (Whichever happens to be more restrictive out of: "Total Frames/Total # of Files", "Total Frames/99" and "First Chapter Length/1.5"). If you enter anything less than that, then the program will not do any decimation or interpolation, but will instead spit out all of the file cuts. This can come in handy if you want to have a more manual chapter selection approach.

Underneath, what the program does is it divides the potential chapter points by the decimation value you entered and puts the result into an array that looks something like this: 0.8, 0.9, 1.4, 1.8, 2.1, 2.9, 3.2, 4.1... The program then chooses values that are closest to the whole numbers: 0.9, 2.1, 2.9, 4.1... In case you have a large file somewhere in the sequence, it is possible to have no chapter point near one of the whole numbers: 0.9, 2.1, 4.1... In that case, the program will ask you:


MISSING CHAPTER POINTS FOUND
(1) - Skip Zeros (1,2,3,E,5,6,7 -> 1,2,3,5,6,7)
(2) - Interpolate (1,2,3,E,5,6,7 -> 1,2,3,4,5,6,7)
Chapter Selection Method:


The above gives a pretty clear description of what happens, if you pick 1, you'll have: 0.9, 2.1, 4.1..., if you pick 2: 0.9, 2.1, 3.1, 4.1... The program can interpolate chapter points even if there is more than one missing. This is probably less useful, since there is no guarantee that the chapter points will be on top of an I-frame when interpolating, and you should probably rerun the program with a higher decimation value. In either case, I found those instances to be rare in my shooting.

Sorry for the rather long post, but perhaps some will find this program useful for their own purposes.

If you encounter any unexpected behavior, please let me know.

You can get it here: http://www.mediafire.com/?jykmj0jzlgz