Mercurial > mplayer.hg
annotate TOOLS/movinfo.c @ 27389:f5f36f035807
synced with r27420
author | Gabrov |
---|---|
date | Wed, 06 Aug 2008 07:50:44 +0000 |
parents | 8eff880f638c |
children | 0f1b5b68af32 |
rev | line source |
---|---|
1 | 1 // show QuickTime .mov file structure (C) 2001. by A'rpi/ESP-team |
1175 | 2 // various hacks by alex@naxine.org |
3 | |
4 /* | |
5 Blocks: 4bytes atom_size | |
6 4bytes atom_type (name) | |
7 ... | |
8 | |
9 By older files, mdat is at the beginning, and moov follows it later, | |
10 by newer files, moov is at the begininng. | |
11 | |
12 Fontosabb typeok: | |
13 | |
14 trak: track: ezeken belul van egy-egy stream (video/audio) | |
15 tkhd: track header: fps (video esten picture size is itt van) | |
16 vmhd: video media handler (video stream informaciok) | |
17 smhd: sound media handler (audio stream informaciok) | |
18 */ | |
1 | 19 |
20 #include <stdio.h> | |
21 #include <stdlib.h> | |
22 | |
1175 | 23 #undef NO_SPECIAL |
24 | |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
26474
diff
changeset
|
25 static char *atom2human_type(int type) |
1175 | 26 { |
27 switch (type) | |
28 { | |
26759
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
29 case 0x766F6F6D: return "Information sections"; /* moov */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
30 case 0x6468766D: return "Movie header"; /* mvhd */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
31 case 0x6169646D: return "Media stream"; /* mdia */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
32 case 0x64686D76: return "Video media header"; /* vmhd */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
33 case 0x64686D73: return "Sound media header"; /* smhd */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
34 case 0x6468646D: return "Media header"; /* mdhd */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
35 case 0x666E696D: return "Media information"; /* minf */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
36 case 0x726C6468: return "Handler reference"; /* hdlr */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
37 case 0x6B617274: return "New track (stream)"; /* trak */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
38 case 0x75716D72: return "rmqu"; |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
39 case 0x65657266: return "free"; |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
40 case 0x64686B74: return "Track header"; /* tkhd */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
41 case 0x61746475: return "User data"; /* udta */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
42 case 0x7461646D: return "Movie data"; /* mdat */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
43 case 0x6C627473: return "Sample information table"; /* stbl */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
44 case 0x64737473: return "Sample description"; /* stsd */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
45 case 0x6F637473: return "Chunk offset table"; /* stco */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
46 case 0x73747473: return "Sample time table"; /* stts */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
47 case 0x63737473: return "Sample->Chunk mapping table"; /* stsc */ |
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
48 case 0x7A737473: return "Sample size table"; /* stsz */ |
1175 | 49 } |
26759
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26576
diff
changeset
|
50 return "unknown"; |
1175 | 51 } |
52 | |
53 #define S_NONE 0 | |
54 #define S_AUDIO 1 | |
55 #define S_VIDEO 2 | |
56 int stream = S_NONE; | |
57 int v_stream = 0; | |
58 int a_stream = 0; | |
59 | |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
26474
diff
changeset
|
60 static unsigned int read_dword(FILE *f){ |
1 | 61 unsigned char atom_size_b[4]; |
62 if(fread(&atom_size_b,4,1,f)<=0) return -1; | |
63 return (atom_size_b[0]<<24)|(atom_size_b[1]<<16)|(atom_size_b[2]<<8)|atom_size_b[3]; | |
64 } | |
65 | |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
26474
diff
changeset
|
66 static void video_stream_info(FILE *f, int len) |
1175 | 67 { |
68 int orig_pos = ftell(f); | |
69 unsigned char data[len-8]; | |
70 int i; | |
23658 | 71 // char codec[len-8]; |
1175 | 72 |
73 len -= 8; | |
74 for (i=0; i<len; i++) | |
75 fread(&data[i], 1, 1, f); | |
76 | |
6908 | 77 // strncpy(codec, &data[43], len-43); |
78 // printf(" [codec: %s]\n", &codec); | |
1175 | 79 fseek(f,orig_pos,SEEK_SET); |
80 } | |
81 | |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
26474
diff
changeset
|
82 static void audio_stream_info(FILE *f, int len) |
1175 | 83 { |
84 int orig_pos = ftell(f); | |
85 unsigned char data[len-8]; | |
86 int i; | |
87 | |
88 len -= 8; | |
89 for (i=0; i<len; i++) | |
90 fread(&data[i], 1, 1, f); | |
91 | |
92 printf(" [%d bit", data[19]); | |
93 if (data[17] == 1) | |
94 printf(" mono"); | |
95 else | |
96 printf(" %d channels", data[17]); | |
97 printf("]\n"); | |
98 fseek(f,orig_pos,SEEK_SET); | |
99 } | |
100 | |
26576 | 101 #if 0 |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
26474
diff
changeset
|
102 static void userdata_info(FILE *f, int len, int pos, int level) |
1199 | 103 { |
104 int orig_pos = pos; /*ftell(f);*/ | |
105 unsigned int atom_size = 1; | |
106 unsigned int atom_type; | |
107 | |
108 // printf("userdata @ %d:%d (%d)\n", pos, pos+len, len); | |
109 | |
110 // fseek(f, pos+3, SEEK_SET); | |
111 | |
112 while (atom_size != 0) | |
113 { | |
114 atom_size=read_dword(f);// if(fread(&atom_size_b,4,1,f)<=0) break; | |
115 if(fread(&atom_type,4,1,f)<=0) break; | |
116 | |
117 if(atom_size<8) break; // error | |
118 | |
119 // printf("%08X: %*s %.4s (%08X) %05d (begin: %08X)\n",pos,level*2,"", | |
120 // &atom_type,atom_type,atom_size,pos+8); | |
121 | |
122 switch(atom_type) | |
123 { | |
124 case 0x797063A9: /* cpy (copyright) */ | |
125 { | |
126 char *data = malloc(atom_size-8); | |
127 | |
128 fseek(f, pos+6, SEEK_SET); | |
129 fread(data, atom_size-8, 1, f); | |
130 printf(" Copyright: %s\n", data); | |
131 free(data); | |
132 } | |
133 break; | |
134 case 0x666E69A9: /* inf (information) */ | |
135 { | |
136 char data[atom_size-8]; | |
137 | |
138 fread(&data, 1, atom_size-8, f); | |
139 printf(" Owner: %s\n", &data); | |
140 } | |
141 break; | |
142 case 0x6D616EA9: /* nam (name) */ | |
143 { | |
144 char data[atom_size-8]; | |
145 | |
146 fread(&data, 1, atom_size-8, f); | |
147 printf(" Name: %s\n", &data); | |
148 } | |
149 break; | |
150 } | |
151 } | |
152 fseek(f,orig_pos,SEEK_SET); | |
153 } | |
26576 | 154 #endif |
1199 | 155 |
156 int time_scale = 0; | |
157 | |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
26474
diff
changeset
|
158 static void lschunks(FILE *f,int level,unsigned int endpos){ |
1 | 159 unsigned int atom_size; |
160 unsigned int atom_type; | |
161 int pos; | |
1175 | 162 |
1 | 163 while(endpos==0 || ftell(f)<endpos){ |
164 pos=ftell(f); | |
165 atom_size=read_dword(f);// if(fread(&atom_size_b,4,1,f)<=0) break; | |
166 if(fread(&atom_type,4,1,f)<=0) break; | |
167 | |
168 if(atom_size<8) break; // error | |
169 | |
1175 | 170 printf("%08X: %*s %.4s (%08X) %05d [%s] (begin: %08X)\n",pos,level*2,"",&atom_type,atom_type,atom_size, |
171 atom2human_type(atom_type), pos+8); // 8: atom_size fields (4) + atom_type fields (4) | |
172 | |
173 #ifndef NO_SPECIAL | |
1199 | 174 // if (atom_type == 0x61746475) |
175 // userdata_info(f, atom_size, pos, level); | |
176 | |
177 if (atom_type == 0x6468646D) | |
178 { | |
179 char data[4]; | |
180 | |
181 fread(&data, 1, 1, f); // char | |
182 printf("mdhd version %d\n", data[0]); | |
183 fread(&data, 3, 1, f); // int24 | |
184 fread(&data, 4, 1, f); // int32 | |
185 fread(&data, 4, 1, f); // int32 | |
186 fread(&data, 4, 1, f); // int32 | |
187 time_scale = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; | |
188 printf("timescale: %d\n", time_scale); | |
189 fread(&data, 4, 1, f); // int32 | |
190 fread(&data, 2, 1, f); // int16 | |
191 fread(&data, 2, 1, f); // int16 | |
192 } | |
193 | |
1175 | 194 if (atom_type == 0x64686D76) |
195 { | |
196 stream = S_VIDEO; | |
197 printf(" Found VIDEO Stream #%d\n", v_stream++); | |
198 } | |
199 | |
200 if (atom_type == 0x64686D73) | |
201 { | |
202 stream = S_AUDIO; | |
203 printf(" Found AUDIO Stream #%d\n", a_stream++); | |
204 } | |
205 | |
206 if (atom_type == 0x64686B74) // tkhd - track header | |
207 { | |
208 int i; | |
209 unsigned char data[atom_size]; | |
1199 | 210 int x, y; |
1175 | 211 |
212 for (i=0; i<atom_size; i++) | |
213 fread(&data[i], 1, 1, f); | |
214 | |
215 x = data[77]; | |
216 y = data[81]; | |
1199 | 217 printf(" Flags: %d\n", data[3]); |
1175 | 218 printf(" Picture size: %dx%d\n", x, y); |
219 if (x == 0 && y == 0) | |
220 printf(" Possible audio stream!\n"); | |
221 } | |
1 | 222 |
223 if(atom_type==0x64737473) { // stsd | |
224 unsigned int tmp; | |
225 unsigned int count; | |
226 int i; | |
227 fread(&tmp,4,1,f); | |
228 count=read_dword(f);// fread(&count,4,1,f); | |
229 printf("desc count = %d\n",count); | |
230 for(i=0;i<count;i++){ | |
231 unsigned int len; | |
232 unsigned int format; | |
233 len=read_dword(f); // fread(&len,4,1,f); | |
234 fread(&format,4,1,f); | |
235 printf(" desc #%d: %.4s (%d)\n",i+1,&format,len); | |
1175 | 236 if (stream == S_VIDEO) |
237 video_stream_info(f, len); | |
238 if (stream == S_AUDIO) | |
239 audio_stream_info(f, len); | |
1 | 240 fseek(f,len-8,SEEK_CUR); |
241 } | |
242 } | |
243 | |
244 if(atom_type==0x6F637473) { // stco | |
245 int len,i; | |
246 read_dword(f); | |
247 len=read_dword(f); | |
248 printf("Chunk table size :%d\n",len); | |
249 for(i=0;i<len;i++) printf(" chunk #%d: 0x%X\n",i+1,read_dword(f)); | |
250 } | |
251 | |
252 | |
253 if(atom_type==0x73747473) { // stts | |
254 int len,i; | |
255 read_dword(f); | |
256 len=read_dword(f); | |
257 printf("T->S table size :%d\n",len); | |
258 for(i=0;i<len;i++){ | |
259 int num=read_dword(f); | |
260 int dur=read_dword(f); | |
1199 | 261 printf("%5d samples: %d duration", num, dur); |
262 if (stream == S_AUDIO) | |
263 printf("(rate: %f Hz)\n", (float)time_scale/dur); | |
264 else | |
265 printf("(fps: %f)\n", (float)time_scale/dur); | |
1 | 266 } |
267 } | |
268 | |
269 if(atom_type==0x63737473) { // stsc | |
270 int len,i; | |
271 read_dword(f); | |
272 len=read_dword(f); | |
273 printf("S->C table size :%d\n",len); | |
274 for(i=0;i<len;i++){ | |
275 int first=read_dword(f); | |
276 int spc=read_dword(f); | |
277 int sdid=read_dword(f); | |
1199 | 278 printf(" chunk %d... %d s/c desc: %d\n",first,spc,sdid); |
1 | 279 } |
280 } | |
281 | |
282 if(atom_type==0x7A737473) { // stsz | |
283 int len,i,ss; | |
284 read_dword(f); | |
285 ss=read_dword(f); | |
286 len=read_dword(f); | |
287 printf("Sample size table len: %d\n",len); | |
288 if(ss){ | |
289 printf(" common sample size: %d bytes\n",ss); | |
290 } else { | |
291 for(i=0;i<len;i++) printf(" sample #%d: %d bytes\n",i+1,read_dword(f)); | |
292 } | |
293 } | |
1175 | 294 #endif |
1 | 295 |
296 #if 1 | |
297 switch(atom_type){ | |
1175 | 298 case 0x7461646D: // mdat Movie data |
1 | 299 case 0x75716D72: // rmqu |
300 case 0x65657266: // free JUNK | |
301 case 0x64686B74: // tkhd Track header | |
302 case 0x61746475: // udta User data | |
303 case 0x64737473: // stsd Sample description | |
304 case 0x6F637473: // stco Chunk offset table | |
305 case 0x73747473: // stts Sample time table | |
306 case 0x63737473: // stsc Sample->Chunk mapping table | |
307 case 0x7A737473: // stsz Sample size table | |
6870 | 308 case 0x746f6e70: // pnot |
309 case 0x54434950: // PICT | |
6908 | 310 case 0x70797466: |
1 | 311 break; |
312 default: lschunks(f,level+1,pos+atom_size); | |
313 } | |
314 #else | |
315 switch(atom_type){ | |
316 case 0x766F6F6D: // moov | |
317 case 0x61726D72: // rmra | |
318 case 0x61646D72: // rmda | |
319 lschunks(f,level+1,pos+atom_size); | |
320 } | |
321 #endif | |
322 fseek(f,pos+atom_size,SEEK_SET); | |
323 } | |
324 } | |
325 | |
1175 | 326 int main(int argc,char* argv[]) |
327 { | |
328 FILE *f; | |
329 | |
330 if ((f = fopen(argc>1?argv[1]:"Akira.mov","rb")) == NULL) | |
331 return 1; | |
1 | 332 |
26474
5ac02417f474
Remove useless 0 flag from s printf conversion specifier, fixes the warning:
diego
parents:
24202
diff
changeset
|
333 printf("%.8s %.4s (%.8s) %5s [%s]\n\n", |
1175 | 334 "position", "atom", "atomtype", "len", "human readable atom name"); |
1 | 335 |
1175 | 336 lschunks(f, 0, 0); |
337 | |
338 printf("\nSummary: streams: %d video/%d audio\n", v_stream, a_stream); | |
23659
f15f95c2671a
Fix "control reaches end of non-void function" warnings.
diego
parents:
23658
diff
changeset
|
339 |
f15f95c2671a
Fix "control reaches end of non-void function" warnings.
diego
parents:
23658
diff
changeset
|
340 return 0; |
1 | 341 } |