//------------------------------------------------------------- //--- 010 Editor v6.0.2 Binary Template // // File: MP4.bt // Author: Marian Denes // Revision: 2.1 // Date: 2015.06.04 // Purpose: Defines a template for parsing MP4 and MOV files. //------------------------------------------------------------- BigEndian(); local int64 pos; local int64 pos2; typedef union { /*uint number;*/ char text[4]; } _typ; string typeFullName(_typ& type) { if (Memcmp(type.text, "ftyp", 4) == 0) return "File type compatibility box"; if (Memcmp(type.text, "mvhd", 4) == 0) return "Movie header box"; if (Memcmp(type.text, "iods", 4) == 0) return "Initial object descriptor box"; if (Memcmp(type.text, "trak", 4) == 0) return "Track box"; if (Memcmp(type.text, "udta", 4) == 0) return "Uset data box"; if (Memcmp(type.text, "mdat", 4) == 0) return "Movie (sample) data box"; if (Memcmp(type.text, "moov", 4) == 0) return "Moovie box"; if (Memcmp(type.text, "tkhd", 4) == 0) return "Track header box"; if (Memcmp(type.text, "mdia", 4) == 0) return "Media box"; if (Memcmp(type.text, "edts", 4) == 0) return "Edit box"; if (Memcmp(type.text, "elst", 4) == 0) return "Edit list"; return "I don't know the full name"; } string typeString(_typ& type) { return "Type of the box: \"" + type.text + "\""; } // MessageBox(idOk, "", "GetCursorPos == %d", GetCursorPos()); while(FTell() < FileSize() - 1) { struct _box { uint size ; _typ type ; if (Memcmp(type.text, "ftyp", 4) == 0) { char major_brand[4] ; char minor_ver [4] ; uint comp_brands[(size - sizeof(size) - sizeof(type) - sizeof(major_brand) - sizeof(minor_ver)) / 4] ; } else if (Memcmp(type.text, "moov", 4) == 0) { pos = FTell(); while(FTell() < pos + size - sizeof(size) - sizeof(type)) struct _box2 { uint size ; _typ type ; if (Memcmp(type.text, "mvhd", 4) == 0) { char version ; char flags[3] ; uint crTime ; uint mdTime ; uint tmScale ; uint duration ; char rest[size - sizeof(size) - sizeof(type) - sizeof(version) - sizeof(flags) - sizeof(crTime) - sizeof(mdTime) - sizeof(tmScale) - sizeof(duration)]; } else if (Memcmp(type.text, "trak", 4) == 0) { pos2 = FTell(); while(FTell() < pos2 + size - sizeof(size) - sizeof(type)) struct _box3 { uint size ; _typ type ; if (Memcmp(type.text, "tkhd", 4) == 0) { char version ; char flags[3] ; uint crTime ; uint mdTime ; uint trkID < name="Track ID", open=false>; uint reserv ; uint duration < name="Duration", open=false>; char rest[size - sizeof(size) - sizeof(type) - sizeof(version) - sizeof(flags) - sizeof(crTime) - sizeof(mdTime) - sizeof(trkID) - sizeof(reserv) - sizeof(duration)]; } else if (Memcmp(type.text, "edts", 4) == 0) { struct _box4 { uint size ; _typ type ; char version ; char flags[3] ; uint entrs; struct { uint trDuration ; uint mediaTime ; uint mediaRate ; } entry[entrs] ; } box ; } else char rest[size - sizeof(size) - sizeof(type)]; } box ; } else char rest[size - sizeof(size) - sizeof(type)]; } box ; } else char rest[size - sizeof(size) - sizeof(type)]; } box ; } string boxName(_box& box) { return box.type.text + " (" + typeFullName(box.type) + ")";; } string boxName2(_box2& box) { return box.type.text + " (" + typeFullName(box.type) + ")"; } string boxName3(_box3& box) { return box.type.text + " (" + typeFullName(box.type) + ")"; } string boxName4(_box4& box) { return box.type.text + " (" + typeFullName(box.type) + ")"; } string brandName(uint brand) { local char text[4]; local int i; for (i = 0; i < 4; ++i) text[i] = brand >> 8 * (3 - i) & 0xFF; return text; } // string boxName5(_box5& box) { // return box.type.text + " (" + typeFullName(box.type) + ")"; // } // local int i; // struct DATABLOCK { // int dataID; // uchar dataArray[16]; // }; // pos = FTell(); // save read position // for( i = 0; i < 4; i++ ) { // DATABLOCK data ; // } // FSeek( pos ); // restore read position // // // Custom read function // string ReadDataBlock( DATABLOCK &d ) // { // // string str; // // SPrintf( str, "ID = '%d'", d.dataID ); // FTell( box[i].type] ); // return str; // }