Mercurial > mplayer.hg
annotate libmpdemux/demux_mov.c @ 4707:af6fe94d455b
+static
author | arpi |
---|---|
date | Thu, 14 Feb 2002 22:33:29 +0000 |
parents | 59eb588c7115 |
children | d8b465e3fd88 |
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" |
12 #include "mp_msg.h" | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
13 #include "help_mp.h" |
1490 | 14 |
15 #include "stream.h" | |
16 #include "demuxer.h" | |
17 #include "stheader.h" | |
18 | |
2386 | 19 #include "bswap.h" |
20 | |
4332 | 21 #include "qtpalette.h" |
22 | |
2148 | 23 #ifdef HAVE_ZLIB |
24 #include <zlib.h> | |
25 #endif | |
26 | |
2786 | 27 #include <fcntl.h> |
28 | |
4129
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
29 #define BE_16(x) (be2me_16(*(unsigned short *)(x))) |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
30 #define BE_32(x) (be2me_32(*(unsigned int *)(x))) |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
31 |
1490 | 32 typedef struct { |
2100 | 33 unsigned int pts; // duration |
34 unsigned int size; | |
35 off_t pos; | |
36 } mov_sample_t; | |
37 | |
38 typedef struct { | |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
39 unsigned int sample; // number of the first sample in the chunk |
2115 | 40 unsigned int size; // number of samples in the chunk |
41 int desc; // for multiple codecs mode - not used | |
2100 | 42 off_t pos; |
43 } mov_chunk_t; | |
44 | |
45 typedef struct { | |
46 unsigned int first; | |
47 unsigned int spc; | |
48 unsigned int sdid; | |
49 } mov_chunkmap_t; | |
50 | |
51 typedef struct { | |
2115 | 52 unsigned int num; |
53 unsigned int dur; | |
54 } mov_durmap_t; | |
55 | |
4624 | 56 #define MOV_TRAK_UNKNOWN 0 |
57 #define MOV_TRAK_VIDEO 1 | |
58 #define MOV_TRAK_AUDIO 2 | |
59 #define MOV_TRAK_FLASH 3 | |
60 #define MOV_TRAK_GENERIC 4 | |
61 #define MOV_TRAK_CODE 5 | |
62 | |
2115 | 63 typedef struct { |
1490 | 64 int id; |
65 int type; | |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
66 off_t pos; |
2101 | 67 // |
1490 | 68 int timescale; |
2100 | 69 unsigned int length; |
2115 | 70 int samplesize; // 0 = variable |
71 int duration; // 0 = variable | |
1490 | 72 int width,height; // for video |
73 unsigned int fourcc; | |
2115 | 74 // |
2101 | 75 int tkdata_len; // track data |
76 unsigned char* tkdata; | |
77 int stdata_len; // stream data | |
78 unsigned char* stdata; | |
2100 | 79 int samples_size; |
80 mov_sample_t* samples; | |
81 int chunks_size; | |
82 mov_chunk_t* chunks; | |
83 int chunkmap_size; | |
84 mov_chunkmap_t* chunkmap; | |
2115 | 85 int durmap_size; |
86 mov_durmap_t* durmap; | |
2544 | 87 int keyframes_size; |
88 unsigned int* keyframes; | |
1490 | 89 } mov_track_t; |
90 | |
2100 | 91 void mov_build_index(mov_track_t* trak){ |
92 int i,j,s; | |
93 int last=trak->chunks_size; | |
2115 | 94 unsigned int pts=0; |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
95 |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
96 #if 0 |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
97 if (trak->chunks_size <= 0) |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
98 { |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
99 mp_msg(MSGT_DEMUX, MSGL_WARN, "No chunk offset table, trying to build one!\n"); |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
100 |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
101 trak->chunks_size = trak->samples_size; |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
102 trak->chunks = realloc(trak->chunks, sizeof(mov_chunk_t)*trak->chunks_size); |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
103 |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
104 for (i=0; i < trak->chunks_size; i++) |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
105 trak->chunks[i].pos = -1; |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
106 } |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
107 #endif |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
108 |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
109 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
|
110 mp_msg(MSGT_DEMUX, MSGL_HINT, "pts=%d scale=%d time=%5.3f\n",trak->length,trak->timescale,(float)trak->length/(float)trak->timescale); |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
111 |
2100 | 112 // process chunkmap: |
113 i=trak->chunkmap_size; | |
114 while(i>0){ | |
115 --i; | |
116 for(j=trak->chunkmap[i].first;j<last;j++){ | |
117 trak->chunks[j].desc=trak->chunkmap[i].sdid; | |
118 trak->chunks[j].size=trak->chunkmap[i].spc; | |
119 } | |
120 last=trak->chunkmap[i].first; | |
121 } | |
2115 | 122 |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
123 #if 0 |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
124 for (i=0; i < trak->chunks_size; i++) |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
125 { |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
126 /* fixup position */ |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
127 if (trak->chunks[i].pos == -1) |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
128 if (i > 0) |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
129 trak->chunks[i].pos = trak->chunks[i-1].pos + trak->chunks[i-1].size; |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
130 else |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
131 trak->chunks[i].pos = 0; /* FIXME: set initial pos */ |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
132 } |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
133 #endif |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
134 |
2115 | 135 // calc pts of chunks: |
136 s=0; | |
137 for(j=0;j<trak->chunks_size;j++){ | |
138 trak->chunks[j].sample=s; | |
139 s+=trak->chunks[j].size; | |
140 } | |
141 | |
4624 | 142 // workaround for fixed-size video frames (dv and uncompressed) |
143 if(!trak->samples_size && trak->type==MOV_TRAK_VIDEO){ | |
144 trak->samples_size=s; | |
145 trak->samples=malloc(sizeof(mov_sample_t)*s); | |
146 for(i=0;i<s;i++) | |
147 trak->samples[i].size=trak->samplesize; | |
148 trak->samplesize=0; | |
149 } | |
150 | |
2115 | 151 if(!trak->samples_size){ |
152 // constant sampesize | |
153 if(trak->durmap_size==1 || (trak->durmap_size==2 && trak->durmap[1].num==1)){ | |
2227 | 154 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
|
155 } 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 | 156 return; |
157 } | |
158 | |
159 // calc pts: | |
160 s=0; | |
161 for(j=0;j<trak->durmap_size;j++){ | |
162 for(i=0;i<trak->durmap[j].num;i++){ | |
163 trak->samples[s].pts=pts; | |
164 ++s; | |
165 pts+=trak->durmap[j].dur; | |
166 } | |
167 } | |
2100 | 168 |
169 // calc sample offsets | |
170 s=0; | |
171 for(j=0;j<trak->chunks_size;j++){ | |
172 off_t pos=trak->chunks[j].pos; | |
173 for(i=0;i<trak->chunks[j].size;i++){ | |
174 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
|
175 mp_msg(MSGT_DEMUX, MSGL_DBG3, "Sample %5d: pts=%8d off=0x%08X size=%d\n",s, |
2100 | 176 trak->samples[s].pts, |
177 (int)trak->samples[s].pos, | |
178 trak->samples[s].size); | |
179 pos+=trak->samples[s].size; | |
180 ++s; | |
181 } | |
182 } | |
183 | |
184 } | |
185 | |
1490 | 186 #define MOV_MAX_TRACKS 256 |
187 | |
188 typedef struct { | |
189 off_t moov_start; | |
190 off_t moov_end; | |
191 off_t mdat_start; | |
192 off_t mdat_end; | |
193 int track_db; | |
194 mov_track_t* tracks[MOV_MAX_TRACKS]; | |
195 } mov_priv_t; | |
196 | |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
197 #warning "FIXME - mov support is only working perfectly on Little Endian systems?!" |
3071 | 198 //#ifdef WORDS_BIGENDIAN |
199 //#define MOV_FOURCC(a,b,c,d) ((d)|(c<<8)|(b<<16)|(a<<24)) | |
200 //#else | |
1490 | 201 #define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d)) |
3071 | 202 //#endif |
1490 | 203 |
204 int mov_check_file(demuxer_t* demuxer){ | |
205 int flags=0; | |
2879 | 206 int no=0; |
1490 | 207 mov_priv_t* priv=malloc(sizeof(mov_priv_t)); |
208 | |
1567 | 209 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for MOV\n"); |
1490 | 210 |
211 memset(priv,0,sizeof(mov_priv_t)); | |
212 demuxer->priv=priv; | |
213 | |
214 while(1){ | |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
215 int skipped=8; |
1490 | 216 off_t len=stream_read_dword(demuxer->stream); |
217 unsigned int id=stream_read_dword(demuxer->stream); | |
218 if(stream_eof(demuxer->stream)) break; // EOF | |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
219 if (len == 1) /* real size is 64bits - cjb */ |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
220 { |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
221 #ifndef _LARGEFILE_SOURCE |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
222 if (stream_read_dword(demuxer->stream) != 0) |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
223 mp_msg(MSGT_DEMUX, MSGL_WARN, "64bit file, but you've MPlayer compiled without LARGEFILE support!\n"); |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
224 len = stream_read_dword(demuxer->stream); |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
225 #else |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
226 len = stream_read_qword(demuxer->stream); |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
227 #endif |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
228 skipped += 8; |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
229 } |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
230 else if(len<8) break; // invalid chunk |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
231 |
1490 | 232 switch(id){ |
233 case MOV_FOURCC('m','o','o','v'): | |
1567 | 234 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n"); |
1490 | 235 priv->moov_start=stream_tell(demuxer->stream); |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
236 priv->moov_end=priv->moov_start+len-skipped; |
1490 | 237 flags|=1; |
238 break; | |
239 case MOV_FOURCC('m','d','a','t'): | |
1567 | 240 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie DATA found!\n"); |
1490 | 241 priv->mdat_start=stream_tell(demuxer->stream); |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
242 priv->mdat_end=priv->mdat_start+len-skipped; |
1490 | 243 flags|=2; |
244 break; | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
245 case MOV_FOURCC('f','r','e','e'): |
2942 | 246 case MOV_FOURCC('s','k','i','p'): |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
247 /* unused, if you edit a mov, you can use space provided by free atoms (redefining it) */ |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
248 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
249 case MOV_FOURCC('w','i','d','e'): |
2879 | 250 break; |
1490 | 251 default: |
2879 | 252 if(no==0) return 0; // first chunk is bad! |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
253 id = bswap_32(id); |
1567 | 254 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); |
1490 | 255 } |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
256 if(!stream_skip(demuxer->stream,len-skipped)) break; |
2879 | 257 ++no; |
1490 | 258 } |
2148 | 259 |
260 if(flags==1) | |
261 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing data (mdat) chunk! Maybe broken file...\n"); | |
262 else if(flags==2) | |
263 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing header (moov/cmov) chunk! Maybe broken file...\n"); | |
1490 | 264 |
265 return (flags==3); | |
266 } | |
267 | |
268 static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak){ | |
269 mov_priv_t* priv=demuxer->priv; | |
270 while(1){ | |
271 off_t pos; | |
272 off_t len; | |
273 unsigned int id; | |
274 // | |
275 pos=stream_tell(demuxer->stream); | |
2148 | 276 // printf("stream_tell==%d\n",pos); |
1490 | 277 if(pos>=endpos) return; // END |
278 len=stream_read_dword(demuxer->stream); | |
2148 | 279 // printf("len==%d\n",len); |
1490 | 280 if(len<8) return; // error |
281 len-=8; | |
282 id=stream_read_dword(demuxer->stream); | |
283 // | |
1567 | 284 mp_msg(MSGT_DEMUX,MSGL_DBG2,"lschunks %.4s %d\n",&id,(int)len); |
1490 | 285 // |
286 if(trak){ | |
287 switch(id){ | |
3071 | 288 case MOV_FOURCC('f','r','e','e'): |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
289 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
|
290 /* here not supported :p */ |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
291 break; |
1490 | 292 case MOV_FOURCC('t','k','h','d'): { |
1567 | 293 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sTrack header!\n",level,""); |
2101 | 294 // read codec data |
295 trak->tkdata_len=len; | |
296 trak->tkdata=malloc(trak->tkdata_len); | |
297 stream_read(demuxer->stream,trak->tkdata,trak->tkdata_len); | |
1490 | 298 break; |
299 } | |
300 case MOV_FOURCC('m','d','h','d'): { | |
2100 | 301 unsigned int tmp; |
1567 | 302 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia header!\n",level,""); |
2100 | 303 #if 0 |
304 tmp=stream_read_dword(demuxer->stream); | |
305 printf("dword1: 0x%08X (%d)\n",tmp,tmp); | |
306 tmp=stream_read_dword(demuxer->stream); | |
307 printf("dword2: 0x%08X (%d)\n",tmp,tmp); | |
308 tmp=stream_read_dword(demuxer->stream); | |
309 printf("dword3: 0x%08X (%d)\n",tmp,tmp); | |
310 tmp=stream_read_dword(demuxer->stream); | |
311 printf("dword4: 0x%08X (%d)\n",tmp,tmp); | |
312 tmp=stream_read_dword(demuxer->stream); | |
313 printf("dword5: 0x%08X (%d)\n",tmp,tmp); | |
314 tmp=stream_read_dword(demuxer->stream); | |
315 printf("dword6: 0x%08X (%d)\n",tmp,tmp); | |
316 #endif | |
317 stream_skip(demuxer->stream,12); | |
1490 | 318 // read timescale |
2100 | 319 trak->timescale=stream_read_dword(demuxer->stream); |
320 // read length | |
321 trak->length=stream_read_dword(demuxer->stream); | |
1490 | 322 break; |
323 } | |
324 case MOV_FOURCC('v','m','h','d'): { | |
1567 | 325 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sVideo header!\n",level,""); |
1490 | 326 trak->type=MOV_TRAK_VIDEO; |
327 // read video data | |
328 break; | |
329 } | |
330 case MOV_FOURCC('s','m','h','d'): { | |
1567 | 331 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSound header!\n",level,""); |
1490 | 332 trak->type=MOV_TRAK_AUDIO; |
333 // read audio data | |
334 break; | |
335 } | |
2786 | 336 case MOV_FOURCC('g','m','h','d'): { |
337 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sGeneric header!\n",level,""); | |
338 trak->type=MOV_TRAK_GENERIC; | |
339 break; | |
340 } | |
4645
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
341 case MOV_FOURCC('n','m','h','d'): { |
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
342 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sGeneric header!\n",level,""); |
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
343 trak->type=MOV_TRAK_GENERIC; |
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
344 break; |
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
345 } |
1490 | 346 case MOV_FOURCC('s','t','s','d'): { |
347 int i=stream_read_dword(demuxer->stream); // temp! | |
348 int count=stream_read_dword(demuxer->stream); | |
1567 | 349 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sDescription list! (cnt:%d)\n",level,"",count); |
1490 | 350 for(i=0;i<count;i++){ |
351 off_t pos=stream_tell(demuxer->stream); | |
352 off_t len=stream_read_dword(demuxer->stream); | |
353 unsigned int fourcc=stream_read_dword_le(demuxer->stream); | |
354 if(len<8) break; // error | |
1567 | 355 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s desc #%d: %.4s",level,"",i,&fourcc); |
1490 | 356 if(!i){ |
357 trak->fourcc=fourcc; | |
358 // read codec data | |
2101 | 359 trak->stdata_len=len-8; |
360 trak->stdata=malloc(trak->stdata_len); | |
361 stream_read(demuxer->stream,trak->stdata,trak->stdata_len); | |
362 if(trak->type==MOV_TRAK_VIDEO && trak->stdata_len>43){ | |
363 mp_msg(MSGT_DEMUX,MSGL_V," '%.*s'",trak->stdata_len-43,trak->stdata+43); | |
1490 | 364 } |
365 } | |
1567 | 366 mp_msg(MSGT_DEMUX,MSGL_V,"\n"); |
1490 | 367 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
|
368 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC); |
1490 | 369 if(!stream_seek(demuxer->stream,pos+len)) break; |
370 } | |
371 break; | |
372 } | |
2100 | 373 case MOV_FOURCC('s','t','t','s'): { |
374 int temp=stream_read_dword(demuxer->stream); | |
375 int len=stream_read_dword(demuxer->stream); | |
376 int i; | |
377 int x=0; | |
378 unsigned int pts=0; | |
379 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample duration table! (%d blocks)\n",level,"",len); | |
2115 | 380 trak->durmap=malloc(sizeof(mov_durmap_t)*len); |
381 memset(trak->durmap,0,sizeof(mov_durmap_t)*len); | |
382 trak->durmap_size=len; | |
2100 | 383 for(i=0;i<len;i++){ |
2115 | 384 trak->durmap[i].num=stream_read_dword(demuxer->stream); |
385 trak->durmap[i].dur=stream_read_dword(demuxer->stream); | |
386 pts+=trak->durmap[i].num*trak->durmap[i].dur; | |
2386 | 387 |
2786 | 388 if(i==0 && trak->type == MOV_TRAK_VIDEO) |
2386 | 389 { |
390 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); | |
391 if (!sh->fps) | |
392 sh->fps = trak->timescale/trak->durmap[i].dur; | |
393 /* initial fps */ | |
394 } | |
2100 | 395 } |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
396 if(trak->length!=pts) mp_msg(MSGT_DEMUX, MSGL_WARN, "Warning! pts=%d length=%d\n",pts,trak->length); |
2100 | 397 break; |
398 } | |
399 case MOV_FOURCC('s','t','s','c'): { | |
400 int temp=stream_read_dword(demuxer->stream); | |
401 int len=stream_read_dword(demuxer->stream); | |
2533 | 402 int ver = (temp << 24); |
403 int flags = (temp << 16)|(temp<<8)|temp; | |
2100 | 404 int i; |
2533 | 405 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample->Chunk mapping table! (%d blocks) (ver:%d,flags:%ld)\n", |
406 level,"",len,ver,flags); | |
2100 | 407 // read data: |
408 trak->chunkmap_size=len; | |
409 trak->chunkmap=malloc(sizeof(mov_chunkmap_t)*len); | |
410 for(i=0;i<len;i++){ | |
2103 | 411 trak->chunkmap[i].first=stream_read_dword(demuxer->stream)-1; |
2100 | 412 trak->chunkmap[i].spc=stream_read_dword(demuxer->stream); |
413 trak->chunkmap[i].sdid=stream_read_dword(demuxer->stream); | |
414 } | |
415 break; | |
416 } | |
417 case MOV_FOURCC('s','t','s','z'): { | |
418 int temp=stream_read_dword(demuxer->stream); | |
419 int ss=stream_read_dword(demuxer->stream); | |
2533 | 420 int ver = (temp << 24); |
421 int flags = (temp << 16)|(temp<<8)|temp; | |
422 int entries=stream_read_dword(demuxer->stream); | |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
423 int i; |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
424 |
2533 | 425 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample size table! (entries=%d ss=%d) (ver:%d,flags:%ld)\n", |
426 level,"",entries,ss,ver,flags); | |
2786 | 427 trak->samplesize=ss; |
428 if (!ss) { | |
429 // variable samplesize | |
430 trak->samples=realloc(trak->samples,sizeof(mov_sample_t)*entries); | |
431 trak->samples_size=entries; | |
432 for(i=0;i<entries;i++) | |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
433 trak->samples[i].size=stream_read_dword(demuxer->stream); |
2786 | 434 } |
2100 | 435 break; |
436 } | |
437 case MOV_FOURCC('s','t','c','o'): { | |
438 int temp=stream_read_dword(demuxer->stream); | |
439 int len=stream_read_dword(demuxer->stream); | |
440 int i; | |
441 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sChunk offset table! (%d chunks)\n",level,"",len); | |
442 // extend array if needed: | |
443 if(len>trak->chunks_size){ | |
444 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len); | |
445 trak->chunks_size=len; | |
446 } | |
447 // read elements: | |
448 for(i=0;i<len;i++) trak->chunks[i].pos=stream_read_dword(demuxer->stream); | |
449 break; | |
450 } | |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
451 case MOV_FOURCC('c','o','6','4'): { |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
452 int temp=stream_read_dword(demuxer->stream); |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
453 int len=stream_read_dword(demuxer->stream); |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
454 int i; |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
455 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s64bit chunk offset table! (%d chunks)\n",level,"",len); |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
456 // extend array if needed: |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
457 if(len>trak->chunks_size){ |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
458 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len); |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
459 trak->chunks_size=len; |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
460 } |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
461 // read elements: |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
462 for(i=0;i<len;i++) |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
463 { |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
464 #ifndef _LARGEFILE_SOURCE |
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
465 if (stream_read_dword(demuxer->stream) != 0) |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
466 mp_msg(MSGT_DEMUX, MSGL_WARN, "Chunk %d has got 64bit address, but you've MPlayer compiled without LARGEFILE support!\n", i); |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
467 trak->chunks[i].pos = stream_read_dword(demuxer->stream); |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
468 #else |
3999
3c6b061ec033
mov_check_file 64bit support by Chris Bednar. also fixed co64 chunk and added warnings for 64bit files reading without largefiles support
alex
parents:
3652
diff
changeset
|
469 trak->chunks[i].pos = stream_read_qword(demuxer->stream); |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
470 #endif |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
471 } |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
472 break; |
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
473 } |
2533 | 474 case MOV_FOURCC('s','t','s','s'): { |
475 int temp=stream_read_dword(demuxer->stream); | |
476 int entries=stream_read_dword(demuxer->stream); | |
477 int ver = (temp << 24); | |
478 int flags = (temp << 16)|(temp<<8)|temp; | |
479 int i; | |
2542 | 480 mp_msg(MSGT_DEMUX, MSGL_V,"MOV: %*sSyncing samples (keyframes) table! (%d entries) (ver:%d,flags:%ld)\n", |
2533 | 481 level, "",entries, ver, flags); |
2544 | 482 trak->keyframes_size=entries; |
483 trak->keyframes=malloc(sizeof(unsigned int)*entries); | |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
484 for (i=0;i<entries;i++) |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
485 trak->keyframes[i]=stream_read_dword(demuxer->stream)-1; |
2544 | 486 // for (i=0;i<entries;i++) printf("%3d: %d\n",i,trak->keyframes[i]); |
2533 | 487 break; |
488 } | |
1490 | 489 case MOV_FOURCC('m','d','i','a'): { |
1567 | 490 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia stream!\n",level,""); |
1490 | 491 lschunks(demuxer,level+1,pos+len,trak); |
492 break; | |
493 } | |
494 case MOV_FOURCC('m','i','n','f'): { | |
1567 | 495 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia info!\n",level,""); |
1490 | 496 lschunks(demuxer,level+1,pos+len,trak); |
497 break; | |
498 } | |
499 case MOV_FOURCC('s','t','b','l'): { | |
1567 | 500 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample info!\n",level,""); |
1490 | 501 lschunks(demuxer,level+1,pos+len,trak); |
502 break; | |
503 } | |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
504 case MOV_FOURCC('e','d','t','s'): { |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
505 mp_msg(MSGT_DEMUX, MSGL_V, "MOV: %*sEdit atom!\n", level, ""); |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
506 lschunks(demuxer,level+1,pos+len,trak); |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
507 break; |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
508 } |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
509 case MOV_FOURCC('e','l','s','t'): { |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
510 int temp=stream_read_dword(demuxer->stream); |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
511 int entries=stream_read_dword(demuxer->stream); |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
512 int ver = (temp << 24); |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
513 int flags = (temp << 16)|(temp<<8)|temp; |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
514 int i; |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
515 |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
516 mp_msg(MSGT_DEMUX, MSGL_V,"MOV: %*sEdit list table (%d entries) (ver:%d,flags:%ld)\n", |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
517 level, "",entries, ver, flags); |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
518 #if 0 |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
519 for (i=0;i<entries;i++) |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
520 { |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
521 printf("entry#%d: dur: %ld mtime: %ld mrate: %ld\n", |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
522 i, stream_read_dword(demuxer->stream), |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
523 stream_read_dword(demuxer->stream), |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
524 stream_read_dword(demuxer->stream)); |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
525 } |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
526 #endif |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
527 break; |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
528 } |
2786 | 529 case MOV_FOURCC('c','o','d','e'): |
530 { | |
3071 | 531 #warning "Implement atom 'code' for FLASH support" |
2786 | 532 } |
2532 | 533 default: |
534 id = bswap_32(id); | |
535 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); | |
536 break; | |
1490 | 537 }//switch(id) |
2532 | 538 } else { /* not in track */ |
539 switch(id) { | |
540 case MOV_FOURCC('t','r','a','k'): { | |
1490 | 541 // if(trak) printf("MOV: Warning! trak in trak?\n"); |
542 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
|
543 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVtooManyTrk); |
1490 | 544 return; |
545 } | |
546 trak=malloc(sizeof(mov_track_t)); | |
547 memset(trak,0,sizeof(mov_track_t)); | |
1567 | 548 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Track #%d:\n",priv->track_db); |
1490 | 549 trak->id=priv->track_db; |
2100 | 550 priv->tracks[priv->track_db]=trak; |
1490 | 551 lschunks(demuxer,level+1,pos+len,trak); |
2100 | 552 mov_build_index(trak); |
553 switch(trak->type){ | |
554 case MOV_TRAK_AUDIO: { | |
555 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db); | |
556 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
|
557 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
|
558 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s\n",&trak->fourcc); |
2543 | 559 #if 0 |
560 { FILE* f=fopen("stdata.dat","wb"); | |
561 fwrite(trak->stdata,trak->stdata_len,1,f); | |
562 fclose(f); } | |
563 { FILE* f=fopen("tkdata.dat","wb"); | |
564 fwrite(trak->tkdata,trak->tkdata_len,1,f); | |
565 fclose(f); } | |
566 #endif | |
2101 | 567 // Emulate WAVEFORMATEX struct: |
568 sh->wf=malloc(sizeof(WAVEFORMATEX)); | |
569 memset(sh->wf,0,sizeof(WAVEFORMATEX)); | |
2543 | 570 sh->wf->nChannels=(trak->stdata[16]<<8)+trak->stdata[17]; |
571 sh->wf->wBitsPerSample=(trak->stdata[18]<<8)+trak->stdata[19]; | |
572 // sh->wf->nSamplesPerSec=trak->timescale; | |
573 sh->wf->nSamplesPerSec=(trak->stdata[24]<<8)+trak->stdata[25]; | |
574 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*sh->wf->wBitsPerSample*sh->wf->nSamplesPerSec/8; | |
2101 | 575 // Selection: |
576 if(demuxer->audio->id==-1 || demuxer->audio->id==priv->track_db){ | |
577 // (auto)selected audio track: | |
578 demuxer->audio->id=priv->track_db; | |
579 demuxer->audio->sh=sh; sh->ds=demuxer->audio; | |
580 } | |
2100 | 581 break; |
582 } | |
583 case MOV_TRAK_VIDEO: { | |
4129
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
584 int i, entry; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
585 int flag, start, count_flag, end, palette_count; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
586 int hdr_ptr = 43+33; // the byte just after depth |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
587 unsigned char *palette_map; |
2100 | 588 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
589 int depth = trak->stdata[43+32]; /* requested by Mike Melanson for Apple RLE decoder -- alex */ |
2100 | 590 sh->format=trak->fourcc; |
2386 | 591 if(!sh->fps) sh->fps=trak->timescale; |
2100 | 592 sh->frametime=1.0f/sh->fps; |
2101 | 593 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8); |
594 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); | |
595 | |
4129
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
596 // palettized? |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
597 if ((depth == 2) || (depth == 4) || (depth == 8) || |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
598 (depth == 34) || (depth == 36) || (depth == 40)) |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
599 palette_count = (1 << (depth & 0x0F)); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
600 else |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
601 palette_count = 0; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
602 |
2101 | 603 // emulate BITMAPINFOHEADER: |
4129
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
604 if (palette_count) |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
605 { |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
606 sh->bih=malloc(sizeof(BITMAPINFOHEADER) + palette_count * 4); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
607 memset(sh->bih,0,sizeof(BITMAPINFOHEADER) + palette_count * 4); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
608 sh->bih->biSize=40 + palette_count * 4; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
609 // fetch the relevant fields |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
610 flag = BE_16(&trak->stdata[hdr_ptr]); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
611 hdr_ptr += 2; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
612 start = BE_32(&trak->stdata[hdr_ptr]); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
613 hdr_ptr += 4; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
614 count_flag = BE_16(&trak->stdata[hdr_ptr]); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
615 hdr_ptr += 2; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
616 end = BE_16(&trak->stdata[hdr_ptr]); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
617 hdr_ptr += 2; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
618 palette_map = (unsigned char *)sh->bih + 40; |
4332 | 619 |
620 // load default palette | |
4646
59eb588c7115
reinstated original palette decision logic from XAnim (was the QT spec
melanson
parents:
4645
diff
changeset
|
621 if (flag & 0x08) |
4332 | 622 { |
4646
59eb588c7115
reinstated original palette decision logic from XAnim (was the QT spec
melanson
parents:
4645
diff
changeset
|
623 mp_msg(MSGT_DEMUX, MSGL_INFO, "Using default QT palette\n"); |
4332 | 624 if (palette_count == 4) |
625 memcpy(palette_map, qt_default_palette_4, 4 * 4); | |
626 else if (palette_count == 16) | |
627 memcpy(palette_map, qt_default_palette_16, 16 * 4); | |
628 if (palette_count == 256) | |
629 memcpy(palette_map, qt_default_palette_256, 256 * 4); | |
630 } | |
631 // load palette from file | |
632 else | |
4129
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
633 { |
4646
59eb588c7115
reinstated original palette decision logic from XAnim (was the QT spec
melanson
parents:
4645
diff
changeset
|
634 mp_msg(MSGT_DEMUX, MSGL_INFO, "Loading palette from file\n"); |
4332 | 635 for (i = start; i <= end; i++) |
636 { | |
637 entry = BE_16(&trak->stdata[hdr_ptr]); | |
638 hdr_ptr += 2; | |
639 // apparently, if count_flag is set, entry is same as i | |
640 if (count_flag & 0x8000) | |
641 entry = i; | |
642 // only care about top 8 bits of 16-bit R, G, or B value | |
4371 | 643 palette_map[entry * 4 + 2] = trak->stdata[hdr_ptr + 0]; |
4332 | 644 palette_map[entry * 4 + 1] = trak->stdata[hdr_ptr + 2]; |
4371 | 645 palette_map[entry * 4 + 0] = trak->stdata[hdr_ptr + 4]; |
4332 | 646 hdr_ptr += 6; |
647 } | |
4129
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
648 } |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
649 } |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
650 else |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
651 { |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
652 sh->bih=malloc(sizeof(BITMAPINFOHEADER)); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
653 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
654 sh->bih->biSize=40; |
31cd2e0bb961
QT demuxer loads palette information from files that transport palettes in
melanson
parents:
3999
diff
changeset
|
655 } |
2101 | 656 sh->bih->biWidth=sh->disp_w; |
657 sh->bih->biHeight=sh->disp_h; | |
658 sh->bih->biPlanes=0; | |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
659 sh->bih->biBitCount=depth; |
2101 | 660 sh->bih->biCompression=trak->fourcc; |
661 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight; | |
662 | |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
663 mp_msg(MSGT_DEMUX, MSGL_INFO, "Image size: %d x %d (%dbits)\n",sh->disp_w,sh->disp_h,sh->bih->biBitCount); |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
664 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43); |
2115 | 665 |
2101 | 666 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){ |
667 // (auto)selected video track: | |
668 demuxer->video->id=priv->track_db; | |
669 demuxer->video->sh=sh; sh->ds=demuxer->video; | |
670 } | |
2100 | 671 break; |
672 } | |
2786 | 673 case MOV_TRAK_GENERIC: |
674 mp_msg(MSGT_DEMUX, MSGL_INFO, "Generic track - not completly understood! (id: %d)\n", | |
675 trak->id); | |
3071 | 676 #warning "Also this contains the FLASH data" |
2786 | 677 #if 0 |
678 mp_msg(MSGT_DEMUX, MSGL_INFO, "Extracting samples to files (possibly this is an flash anim)\n"); | |
679 { | |
680 int pos = stream_tell(demuxer->stream); | |
681 int i; | |
682 int fd; | |
683 char name[20]; | |
684 | |
685 for (i=0; i<trak->samples_size; i++) | |
686 { | |
687 char buf[trak->samples[i].size]; | |
688 stream_seek(demuxer->stream, trak->samples[i].pos); | |
689 snprintf((char *)&name[0], 20, "samp%d", i); | |
690 fd = open((char *)&name[0], O_CREAT|O_WRONLY); | |
691 stream_read(demuxer->stream, &buf[0], trak->samples[i].size); | |
692 write(fd, &buf[0], trak->samples[i].size); | |
693 close(fd); | |
694 } | |
695 for (i=0; i<trak->chunks_size; i++) | |
696 { | |
697 char buf[trak->length]; | |
698 stream_seek(demuxer->stream, trak->chunks[i].pos); | |
699 snprintf((char *)&name[0], 20, "chunk%d", i); | |
700 fd = open((char *)&name[0], O_CREAT|O_WRONLY); | |
701 stream_read(demuxer->stream, &buf[0], trak->length); | |
702 write(fd, &buf[0], trak->length); | |
703 close(fd); | |
704 } | |
705 if (trak->samplesize > 0) | |
706 { | |
707 char *buf; | |
708 | |
709 buf = malloc(trak->samplesize); | |
710 stream_seek(demuxer->stream, trak->chunks[0].pos); | |
711 snprintf((char *)&name[0], 20, "trak%d", trak->id); | |
712 fd = open((char *)&name[0], O_CREAT|O_WRONLY); | |
713 stream_read(demuxer->stream, buf, trak->samplesize); | |
714 write(fd, buf, trak->samplesize); | |
715 close(fd); | |
716 } | |
717 stream_seek(demuxer->stream, pos); | |
718 } | |
719 #endif | |
720 break; | |
2532 | 721 default: |
722 mp_msg(MSGT_DEMUX, MSGL_INFO, "Unknown track type found (type: %d)\n", trak->type); | |
723 break; | |
2100 | 724 } |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
725 mp_msg(MSGT_DEMUX, MSGL_INFO, "--------------\n"); |
2100 | 726 priv->track_db++; |
1490 | 727 trak=NULL; |
2532 | 728 break; |
729 } | |
2148 | 730 #ifndef HAVE_ZLIB |
2532 | 731 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
|
732 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); |
1490 | 733 return; |
734 } | |
2148 | 735 #else |
2532 | 736 case MOV_FOURCC('c','m','o','v'): { |
2148 | 737 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); |
738 lschunks(demuxer,level+1,pos+len,NULL); | |
2532 | 739 break; |
740 } | |
741 case MOV_FOURCC('d','c','o','m'): { | |
2148 | 742 // int temp=stream_read_dword(demuxer->stream); |
2386 | 743 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
|
744 mp_msg(MSGT_DEMUX, MSGL_INFO, "Compressed header uses %.4s algo!\n",&len); |
2532 | 745 break; |
746 } | |
747 case MOV_FOURCC('c','m','v','d'): { | |
2148 | 748 // int temp=stream_read_dword(demuxer->stream); |
749 unsigned int moov_sz=stream_read_dword(demuxer->stream); | |
750 unsigned int cmov_sz=len-4; | |
751 unsigned char* cmov_buf=malloc(cmov_sz); | |
752 unsigned char* moov_buf=malloc(moov_sz+16); | |
753 int zret; | |
754 z_stream zstrm; | |
755 stream_t* backup; | |
756 | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
757 mp_msg(MSGT_DEMUX, MSGL_INFO, "Compressed header size: %d / %d\n",cmov_sz,moov_sz); |
2148 | 758 |
759 stream_read(demuxer->stream,cmov_buf,cmov_sz); | |
760 | |
761 zstrm.zalloc = (alloc_func)0; | |
762 zstrm.zfree = (free_func)0; | |
763 zstrm.opaque = (voidpf)0; | |
764 zstrm.next_in = cmov_buf; | |
765 zstrm.avail_in = cmov_sz; | |
766 zstrm.next_out = moov_buf; | |
767 zstrm.avail_out = moov_sz; | |
768 | |
769 zret = inflateInit(&zstrm); | |
770 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
|
771 { mp_msg(MSGT_DEMUX, MSGL_ERR, "QT cmov: inflateInit err %d\n",zret); |
2148 | 772 return; |
773 } | |
774 zret = inflate(&zstrm, Z_NO_FLUSH); | |
775 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
|
776 { mp_msg(MSGT_DEMUX, MSGL_ERR, "QT cmov inflate: ERR %d\n",zret); |
2148 | 777 return; |
778 } | |
779 #if 0 | |
780 else { | |
781 FILE *DecOut; | |
782 DecOut = fopen("Out.bin", "w"); | |
783 fwrite(moov_buf, 1, moov_sz, DecOut); | |
784 fclose(DecOut); | |
785 } | |
786 #endif | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
787 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
|
788 mp_msg(MSGT_DEMUX, MSGL_WARN, "Warning! moov size differs cmov: %d zlib: %d\n",moov_sz,zstrm.total_out); |
2148 | 789 zret = inflateEnd(&zstrm); |
790 | |
791 backup=demuxer->stream; | |
792 demuxer->stream=new_memory_stream(moov_buf,moov_sz); | |
793 stream_skip(demuxer->stream,8); | |
794 lschunks(demuxer,level+1,moov_sz,NULL); // parse uncompr. 'moov' | |
795 //free_stream(demuxer->stream); | |
796 demuxer->stream=backup; | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
797 free(cmov_buf); |
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
798 free(moov_buf); |
2532 | 799 break; |
2148 | 800 } |
801 #endif | |
2532 | 802 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
|
803 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
804 unsigned int udta_id; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
805 off_t udta_len; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
806 off_t udta_size = len; |
1490 | 807 |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
808 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
|
809 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
|
810 |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
811 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
|
812 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
813 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
|
814 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
|
815 udta_size -= 8; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
816 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
|
817 switch (udta_id) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
818 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
819 case MOV_FOURCC(0xa9,'c','p','y'): |
2542 | 820 case MOV_FOURCC(0xa9,'d','a','y'): |
821 case MOV_FOURCC(0xa9,'d','i','r'): | |
822 /* 0xa9,'e','d','1' - '9' : edit timestamps */ | |
823 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
|
824 case MOV_FOURCC(0xa9,'i','n','f'): |
2542 | 825 case MOV_FOURCC(0xa9,'p','r','d'): |
826 case MOV_FOURCC(0xa9,'p','r','f'): | |
827 case MOV_FOURCC(0xa9,'r','e','q'): | |
828 case MOV_FOURCC(0xa9,'s','r','c'): | |
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 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
|
835 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
836 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
|
837 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
|
838 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
|
839 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
|
840 switch(udta_id) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
841 { |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
842 case MOV_FOURCC(0xa9,'a','u','t'): |
3071 | 843 demux_info_add(demuxer, "author", &text[2]); |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
844 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
|
845 break; |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
846 case MOV_FOURCC(0xa9,'c','p','y'): |
3071 | 847 demux_info_add(demuxer, "copyright", &text[2]); |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
848 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
|
849 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
850 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
|
851 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
|
852 break; |
2542 | 853 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
|
854 case MOV_FOURCC(0xa9,'n','a','m'): |
3071 | 855 demux_info_add(demuxer, "name", &text[2]); |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
856 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
|
857 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
858 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
|
859 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
|
860 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
861 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
|
862 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
|
863 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
864 case MOV_FOURCC(0xa9,'c','m','t'): |
3071 | 865 demux_info_add(demuxer, "comments", &text[2]); |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
866 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
|
867 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
868 case MOV_FOURCC(0xa9,'r','e','q'): |
2542 | 869 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
|
870 break; |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
871 case MOV_FOURCC(0xa9,'s','w','r'): |
3071 | 872 demux_info_add(demuxer, "encoder", &text[2]); |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
873 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
|
874 break; |
2542 | 875 case MOV_FOURCC(0xa9,'d','a','y'): |
876 mp_msg(MSGT_DEMUX, MSGL_INFO, " Creation timestamp: %s\n", &text[2]); | |
877 break; | |
878 case MOV_FOURCC(0xa9,'f','m','t'): | |
879 mp_msg(MSGT_DEMUX, MSGL_INFO, " Format: %s\n", &text[2]); | |
880 break; | |
881 case MOV_FOURCC(0xa9,'p','r','d'): | |
882 mp_msg(MSGT_DEMUX, MSGL_INFO, " Producer: %s\n", &text[2]); | |
883 break; | |
884 case MOV_FOURCC(0xa9,'p','r','f'): | |
885 mp_msg(MSGT_DEMUX, MSGL_INFO, " Performer(s): %s\n", &text[2]); | |
886 break; | |
887 case MOV_FOURCC(0xa9,'s','r','c'): | |
888 mp_msg(MSGT_DEMUX, MSGL_INFO, " Source providers: %s\n", &text[2]); | |
889 break; | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
890 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
891 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
|
892 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
893 } |
2542 | 894 /* some other shits: WLOC - window location, |
895 LOOP - looping style, | |
896 SelO - play only selected frames | |
897 AllF - play all frames | |
898 */ | |
899 case MOV_FOURCC('W','L','O','C'): | |
900 case MOV_FOURCC('L','O','O','P'): | |
901 case MOV_FOURCC('S','e','l','O'): | |
902 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
|
903 default: |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
904 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
905 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
|
906 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
|
907 udta_size -= udta_len; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
908 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
909 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
910 } |
2532 | 911 break; |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
912 } /* eof udta */ |
2532 | 913 default: |
914 id = bswap_32(id); | |
915 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); | |
916 } /* endof switch */ | |
917 } /* endof else */ | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
918 |
1490 | 919 pos+=len+8; |
920 if(pos>=endpos) break; | |
921 if(!stream_seek(demuxer->stream,pos)) break; | |
922 } | |
923 } | |
924 | |
925 int mov_read_header(demuxer_t* demuxer){ | |
926 mov_priv_t* priv=demuxer->priv; | |
927 | |
2483
22bfa362af42
added two new clip info types, all printf's were upgraded to mp_msg
alex
parents:
2429
diff
changeset
|
928 mp_msg(MSGT_DEMUX, MSGL_DBG3, "mov_read_header!\n"); |
1490 | 929 |
930 // Parse header: | |
2100 | 931 stream_reset(demuxer->stream); |
1490 | 932 if(!stream_seek(demuxer->stream,priv->moov_start)) return 0; // ??? |
933 lschunks(demuxer, 0, priv->moov_end, NULL); | |
934 | |
2127 | 935 return 1; |
1490 | 936 } |
2101 | 937 |
938 // return value: | |
939 // 0 = EOF or no stream found | |
940 // 1 = successfully read a packet | |
941 int demux_mov_fill_buffer(demuxer_t *demuxer,demux_stream_t* ds){ | |
942 mov_priv_t* priv=demuxer->priv; | |
943 mov_track_t* trak=NULL; | |
944 float pts; | |
945 | |
946 if(ds->id<0 || ds->id>=priv->track_db) return 0; | |
947 trak=priv->tracks[ds->id]; | |
948 | |
2115 | 949 if(trak->samplesize){ |
950 // read chunk: | |
2419 | 951 int x; |
2115 | 952 if(trak->pos>=trak->chunks_size) return 0; // EOF |
953 stream_seek(demuxer->stream,trak->chunks[trak->pos].pos); | |
954 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
3071 | 955 if(trak->samplesize!=1) |
956 { | |
4645
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
957 mp_msg(MSGT_DEMUX, MSGL_DBG2, "WARNING! Samplesize(%d) != 1\n", |
3071 | 958 trak->samplesize); |
959 x=trak->chunks[trak->pos].size*trak->samplesize; | |
960 } | |
961 else | |
962 x=trak->chunks[trak->pos].size; | |
3652
65fd971932dc
added co64 (64bit chunk offset table) chunk (needed for mov files created with xawtv) and added depth detection in video track (tested with my *.mov files (about 15-20) and worked fine)
alex
parents:
3071
diff
changeset
|
963 // printf("X = %d\n", x); |
4645
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
964 /* the following stuff is audio related */ |
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
965 if (trak->type == MOV_TRAK_AUDIO) |
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
966 { |
4624 | 967 if(trak->stdata_len>=36 && trak->stdata[30] && trak->stdata[31]){ |
2543 | 968 // extended stsd header - works for CBR MP3: |
969 x/=(trak->stdata[30]<<8)+trak->stdata[31]; // samples/packet | |
970 // x*=(trak->stdata[34]<<8)+trak->stdata[35]; // bytes/packet | |
971 x*=(trak->stdata[38]<<8)+trak->stdata[39]; // bytes/frame | |
972 } else { | |
973 // works for ima4: -- we should find this info in mov headers! | |
2549 | 974 if(ds->ss_div!=1 || ds->ss_mul!=1){ |
975 x/=ds->ss_div; x*=ds->ss_mul; // compression ratio fix ! HACK ! | |
976 } else { | |
977 x*=(trak->stdata[18]<<8)+trak->stdata[19];x/=8; // bits/sample | |
978 } | |
2543 | 979 } |
4645
33c2fc18138c
added nmhd, added checking for audio trak in demux_mov_fill_buffer
alex
parents:
4624
diff
changeset
|
980 } /* MOV_TRAK_AUDIO */ |
2419 | 981 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
|
982 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 | 983 } else { |
2101 | 984 // read sample: |
985 if(trak->pos>=trak->samples_size) return 0; // EOF | |
986 stream_seek(demuxer->stream,trak->samples[trak->pos].pos); | |
987 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; | |
988 ds_read_packet(ds,demuxer->stream,trak->samples[trak->pos].size,pts,trak->samples[trak->pos].pos,0); | |
2115 | 989 } |
2101 | 990 ++trak->pos; |
2115 | 991 |
2101 | 992 return 1; |
993 | |
994 } | |
2227 | 995 |
996 static float mov_seek_track(mov_track_t* trak,float pts,int flags){ | |
997 | |
998 // printf("MOV track seek called %5.3f \n",pts); | |
999 if(flags&2) pts*=trak->length; else pts*=(float)trak->timescale; | |
1000 | |
1001 if(trak->samplesize){ | |
1002 int sample=pts/trak->duration; | |
1003 // printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration); | |
1004 if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative | |
1005 trak->pos=0; | |
1006 while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos; | |
1007 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
1008 } else { | |
2545 | 1009 unsigned int ipts; |
1010 if(!(flags&1)) pts+=trak->samples[trak->pos].pts; | |
1011 if(pts<0) pts=0; | |
1012 ipts=pts; | |
1013 //printf("MOV track seek - sample: %d \n",ipts); | |
2544 | 1014 for(trak->pos=0;trak->pos<trak->samples_size;++trak->pos){ |
1015 if(trak->samples[trak->pos].pts>=ipts) break; // found it! | |
1016 } | |
1017 if(trak->keyframes_size){ | |
1018 // find nearest keyframe | |
1019 int i; | |
1020 for(i=0;i<trak->keyframes_size;i++){ | |
1021 if(trak->keyframes[i]>=trak->pos) break; | |
1022 } | |
2546
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
1023 if(i>0 && (trak->keyframes[i]-trak->pos) > (trak->pos-trak->keyframes[i-1])) |
c9485365537d
added edit atom (edit list), some comments and typos fixes
alex
parents:
2545
diff
changeset
|
1024 --i; |
2544 | 1025 trak->pos=trak->keyframes[i]; |
1026 // printf("nearest keyframe: %d \n",trak->pos); | |
1027 } | |
2227 | 1028 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; |
1029 } | |
1030 | |
1031 // printf("MOV track seek done: %5.3f \n",pts); | |
1032 | |
1033 return pts; | |
1034 } | |
1035 | |
1036 void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){ | |
1037 mov_priv_t* priv=demuxer->priv; | |
1038 demux_stream_t* ds; | |
1039 | |
1040 // printf("MOV seek called %5.3f flag=%d \n",pts,flags); | |
1041 | |
1042 ds=demuxer->video; | |
1043 if(ds && ds->id>=0 && ds->id<priv->track_db){ | |
1044 mov_track_t* trak=priv->tracks[ds->id]; | |
1045 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; | |
1046 //if(!(flags&1)) pts+=ds->pts; | |
1047 pts=ds->pts=mov_seek_track(trak,pts,flags); | |
1048 flags=1; // absolute seconds | |
1049 } | |
1050 | |
1051 ds=demuxer->audio; | |
1052 if(ds && ds->id>=0 && ds->id<priv->track_db){ | |
1053 mov_track_t* trak=priv->tracks[ds->id]; | |
1054 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; | |
1055 //if(!(flags&1)) pts+=ds->pts; | |
1056 ds->pts=mov_seek_track(trak,pts,flags); | |
1057 } | |
1058 | |
1059 } | |
1060 |