forked from difcareer/010templates
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMP4Template.bt
executable file
·163 lines (145 loc) · 7.82 KB
/
MP4Template.bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//-------------------------------------------------------------
//--- 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 <hidden=true>;
_typ type <bgcolor=cLtRed, fgcolor=cWhite, name="Box Type", open=false,
name =typeString/*, comment=typeFullName*/>;
if (Memcmp(type.text, "ftyp", 4) == 0) {
char major_brand[4] <bgcolor=cDkGreen, fgcolor=cWhite, name="Major brand"> ;
char minor_ver [4] <bgcolor=cDkBlue, fgcolor=cWhite, name="Minor version"> ;
uint comp_brands[(size - sizeof(size) - sizeof(type) - sizeof(major_brand) -
sizeof(minor_ver)) / 4] <name = "Compatible brands",
comment = brandName, open=true>;
} else if (Memcmp(type.text, "moov", 4) == 0) {
pos = FTell();
while(FTell() < pos + size - sizeof(size) - sizeof(type))
struct _box2 {
uint size <hidden=true>;
_typ type <bgcolor=cLtRed, fgcolor=cWhite, name="Box Type", open=false,
name =typeString/*, comment=typeFullName*/>;
if (Memcmp(type.text, "mvhd", 4) == 0) {
char version <hidden=true>;
char flags[3] <hidden=true>;
uint crTime <bgcolor=cLtGreen, fgcolor=cBlack, name="Creation Time", open=false>;
uint mdTime <bgcolor=cPurple, fgcolor=cWhite, name="Modification Time", open=false>;
uint tmScale <name="Time scale",comment="Number of units per 1 second">;
uint duration <name="Duration", comment="In units defined in the previous field">;
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 <hidden=true>;
_typ type <bgcolor=cLtRed, fgcolor=cWhite, name="Box Type", open=false,
name = typeString/*, comment=typeFullName*/>;
if (Memcmp(type.text, "tkhd", 4) == 0) {
char version <hidden=true>;
char flags[3] <hidden=true>;
uint crTime <bgcolor=cLtGreen, fgcolor=cBlack, name="Creation Time", open=false>;
uint mdTime <bgcolor=cPurple, fgcolor=cWhite, name="Modification Time", open=false>;
uint trkID < name="Track ID", open=false>;
uint reserv <hidden = true, name="Reserved">;
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 <hidden=true>;
_typ type <bgcolor=cLtRed, fgcolor=cWhite, name="Box Type", open=false,
name = typeString>;
char version <hidden=true>;
char flags[3] <hidden=true>;
uint entrs<name ="Number of entries">;
struct {
uint trDuration <name="Track duration">;
uint mediaTime <name="Media time">;
uint mediaRate <name="Media rate">;
} entry[entrs] <open=true>;
} box <optimize=false, open=true, comment=boxName4>;
} else
char rest[size - sizeof(size) - sizeof(type)];
} box <optimize=false, open=true, comment=boxName3>;
} else
char rest[size - sizeof(size) - sizeof(type)];
} box <optimize=false, open=true, comment=boxName2>;
} else
char rest[size - sizeof(size) - sizeof(type)];
} box <optimize=false, open=true, comment=boxName>;
}
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 <read=ReadDataBlock>;
// }
// 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;
// }