Let's start right in!
The following listing is a dump of a typical MP4 file's box structure. This also introduces you to the ISO SAX dump format. It is generated by the following JUnit test case:
@Test
public void boxTreeDump() throws Exception {
final File fx = new File("**redacted**.m4a");
assertTrue("exists failed", fx.exists());
final ParseCallback tx = new BoxTreeDump();
ISOParser.parse(fx, new ConsoleHandler(), tx);
}
Let's note a few things about the setup:
0 /ftyp ftyp@0-23[24/8]
0 /moov moov@24-3527779[3527756/8]
1 /moov/mvhd mvhd.v0:0@32-139[108/12]
1 /moov/trak trak@140-3343360[3343221/8]
2 /moov/trak/tkhd tkhd.v0:1@148-239[92/12]
2 /moov/trak/edts edts@240-75[36/8]
3 /moov/trak/edts/elst elst.v0:0@248-75[28/12]
2 /moov/trak/free free@276-335[60/8]
2 /moov/trak/tref tref@336-59[24/8]
2 /moov/trak/mdia mdia@360-3343360[3343001/8]
3 /moov/trak/mdia/mdhd mdhd.v0:0@368-99[32/12]
3 /moov/trak/mdia/hdlr hdlr.v0:0@400-57[58/12]
3 /moov/trak/mdia/minf minf@458-3343360[3342903/8]
4 /moov/trak/mdia/minf/smhd smhd@466-81[16/8]
4 /moov/trak/mdia/minf/dinf dinf@482-517[36/8]
5 /moov/trak/mdia/minf/dinf/dref dref.v0:0@490-517[28/12]
4 /moov/trak/mdia/minf/stbl stbl@518-3343360[3342843/8]
5 /moov/trak/mdia/minf/stbl/stsd stsd.v0:0@526-628[103/12]
5 /moov/trak/mdia/minf/stbl/stts stts.v0:0@629-52[24/12]
5 /moov/trak/mdia/minf/stbl/stsc stsc.v0:0@653-669776[669124/12]
5 /moov/trak/mdia/minf/stbl/stsz stsz.v0:0@669777-3012636[2342860/12]
5 /moov/trak/mdia/minf/stbl/stco stco.v0:0@3012637-343360[330724/12]
1 /moov/trak trak@3343361-917[557/8]
2 /moov/trak/tkhd tkhd.v0:f@3343369-460[92/12]
2 /moov/trak/edts edts@3343461-96[36/8]
3 /moov/trak/edts/elst elst.v0:0@3343469-96[28/12]
2 /moov/trak/mdia mdia@3343497-917[421/8]
3 /moov/trak/mdia/mdhd mdhd.v0:0@3343505-36[32/12]
3 /moov/trak/mdia/hdlr hdlr.v0:0@3343537-94[58/12]
3 /moov/trak/mdia/minf minf@3343595-917[323/8]
4 /moov/trak/mdia/minf/vmhd vmhd@3343603-22[20/8]
4 /moov/trak/mdia/minf/hdlr hdlr.v0:0@3343623-79[57/12]
4 /moov/trak/mdia/minf/dinf dinf@3343680-715[36/8]
5 /moov/trak/mdia/minf/dinf/dref dref.v0:0@3343688-715[28/12]
4 /moov/trak/mdia/minf/stbl stbl@3343716-917[202/8]
5 /moov/trak/mdia/minf/stbl/stsd stsd.v0:0@3343724-825[102/12]
5 /moov/trak/mdia/minf/stbl/stts stts.v0:0@3343826-49[24/12]
5 /moov/trak/mdia/minf/stbl/stsc stsc.v0:0@3343850-77[28/12]
5 /moov/trak/mdia/minf/stbl/stsz stsz.v0:0@3343878-97[20/12]
5 /moov/trak/mdia/minf/stbl/stco stco.v0:0@3343898-917[20/12]
1 /moov/trak trak@3343918-4666[749/8]
2 /moov/trak/tkhd tkhd.v0:e@3343926-4017[92/12]
2 /moov/trak/edts edts@3344018-53[36/8]
3 /moov/trak/edts/elst elst.v0:0@3344026-53[28/12]
2 /moov/trak/mdia mdia@3344054-666[613/8]
3 /moov/trak/mdia/mdhd mdhd.v0:0@3344062-93[32/12]
3 /moov/trak/mdia/hdlr hdlr.v0:0@3344094-150[57/12]
3 /moov/trak/mdia/minf minf@3344151-666[516/8]
4 /moov/trak/mdia/minf/gmhd gmhd@3344159-234[76/8]
5 /moov/trak/mdia/minf/gmhd/gmin gmin@3344167-90[24/8]
5 /moov/trak/mdia/minf/gmhd/text text@3344191-234[44/8]
4 /moov/trak/mdia/minf/hdlr hdlr.v0:0@3344235-91[57/12]
4 /moov/trak/mdia/minf/dinf dinf@3344292-327[36/8]
5 /moov/trak/mdia/minf/dinf/dref dref.v0:0@3344300-27[28/12]
4 /moov/trak/mdia/minf/stbl stbl@3344328-666[339/8]
5 /moov/trak/mdia/minf/stbl/stsd stsd.v0:0@3344336-410[75/12]
5 /moov/trak/mdia/minf/stbl/stts stts.v0:0@3344411-514[104/12]
5 /moov/trak/mdia/minf/stbl/stsc stsc.v0:0@3344515-42[28/12]
5 /moov/trak/mdia/minf/stbl/stsz stsz.v0:0@3344543-606[64/12]
5 /moov/trak/mdia/minf/stbl/stco stco.v0:0@3344607-66[60/12]
1 /moov/udta udta@3344667-527779[183113/8]
2 /moov/udta/meta meta.v0:0@3344675-527779[183105/12]
3 /moov/udta/meta/hdlr hdlr.v0:0@3344687-720[34/12]
3 /moov/udta/meta/ilst ilst@3344721-527779[183059/8]
0 /wide wide@3527780-7[8/8]
0 /mdat mdat@3527788-150988716[147460929/8]
java.lang.IllegalArgumentException: invalid top-level tag 'pHYs' @150988717
java.lang.IllegalStateException: 196710 Extra bytes not in a box
The box dump format consists of the following bits:
Now let's cover the "error" messages at the end. ISO SAX notifies the context of any issues encountered during the box scanning process.
The first thing to notice is ISO SAX validates top-level boxes. There is a small, fixed number of these, so this is desired behavior. The next thing to notice is that there are "left over" bytes after the box structure is completed. This is also normal; the ISO standard does not stipulate what happens outside the box structure, and QuickTime in particular will add data it needs (e.g. sample data) after all the boxes are output.