Mercurial > mplayer.hg
annotate libmpdemux/demux_mov.c @ 2545:89e3bf3c0c4e
seek ebfore begin of the movie fixed
author | arpi |
---|---|
date | Mon, 29 Oct 2001 22:11:40 +0000 |
parents | fd48f0d813b6 |
children | c9485365537d |
rev | line source |
---|---|
2148 | 1 // QuickTime MOV file parser by A'rpi |
2 // based on TOOLS/movinfo.c by me & Al3x | |
3 // compressed header support from moov.c of the openquicktime lib. | |
2386 | 4 // References: http://openquicktime.sf.net/, http://www.heroinewarrior.com/ |
2542 | 5 // http://www.geocities.com/SiliconValley/Lakes/2160/fformats/files/mov.pdf |
1490 | 6 |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <unistd.h> | |
10 | |
1567 | 11 #include "config.h" |
2148 | 12 |
1567 | 13 #include "mp_msg.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
14 #include "help_mp.h" |
1490 | 15 |
16 #include "stream.h" | |
17 #include "demuxer.h" | |
18 #include "stheader.h" | |
19 | |
2386 | 20 #include "bswap.h" |
21 | |
2148 | 22 #ifdef HAVE_ZLIB |
23 #include <zlib.h> | |
24 #endif | |
25 | |
1490 | 26 typedef struct { |
2100 | 27 unsigned int pts; // duration |
28 unsigned int size; | |
29 off_t pos; | |
30 } mov_sample_t; | |
31 | |
32 typedef struct { | |
2115 | 33 unsigned int sample; // number of the first sample in teh chunk |
34 unsigned int size; // number of samples in the chunk | |
35 int desc; // for multiple codecs mode - not used | |
2100 | 36 off_t pos; |
37 } mov_chunk_t; | |
38 | |
39 typedef struct { | |
40 unsigned int first; | |
41 unsigned int spc; | |
42 unsigned int sdid; | |
43 } mov_chunkmap_t; | |
44 | |
45 typedef struct { | |
2115 | 46 unsigned int num; |
47 unsigned int dur; | |
48 } mov_durmap_t; | |
49 | |
50 typedef struct { | |
1490 | 51 int id; |
52 int type; | |
2101 | 53 int pos; |
54 // | |
1490 | 55 int timescale; |
2100 | 56 unsigned int length; |
2115 | 57 int samplesize; // 0 = variable |
58 int duration; // 0 = variable | |
1490 | 59 int width,height; // for video |
60 unsigned int fourcc; | |
2115 | 61 // |
2101 | 62 int tkdata_len; // track data |
63 unsigned char* tkdata; | |
64 int stdata_len; // stream data | |
65 unsigned char* stdata; | |
2100 | 66 int samples_size; |
67 mov_sample_t* samples; | |
68 int chunks_size; | |
69 mov_chunk_t* chunks; | |
70 int chunkmap_size; | |
71 mov_chunkmap_t* chunkmap; | |
2115 | 72 int durmap_size; |
73 mov_durmap_t* durmap; | |
2544 | 74 int keyframes_size; |
75 unsigned int* keyframes; | |
1490 | 76 } mov_track_t; |
77 | |
2100 | 78 void mov_build_index(mov_track_t* trak){ |
79 int i,j,s; | |
80 int last=trak->chunks_size; | |
2115 | 81 unsigned int pts=0; |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
82 mp_msg(MSGT_DEMUX, MSGL_HINT, "MOV track: %d chunks, %d samples\n",trak->chunks_size,trak->samples_size); |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
83 mp_msg(MSGT_DEMUX, MSGL_HINT, "pts=%d scale=%d time=%5.3f\n",trak->length,trak->timescale,(float)trak->length/(float)trak->timescale); |
2100 | 84 // process chunkmap: |
85 i=trak->chunkmap_size; | |
86 while(i>0){ | |
87 --i; | |
88 for(j=trak->chunkmap[i].first;j<last;j++){ | |
89 trak->chunks[j].desc=trak->chunkmap[i].sdid; | |
90 trak->chunks[j].size=trak->chunkmap[i].spc; | |
91 } | |
92 last=trak->chunkmap[i].first; | |
93 } | |
2115 | 94 |
95 // calc pts of chunks: | |
96 s=0; | |
97 for(j=0;j<trak->chunks_size;j++){ | |
98 trak->chunks[j].sample=s; | |
99 s+=trak->chunks[j].size; | |
100 } | |
101 | |
102 if(!trak->samples_size){ | |
103 // constant sampesize | |
104 if(trak->durmap_size==1 || (trak->durmap_size==2 && trak->durmap[1].num==1)){ | |
2227 | 105 trak->duration=trak->durmap[0].dur; |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
106 } else mp_msg(MSGT_DEMUX, MSGL_ERR, "*** constant samplesize & variable duration not yet supported! ***\nContact the author if you have such sample file!\n"); |
2115 | 107 return; |
108 } | |
109 | |
110 // calc pts: | |
111 s=0; | |
112 for(j=0;j<trak->durmap_size;j++){ | |
113 for(i=0;i<trak->durmap[j].num;i++){ | |
114 trak->samples[s].pts=pts; | |
115 ++s; | |
116 pts+=trak->durmap[j].dur; | |
117 } | |
118 } | |
2100 | 119 |
120 // calc sample offsets | |
121 s=0; | |
122 for(j=0;j<trak->chunks_size;j++){ | |
123 off_t pos=trak->chunks[j].pos; | |
124 for(i=0;i<trak->chunks[j].size;i++){ | |
125 trak->samples[s].pos=pos; | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
126 mp_msg(MSGT_DEMUX, MSGL_DBG3, "Sample %5d: pts=%8d off=0x%08X size=%d\n",s, |
2100 | 127 trak->samples[s].pts, |
128 (int)trak->samples[s].pos, | |
129 trak->samples[s].size); | |
130 pos+=trak->samples[s].size; | |
131 ++s; | |
132 } | |
133 } | |
134 | |
135 } | |
136 | |
1490 | 137 #define MOV_MAX_TRACKS 256 |
138 | |
139 #define MOV_TRAK_UNKNOWN 0 | |
140 #define MOV_TRAK_VIDEO 1 | |
141 #define MOV_TRAK_AUDIO 2 | |
2532 | 142 #define MOV_TRAK_FLASH 3 |
1490 | 143 |
144 typedef struct { | |
145 off_t moov_start; | |
146 off_t moov_end; | |
147 off_t mdat_start; | |
148 off_t mdat_end; | |
149 int track_db; | |
150 mov_track_t* tracks[MOV_MAX_TRACKS]; | |
151 } mov_priv_t; | |
152 | |
153 #define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d)) | |
154 | |
155 int mov_check_file(demuxer_t* demuxer){ | |
156 int flags=0; | |
157 mov_priv_t* priv=malloc(sizeof(mov_priv_t)); | |
158 | |
1567 | 159 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for MOV\n"); |
1490 | 160 |
161 memset(priv,0,sizeof(mov_priv_t)); | |
162 demuxer->priv=priv; | |
163 | |
164 while(1){ | |
165 off_t len=stream_read_dword(demuxer->stream); | |
166 unsigned int id=stream_read_dword(demuxer->stream); | |
167 if(stream_eof(demuxer->stream)) break; // EOF | |
168 if(len<8) break; // invalid chunk | |
169 switch(id){ | |
170 case MOV_FOURCC('m','o','o','v'): | |
1567 | 171 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n"); |
1490 | 172 priv->moov_start=stream_tell(demuxer->stream); |
173 priv->moov_end=priv->moov_start+len-8; | |
174 flags|=1; | |
175 break; | |
176 case MOV_FOURCC('m','d','a','t'): | |
1567 | 177 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie DATA found!\n"); |
1490 | 178 priv->mdat_start=stream_tell(demuxer->stream); |
179 priv->mdat_end=priv->mdat_start+len-8; | |
180 flags|=2; | |
181 break; | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
182 case MOV_FOURCC('f','r','e','e'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
183 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
184 case MOV_FOURCC('w','i','d','e'): |
1490 | 185 default: |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
186 id = bswap_32(id); |
1567 | 187 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); |
1490 | 188 } |
189 if(!stream_skip(demuxer->stream,len-8)) break; | |
190 } | |
2148 | 191 |
192 if(flags==1) | |
193 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing data (mdat) chunk! Maybe broken file...\n"); | |
194 else if(flags==2) | |
195 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing header (moov/cmov) chunk! Maybe broken file...\n"); | |
1490 | 196 |
197 return (flags==3); | |
198 } | |
199 | |
200 static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak){ | |
201 mov_priv_t* priv=demuxer->priv; | |
202 while(1){ | |
203 off_t pos; | |
204 off_t len; | |
205 unsigned int id; | |
206 // | |
207 pos=stream_tell(demuxer->stream); | |
2148 | 208 // printf("stream_tell==%d\n",pos); |
1490 | 209 if(pos>=endpos) return; // END |
210 len=stream_read_dword(demuxer->stream); | |
2148 | 211 // printf("len==%d\n",len); |
1490 | 212 if(len<8) return; // error |
213 len-=8; | |
214 id=stream_read_dword(demuxer->stream); | |
215 // | |
1567 | 216 mp_msg(MSGT_DEMUX,MSGL_DBG2,"lschunks %.4s %d\n",&id,(int)len); |
1490 | 217 // |
218 if(trak){ | |
219 switch(id){ | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
220 case MOV_FOURCC('u','d','t','a'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
221 /* here not supported :p */ |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
222 break; |
1490 | 223 case MOV_FOURCC('t','k','h','d'): { |
1567 | 224 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sTrack header!\n",level,""); |
2101 | 225 // read codec data |
226 trak->tkdata_len=len; | |
227 trak->tkdata=malloc(trak->tkdata_len); | |
228 stream_read(demuxer->stream,trak->tkdata,trak->tkdata_len); | |
1490 | 229 break; |
230 } | |
231 case MOV_FOURCC('m','d','h','d'): { | |
2100 | 232 unsigned int tmp; |
1567 | 233 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia header!\n",level,""); |
2100 | 234 #if 0 |
235 tmp=stream_read_dword(demuxer->stream); | |
236 printf("dword1: 0x%08X (%d)\n",tmp,tmp); | |
237 tmp=stream_read_dword(demuxer->stream); | |
238 printf("dword2: 0x%08X (%d)\n",tmp,tmp); | |
239 tmp=stream_read_dword(demuxer->stream); | |
240 printf("dword3: 0x%08X (%d)\n",tmp,tmp); | |
241 tmp=stream_read_dword(demuxer->stream); | |
242 printf("dword4: 0x%08X (%d)\n",tmp,tmp); | |
243 tmp=stream_read_dword(demuxer->stream); | |
244 printf("dword5: 0x%08X (%d)\n",tmp,tmp); | |
245 tmp=stream_read_dword(demuxer->stream); | |
246 printf("dword6: 0x%08X (%d)\n",tmp,tmp); | |
247 #endif | |
248 stream_skip(demuxer->stream,12); | |
1490 | 249 // read timescale |
2100 | 250 trak->timescale=stream_read_dword(demuxer->stream); |
251 // read length | |
252 trak->length=stream_read_dword(demuxer->stream); | |
1490 | 253 break; |
254 } | |
255 case MOV_FOURCC('v','m','h','d'): { | |
1567 | 256 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sVideo header!\n",level,""); |
1490 | 257 trak->type=MOV_TRAK_VIDEO; |
258 // read video data | |
259 break; | |
260 } | |
261 case MOV_FOURCC('s','m','h','d'): { | |
1567 | 262 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSound header!\n",level,""); |
1490 | 263 trak->type=MOV_TRAK_AUDIO; |
264 // read audio data | |
265 break; | |
266 } | |
267 case MOV_FOURCC('s','t','s','d'): { | |
268 int i=stream_read_dword(demuxer->stream); // temp! | |
269 int count=stream_read_dword(demuxer->stream); | |
1567 | 270 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sDescription list! (cnt:%d)\n",level,"",count); |
1490 | 271 for(i=0;i<count;i++){ |
272 off_t pos=stream_tell(demuxer->stream); | |
273 off_t len=stream_read_dword(demuxer->stream); | |
274 unsigned int fourcc=stream_read_dword_le(demuxer->stream); | |
275 if(len<8) break; // error | |
1567 | 276 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s desc #%d: %.4s",level,"",i,&fourcc); |
1490 | 277 if(!i){ |
278 trak->fourcc=fourcc; | |
279 // read codec data | |
2101 | 280 trak->stdata_len=len-8; |
281 trak->stdata=malloc(trak->stdata_len); | |
282 stream_read(demuxer->stream,trak->stdata,trak->stdata_len); | |
283 if(trak->type==MOV_TRAK_VIDEO && trak->stdata_len>43){ | |
284 mp_msg(MSGT_DEMUX,MSGL_V," '%.*s'",trak->stdata_len-43,trak->stdata+43); | |
1490 | 285 } |
286 } | |
1567 | 287 mp_msg(MSGT_DEMUX,MSGL_V,"\n"); |
1490 | 288 if(fourcc!=trak->fourcc && i) |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
289 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC); |
1490 | 290 if(!stream_seek(demuxer->stream,pos+len)) break; |
291 } | |
292 break; | |
293 } | |
2100 | 294 case MOV_FOURCC('s','t','t','s'): { |
295 int temp=stream_read_dword(demuxer->stream); | |
296 int len=stream_read_dword(demuxer->stream); | |
297 int i; | |
298 int x=0; | |
299 unsigned int pts=0; | |
300 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample duration table! (%d blocks)\n",level,"",len); | |
2115 | 301 trak->durmap=malloc(sizeof(mov_durmap_t)*len); |
302 memset(trak->durmap,0,sizeof(mov_durmap_t)*len); | |
303 trak->durmap_size=len; | |
2100 | 304 for(i=0;i<len;i++){ |
2115 | 305 trak->durmap[i].num=stream_read_dword(demuxer->stream); |
306 trak->durmap[i].dur=stream_read_dword(demuxer->stream); | |
307 pts+=trak->durmap[i].num*trak->durmap[i].dur; | |
2386 | 308 |
309 if(i==0) | |
310 { | |
311 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); | |
312 if (!sh->fps) | |
313 sh->fps = trak->timescale/trak->durmap[i].dur; | |
314 /* initial fps */ | |
315 } | |
2100 | 316 } |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
317 if(trak->length!=pts) mp_msg(MSGT_DEMUX, MSGL_WARN, "Warning! pts=%d length=%d\n",pts,trak->length); |
2100 | 318 break; |
319 } | |
320 case MOV_FOURCC('s','t','s','c'): { | |
321 int temp=stream_read_dword(demuxer->stream); | |
322 int len=stream_read_dword(demuxer->stream); | |
2533 | 323 int ver = (temp << 24); |
324 int flags = (temp << 16)|(temp<<8)|temp; | |
2100 | 325 int i; |
2533 | 326 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample->Chunk mapping table! (%d blocks) (ver:%d,flags:%ld)\n", |
327 level,"",len,ver,flags); | |
2100 | 328 // read data: |
329 trak->chunkmap_size=len; | |
330 trak->chunkmap=malloc(sizeof(mov_chunkmap_t)*len); | |
331 for(i=0;i<len;i++){ | |
2103 | 332 trak->chunkmap[i].first=stream_read_dword(demuxer->stream)-1; |
2100 | 333 trak->chunkmap[i].spc=stream_read_dword(demuxer->stream); |
334 trak->chunkmap[i].sdid=stream_read_dword(demuxer->stream); | |
335 } | |
336 break; | |
337 } | |
338 case MOV_FOURCC('s','t','s','z'): { | |
339 int temp=stream_read_dword(demuxer->stream); | |
340 int ss=stream_read_dword(demuxer->stream); | |
2533 | 341 int ver = (temp << 24); |
342 int flags = (temp << 16)|(temp<<8)|temp; | |
343 int entries=stream_read_dword(demuxer->stream); | |
344 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample size table! (entries=%d ss=%d) (ver:%d,flags:%ld)\n", | |
345 level,"",entries,ss,ver,flags); | |
2115 | 346 trak->samplesize=ss; |
347 if(!ss){ | |
348 // variable samplesize | |
349 int i; | |
2533 | 350 trak->samples=realloc(trak->samples,sizeof(mov_sample_t)*entries); |
351 trak->samples_size=entries; | |
352 for(i=0;i<entries;i++) | |
2115 | 353 trak->samples[i].size=stream_read_dword(demuxer->stream); |
2100 | 354 } |
355 break; | |
356 } | |
357 case MOV_FOURCC('s','t','c','o'): { | |
358 int temp=stream_read_dword(demuxer->stream); | |
359 int len=stream_read_dword(demuxer->stream); | |
360 int i; | |
361 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sChunk offset table! (%d chunks)\n",level,"",len); | |
362 // extend array if needed: | |
363 if(len>trak->chunks_size){ | |
364 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len); | |
365 trak->chunks_size=len; | |
366 } | |
367 // read elements: | |
368 for(i=0;i<len;i++) trak->chunks[i].pos=stream_read_dword(demuxer->stream); | |
369 break; | |
370 } | |
2533 | 371 case MOV_FOURCC('s','t','s','s'): { |
372 int temp=stream_read_dword(demuxer->stream); | |
373 int entries=stream_read_dword(demuxer->stream); | |
374 int ver = (temp << 24); | |
375 int flags = (temp << 16)|(temp<<8)|temp; | |
376 int i; | |
2542 | 377 mp_msg(MSGT_DEMUX, MSGL_V,"MOV: %*sSyncing samples (keyframes) table! (%d entries) (ver:%d,flags:%ld)\n", |
2533 | 378 level, "",entries, ver, flags); |
2544 | 379 trak->keyframes_size=entries; |
380 trak->keyframes=malloc(sizeof(unsigned int)*entries); | |
381 for (i=0;i<entries;i++) trak->keyframes[i]=stream_read_dword(demuxer->stream)-1; | |
382 // for (i=0;i<entries;i++) printf("%3d: %d\n",i,trak->keyframes[i]); | |
2533 | 383 break; |
384 } | |
1490 | 385 case MOV_FOURCC('m','d','i','a'): { |
1567 | 386 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia stream!\n",level,""); |
1490 | 387 lschunks(demuxer,level+1,pos+len,trak); |
388 break; | |
389 } | |
390 case MOV_FOURCC('m','i','n','f'): { | |
1567 | 391 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia info!\n",level,""); |
1490 | 392 lschunks(demuxer,level+1,pos+len,trak); |
393 break; | |
394 } | |
395 case MOV_FOURCC('s','t','b','l'): { | |
1567 | 396 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample info!\n",level,""); |
1490 | 397 lschunks(demuxer,level+1,pos+len,trak); |
398 break; | |
399 } | |
2532 | 400 default: |
401 id = bswap_32(id); | |
402 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); | |
403 break; | |
1490 | 404 }//switch(id) |
2532 | 405 } else { /* not in track */ |
406 switch(id) { | |
407 case MOV_FOURCC('t','r','a','k'): { | |
1490 | 408 // if(trak) printf("MOV: Warning! trak in trak?\n"); |
409 if(priv->track_db>=MOV_MAX_TRACKS){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
410 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVtooManyTrk); |
1490 | 411 return; |
412 } | |
413 trak=malloc(sizeof(mov_track_t)); | |
414 memset(trak,0,sizeof(mov_track_t)); | |
1567 | 415 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Track #%d:\n",priv->track_db); |
1490 | 416 trak->id=priv->track_db; |
2100 | 417 priv->tracks[priv->track_db]=trak; |
1490 | 418 lschunks(demuxer,level+1,pos+len,trak); |
2100 | 419 mov_build_index(trak); |
420 switch(trak->type){ | |
421 case MOV_TRAK_AUDIO: { | |
422 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db); | |
423 sh->format=trak->fourcc; | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
424 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio bits: %d chans: %d\n",trak->stdata[19],trak->stdata[17]); |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
425 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s\n",&trak->fourcc); |
2543 | 426 #if 0 |
427 { FILE* f=fopen("stdata.dat","wb"); | |
428 fwrite(trak->stdata,trak->stdata_len,1,f); | |
429 fclose(f); } | |
430 { FILE* f=fopen("tkdata.dat","wb"); | |
431 fwrite(trak->tkdata,trak->tkdata_len,1,f); | |
432 fclose(f); } | |
433 #endif | |
2101 | 434 // Emulate WAVEFORMATEX struct: |
435 sh->wf=malloc(sizeof(WAVEFORMATEX)); | |
436 memset(sh->wf,0,sizeof(WAVEFORMATEX)); | |
2543 | 437 sh->wf->nChannels=(trak->stdata[16]<<8)+trak->stdata[17]; |
438 sh->wf->wBitsPerSample=(trak->stdata[18]<<8)+trak->stdata[19]; | |
439 // sh->wf->nSamplesPerSec=trak->timescale; | |
440 sh->wf->nSamplesPerSec=(trak->stdata[24]<<8)+trak->stdata[25]; | |
441 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*sh->wf->wBitsPerSample*sh->wf->nSamplesPerSec/8; | |
2101 | 442 // Selection: |
443 if(demuxer->audio->id==-1 || demuxer->audio->id==priv->track_db){ | |
444 // (auto)selected audio track: | |
445 demuxer->audio->id=priv->track_db; | |
446 demuxer->audio->sh=sh; sh->ds=demuxer->audio; | |
447 } | |
2100 | 448 break; |
449 } | |
450 case MOV_TRAK_VIDEO: { | |
451 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); | |
452 sh->format=trak->fourcc; | |
2386 | 453 if(!sh->fps) sh->fps=trak->timescale; |
2100 | 454 sh->frametime=1.0f/sh->fps; |
2101 | 455 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8); |
456 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); | |
457 | |
458 // emulate BITMAPINFOHEADER: | |
459 sh->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
460 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); | |
461 sh->bih->biSize=40; | |
462 sh->bih->biWidth=sh->disp_w; | |
463 sh->bih->biHeight=sh->disp_h; | |
464 sh->bih->biPlanes=0; | |
465 sh->bih->biBitCount=16; | |
466 sh->bih->biCompression=trak->fourcc; | |
467 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight; | |
468 | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
469 mp_msg(MSGT_DEMUX, MSGL_INFO, "Image size: %d x %d\n",sh->disp_w,sh->disp_h); |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
470 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43); |
2115 | 471 |
2101 | 472 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){ |
473 // (auto)selected video track: | |
474 demuxer->video->id=priv->track_db; | |
475 demuxer->video->sh=sh; sh->ds=demuxer->video; | |
476 } | |
2100 | 477 break; |
478 } | |
2532 | 479 default: |
480 mp_msg(MSGT_DEMUX, MSGL_INFO, "Unknown track type found (type: %d)\n", trak->type); | |
481 break; | |
2100 | 482 } |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
483 mp_msg(MSGT_DEMUX, MSGL_INFO, "--------------\n"); |
2100 | 484 priv->track_db++; |
1490 | 485 trak=NULL; |
2532 | 486 break; |
487 } | |
2148 | 488 #ifndef HAVE_ZLIB |
2532 | 489 case MOV_FOURCC('c','m','o','v'): { |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
490 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); |
1490 | 491 return; |
492 } | |
2148 | 493 #else |
2532 | 494 case MOV_FOURCC('c','m','o','v'): { |
2148 | 495 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); |
496 lschunks(demuxer,level+1,pos+len,NULL); | |
2532 | 497 break; |
498 } | |
499 case MOV_FOURCC('d','c','o','m'): { | |
2148 | 500 // int temp=stream_read_dword(demuxer->stream); |
2386 | 501 unsigned int len=bswap_32(stream_read_dword(demuxer->stream)); |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
502 mp_msg(MSGT_DEMUX, MSGL_INFO, "Compressed header uses %.4s algo!\n",&len); |
2532 | 503 break; |
504 } | |
505 case MOV_FOURCC('c','m','v','d'): { | |
2148 | 506 // int temp=stream_read_dword(demuxer->stream); |
507 unsigned int moov_sz=stream_read_dword(demuxer->stream); | |
508 unsigned int cmov_sz=len-4; | |
509 unsigned char* cmov_buf=malloc(cmov_sz); | |
510 unsigned char* moov_buf=malloc(moov_sz+16); | |
511 int zret; | |
512 z_stream zstrm; | |
513 stream_t* backup; | |
514 | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
515 mp_msg(MSGT_DEMUX, MSGL_INFO, "Compressed header size: %d / %d\n",cmov_sz,moov_sz); |
2148 | 516 |
517 stream_read(demuxer->stream,cmov_buf,cmov_sz); | |
518 | |
519 zstrm.zalloc = (alloc_func)0; | |
520 zstrm.zfree = (free_func)0; | |
521 zstrm.opaque = (voidpf)0; | |
522 zstrm.next_in = cmov_buf; | |
523 zstrm.avail_in = cmov_sz; | |
524 zstrm.next_out = moov_buf; | |
525 zstrm.avail_out = moov_sz; | |
526 | |
527 zret = inflateInit(&zstrm); | |
528 if (zret != Z_OK) | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
529 { mp_msg(MSGT_DEMUX, MSGL_ERR, "QT cmov: inflateInit err %d\n",zret); |
2148 | 530 return; |
531 } | |
532 zret = inflate(&zstrm, Z_NO_FLUSH); | |
533 if ((zret != Z_OK) && (zret != Z_STREAM_END)) | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
534 { mp_msg(MSGT_DEMUX, MSGL_ERR, "QT cmov inflate: ERR %d\n",zret); |
2148 | 535 return; |
536 } | |
537 #if 0 | |
538 else { | |
539 FILE *DecOut; | |
540 DecOut = fopen("Out.bin", "w"); | |
541 fwrite(moov_buf, 1, moov_sz, DecOut); | |
542 fclose(DecOut); | |
543 } | |
544 #endif | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
545 if(moov_sz != zstrm.total_out) |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
546 mp_msg(MSGT_DEMUX, MSGL_WARN, "Warning! moov size differs cmov: %d zlib: %d\n",moov_sz,zstrm.total_out); |
2148 | 547 zret = inflateEnd(&zstrm); |
548 | |
549 backup=demuxer->stream; | |
550 demuxer->stream=new_memory_stream(moov_buf,moov_sz); | |
551 stream_skip(demuxer->stream,8); | |
552 lschunks(demuxer,level+1,moov_sz,NULL); // parse uncompr. 'moov' | |
553 //free_stream(demuxer->stream); | |
554 demuxer->stream=backup; | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
555 free(cmov_buf); |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
556 free(moov_buf); |
2532 | 557 break; |
2148 | 558 } |
559 #endif | |
2532 | 560 case MOV_FOURCC('u','d','t','a'): |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
561 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
562 unsigned int udta_id; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
563 off_t udta_len; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
564 off_t udta_size = len; |
1490 | 565 |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
566 mp_msg(MSGT_DEMUX, MSGL_DBG2, "mov: user data record found\n"); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
567 mp_msg(MSGT_DEMUX, MSGL_INFO, "Quicktime Clip Info:\n"); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
568 |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
569 while((len > 8) && (udta_size > 8)) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
570 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
571 udta_len = stream_read_dword(demuxer->stream); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
572 udta_id = stream_read_dword(demuxer->stream); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
573 udta_size -= 8; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
574 mp_msg(MSGT_DEMUX, MSGL_DBG2, "udta_id: %.4s (len: %d)\n", &udta_id, udta_len); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
575 switch (udta_id) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
576 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
577 case MOV_FOURCC(0xa9,'c','p','y'): |
2542 | 578 case MOV_FOURCC(0xa9,'d','a','y'): |
579 case MOV_FOURCC(0xa9,'d','i','r'): | |
580 /* 0xa9,'e','d','1' - '9' : edit timestamps */ | |
581 case MOV_FOURCC(0xa9,'f','m','t'): | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
582 case MOV_FOURCC(0xa9,'i','n','f'): |
2542 | 583 case MOV_FOURCC(0xa9,'p','r','d'): |
584 case MOV_FOURCC(0xa9,'p','r','f'): | |
585 case MOV_FOURCC(0xa9,'r','e','q'): | |
586 case MOV_FOURCC(0xa9,'s','r','c'): | |
587 case MOV_FOURCC('n','a','m','e'): | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
588 case MOV_FOURCC(0xa9,'n','a','m'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
589 case MOV_FOURCC(0xa9,'A','R','T'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
590 case MOV_FOURCC(0xa9,'c','m','t'): |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
591 case MOV_FOURCC(0xa9,'a','u','t'): |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
592 case MOV_FOURCC(0xa9,'s','w','r'): |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
593 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
594 off_t text_len = stream_read_word(demuxer->stream); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
595 char text[text_len+2+1]; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
596 stream_read(demuxer->stream, (char *)&text, text_len+2); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
597 text[text_len+2] = 0x0; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
598 switch(udta_id) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
599 { |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
600 case MOV_FOURCC(0xa9,'a','u','t'): |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
601 mp_msg(MSGT_DEMUX, MSGL_INFO, " Author: %s\n", &text[2]); |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
602 break; |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
603 case MOV_FOURCC(0xa9,'c','p','y'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
604 mp_msg(MSGT_DEMUX, MSGL_INFO, " Copyright: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
605 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
606 case MOV_FOURCC(0xa9,'i','n','f'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
607 mp_msg(MSGT_DEMUX, MSGL_INFO, " Info: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
608 break; |
2542 | 609 case MOV_FOURCC('n','a','m','e'): |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
610 case MOV_FOURCC(0xa9,'n','a','m'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
611 mp_msg(MSGT_DEMUX, MSGL_INFO, " Name: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
612 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
613 case MOV_FOURCC(0xa9,'A','R','T'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
614 mp_msg(MSGT_DEMUX, MSGL_INFO, " Artist: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
615 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
616 case MOV_FOURCC(0xa9,'d','i','r'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
617 mp_msg(MSGT_DEMUX, MSGL_INFO, " Director: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
618 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
619 case MOV_FOURCC(0xa9,'c','m','t'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
620 mp_msg(MSGT_DEMUX, MSGL_INFO, " Comment: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
621 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
622 case MOV_FOURCC(0xa9,'r','e','q'): |
2542 | 623 mp_msg(MSGT_DEMUX, MSGL_INFO, " Requirements: %s\n", &text[2]); |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
624 break; |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
625 case MOV_FOURCC(0xa9,'s','w','r'): |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
626 mp_msg(MSGT_DEMUX, MSGL_INFO, " Software: %s\n", &text[2]); |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
627 break; |
2542 | 628 case MOV_FOURCC(0xa9,'d','a','y'): |
629 mp_msg(MSGT_DEMUX, MSGL_INFO, " Creation timestamp: %s\n", &text[2]); | |
630 break; | |
631 case MOV_FOURCC(0xa9,'f','m','t'): | |
632 mp_msg(MSGT_DEMUX, MSGL_INFO, " Format: %s\n", &text[2]); | |
633 break; | |
634 case MOV_FOURCC(0xa9,'p','r','d'): | |
635 mp_msg(MSGT_DEMUX, MSGL_INFO, " Producer: %s\n", &text[2]); | |
636 break; | |
637 case MOV_FOURCC(0xa9,'p','r','f'): | |
638 mp_msg(MSGT_DEMUX, MSGL_INFO, " Performer(s): %s\n", &text[2]); | |
639 break; | |
640 case MOV_FOURCC(0xa9,'s','r','c'): | |
641 mp_msg(MSGT_DEMUX, MSGL_INFO, " Source providers: %s\n", &text[2]); | |
642 break; | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
643 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
644 udta_size -= 4+text_len; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
645 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
646 } |
2542 | 647 /* some other shits: WLOC - window location, |
648 LOOP - looping style, | |
649 SelO - play only selected frames | |
650 AllF - play all frames | |
651 */ | |
652 case MOV_FOURCC('W','L','O','C'): | |
653 case MOV_FOURCC('L','O','O','P'): | |
654 case MOV_FOURCC('S','e','l','O'): | |
655 case MOV_FOURCC('A','l','l','F'): | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
656 default: |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
657 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
658 char dump[udta_len-4]; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
659 stream_read(demuxer->stream, (char *)&dump, udta_len-4-4); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
660 udta_size -= udta_len; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
661 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
662 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
663 } |
2532 | 664 break; |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
665 } /* eof udta */ |
2532 | 666 default: |
667 id = bswap_32(id); | |
668 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); | |
669 } /* endof switch */ | |
670 } /* endof else */ | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
671 |
1490 | 672 pos+=len+8; |
673 if(pos>=endpos) break; | |
674 if(!stream_seek(demuxer->stream,pos)) break; | |
675 } | |
676 } | |
677 | |
678 int mov_read_header(demuxer_t* demuxer){ | |
679 mov_priv_t* priv=demuxer->priv; | |
680 | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
681 mp_msg(MSGT_DEMUX, MSGL_DBG3, "mov_read_header!\n"); |
1490 | 682 |
683 // Parse header: | |
2100 | 684 stream_reset(demuxer->stream); |
1490 | 685 if(!stream_seek(demuxer->stream,priv->moov_start)) return 0; // ??? |
686 lschunks(demuxer, 0, priv->moov_end, NULL); | |
687 | |
2127 | 688 return 1; |
1490 | 689 } |
2101 | 690 |
691 // return value: | |
692 // 0 = EOF or no stream found | |
693 // 1 = successfully read a packet | |
694 int demux_mov_fill_buffer(demuxer_t *demuxer,demux_stream_t* ds){ | |
695 mov_priv_t* priv=demuxer->priv; | |
696 mov_track_t* trak=NULL; | |
697 float pts; | |
698 | |
699 if(ds->id<0 || ds->id>=priv->track_db) return 0; | |
700 trak=priv->tracks[ds->id]; | |
701 | |
2115 | 702 if(trak->samplesize){ |
703 // read chunk: | |
2419 | 704 int x; |
2115 | 705 if(trak->pos>=trak->chunks_size) return 0; // EOF |
706 stream_seek(demuxer->stream,trak->chunks[trak->pos].pos); | |
707 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
2543 | 708 x=trak->chunks[trak->pos].size; |
709 // x=trak->chunks[trak->pos].size*trak->samplesize; | |
710 if(trak->samplesize!=1) printf("WARNING! Samplesize=%d \n",trak->samplesize); | |
711 if(trak->stdata_len>=36){ | |
712 // extended stsd header - works for CBR MP3: | |
713 x/=(trak->stdata[30]<<8)+trak->stdata[31]; // samples/packet | |
714 // x*=(trak->stdata[34]<<8)+trak->stdata[35]; // bytes/packet | |
715 x*=(trak->stdata[38]<<8)+trak->stdata[39]; // bytes/frame | |
716 } else { | |
717 // works for ima4: -- we should find this info in mov headers! | |
718 x/=ds->ss_div; x*=ds->ss_mul; // compression ratio fix ! HACK ! | |
719 // x*=(trak->stdata[18]<<8)+trak->stdata[19];x/=8; // bits/sample | |
720 | |
721 } | |
2419 | 722 ds_read_packet(ds,demuxer->stream,x,pts,trak->chunks[trak->pos].pos,0); |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
723 if(ds==demuxer->audio) mp_msg(MSGT_DEMUX, MSGL_DBG2, "sample %d bytes pts %5.3f\n",trak->chunks[trak->pos].size*trak->samplesize,pts); |
2115 | 724 } else { |
2101 | 725 // read sample: |
726 if(trak->pos>=trak->samples_size) return 0; // EOF | |
727 stream_seek(demuxer->stream,trak->samples[trak->pos].pos); | |
728 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; | |
729 ds_read_packet(ds,demuxer->stream,trak->samples[trak->pos].size,pts,trak->samples[trak->pos].pos,0); | |
2115 | 730 } |
2101 | 731 ++trak->pos; |
2115 | 732 |
2101 | 733 return 1; |
734 | |
735 } | |
2227 | 736 |
737 static float mov_seek_track(mov_track_t* trak,float pts,int flags){ | |
738 | |
739 // printf("MOV track seek called %5.3f \n",pts); | |
740 if(flags&2) pts*=trak->length; else pts*=(float)trak->timescale; | |
741 | |
742 if(trak->samplesize){ | |
743 int sample=pts/trak->duration; | |
744 // printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration); | |
745 if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative | |
746 trak->pos=0; | |
747 while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos; | |
748 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
749 } else { | |
2545 | 750 unsigned int ipts; |
751 if(!(flags&1)) pts+=trak->samples[trak->pos].pts; | |
752 if(pts<0) pts=0; | |
753 ipts=pts; | |
754 //printf("MOV track seek - sample: %d \n",ipts); | |
2544 | 755 for(trak->pos=0;trak->pos<trak->samples_size;++trak->pos){ |
756 if(trak->samples[trak->pos].pts>=ipts) break; // found it! | |
757 } | |
758 if(trak->keyframes_size){ | |
759 // find nearest keyframe | |
760 int i; | |
761 for(i=0;i<trak->keyframes_size;i++){ | |
762 if(trak->keyframes[i]>=trak->pos) break; | |
763 } | |
764 if(i>0 && | |
765 (trak->keyframes[i]-trak->pos) > (trak->pos-trak->keyframes[i-1])) --i; | |
766 trak->pos=trak->keyframes[i]; | |
767 // printf("nearest keyframe: %d \n",trak->pos); | |
768 } | |
2227 | 769 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; |
770 } | |
771 | |
772 // printf("MOV track seek done: %5.3f \n",pts); | |
773 | |
774 return pts; | |
775 } | |
776 | |
777 void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){ | |
778 mov_priv_t* priv=demuxer->priv; | |
779 demux_stream_t* ds; | |
780 | |
781 // printf("MOV seek called %5.3f flag=%d \n",pts,flags); | |
782 | |
783 ds=demuxer->video; | |
784 if(ds && ds->id>=0 && ds->id<priv->track_db){ | |
785 mov_track_t* trak=priv->tracks[ds->id]; | |
786 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; | |
787 //if(!(flags&1)) pts+=ds->pts; | |
788 pts=ds->pts=mov_seek_track(trak,pts,flags); | |
789 flags=1; // absolute seconds | |
790 } | |
791 | |
792 ds=demuxer->audio; | |
793 if(ds && ds->id>=0 && ds->id<priv->track_db){ | |
794 mov_track_t* trak=priv->tracks[ds->id]; | |
795 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; | |
796 //if(!(flags&1)) pts+=ds->pts; | |
797 ds->pts=mov_seek_track(trak,pts,flags); | |
798 } | |
799 | |
800 } | |
801 |