comparison libmpdemux/demux_mov.c @ 5242:d4ffcbe9ed3d

Recognize and skip ftype chunk used by some .mp4 files and add fallback to displaysize if imagesize is unavailable. Also update some doc info.
author atmos4
date Thu, 21 Mar 2002 16:42:58 +0000
parents 126d5fd76a70
children 34c706ab6f6f
comparison
equal deleted inserted replaced
5241:126d5fd76a70 5242:d4ffcbe9ed3d
2 // additional work by Atmos 2 // additional work by Atmos
3 // based on TOOLS/movinfo.c by A'rpi & Al3x 3 // based on TOOLS/movinfo.c by A'rpi & Al3x
4 // compressed header support from moov.c of the openquicktime lib. 4 // compressed header support from moov.c of the openquicktime lib.
5 // References: http://openquicktime.sf.net/, http://www.heroinewarrior.com/ 5 // References: http://openquicktime.sf.net/, http://www.heroinewarrior.com/
6 // http://www.geocities.com/SiliconValley/Lakes/2160/fformats/files/mov.pdf 6 // http://www.geocities.com/SiliconValley/Lakes/2160/fformats/files/mov.pdf
7 // The QuickTime File Format PDF (QTFileFormat.pdf) from Apple: 7 // (above url no longer works, file mirrored somewhere? ::atmos)
8 // http://developer.apple.com/quicktime/ 8 // The QuickTime File Format PDF from Apple:
9 // http://developer.apple.com/techpubs/quicktime/qtdevdocs/PDF/QTFileFormat.pdf
10 // (Complete list of documentation at http://developer.apple.com/quicktime/)
11 // MP4-Lib sources from http://mpeg4ip.sf.net/ might be usefull fot .mp4
12 // aswell as .mov specific stuff.
9 13
10 #include <stdio.h> 14 #include <stdio.h>
11 #include <stdlib.h> 15 #include <stdlib.h>
12 #include <unistd.h> 16 #include <unistd.h>
13 17
231 } 235 }
232 #if 0 236 #if 0
233 else if (len == 0) /* deleted chunk */ 237 else if (len == 0) /* deleted chunk */
234 { 238 {
235 /* XXX: CJB! is this right? - alex */ 239 /* XXX: CJB! is this right? - alex */
236 goto skip_chunk; 240 break; // skip chunk
237 } 241 }
238 #endif 242 #endif
239 else if(len<8) break; // invalid chunk 243 else if(len<8) break; // invalid chunk
240 244
241 switch(id){ 245 switch(id){
246 case MOV_FOURCC('f','t','y','p'):
247 // skip over the file type chunk
248 // Here are my guesses on it's format (atmos):
249 // char[4] majorBrand (eg. 'isom')
250 // int minorVersion (eg. 0x00000000)
251 // char[4] mediaType(?) (eg. 'mp41')
252 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Skipping unsupported Filetype chunk (len: %d)!\n",
253 len);
254 break;
242 case MOV_FOURCC('m','o','o','v'): 255 case MOV_FOURCC('m','o','o','v'):
243 // case MOV_FOURCC('c','m','o','v'): 256 // case MOV_FOURCC('c','m','o','v'):
244 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n"); 257 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n");
245 priv->moov_start=(off_t)stream_tell(demuxer->stream); 258 priv->moov_start=(off_t)stream_tell(demuxer->stream);
246 priv->moov_end=(off_t)priv->moov_start+len-skipped; 259 priv->moov_end=(off_t)priv->moov_start+len-skipped;
266 default: 279 default:
267 if(no==0) return 0; // first chunk is bad! 280 if(no==0) return 0; // first chunk is bad!
268 id = be2me_32(id); 281 id = be2me_32(id);
269 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); 282 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len);
270 } 283 }
271 skip_chunk:
272 if(!stream_skip(demuxer->stream,len-skipped)) break; 284 if(!stream_skip(demuxer->stream,len-skipped)) break;
273 ++no; 285 ++no;
274 } 286 }
275 287
276 if(flags==1) 288 if(flags==1)
655 sh->samplerate/*char2short(trak->stdata,24)*/); 667 sh->samplerate/*char2short(trak->stdata,24)*/);
656 if((trak->stdata[9]==0) && trak->stdata_len >= 36) { // version 0 with extra atoms 668 if((trak->stdata[9]==0) && trak->stdata_len >= 36) { // version 0 with extra atoms
657 int atom_len = char2int(trak->stdata,28); 669 int atom_len = char2int(trak->stdata,28);
658 switch(char2int(trak->stdata,32)) { // atom type 670 switch(char2int(trak->stdata,32)) { // atom type
659 case MOV_FOURCC('e','s','d','s'): 671 case MOV_FOURCC('e','s','d','s'):
660 mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found MPEG4 esds audio atom (%d)!\n", atom_len); 672 mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found MPEG4 audio Elementary Stream Descriptor atom (%d)!\n", atom_len);
661 if(atom_len >= 28) 673 if(atom_len >= 28)
662 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio compressed datarate: %dkbit/s\n", 674 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio compressed datarate: %dkbit/s\n",
663 char2int(trak->stdata,62)/1000); 675 char2int(trak->stdata,62)/1000);
664 sh->i_bps=char2int(trak->stdata,62)/8; 676 sh->i_bps=char2int(trak->stdata,62)/8;
665 break; 677 break;
753 // Motion-JPEG default huffman table 765 // Motion-JPEG default huffman table
754 mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found unsupported MJPEG-Huffman movie atom (%d)!\n", 766 mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found unsupported MJPEG-Huffman movie atom (%d)!\n",
755 atom_len); 767 atom_len);
756 break; 768 break;
757 case MOV_FOURCC('e','s','d','s'): 769 case MOV_FOURCC('e','s','d','s'):
758 // MPEG4 esds header 770 // MPEG4 Elementary Stream Descriptor header
759 mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found MPEG4 esds movie atom (%d)!\n", atom_len); 771 mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found MPEG4 movie Elementary Stream Descriptor atom (%d)!\n", atom_len);
760 // add code here to save esds header of length atom_len-8 772 // add code here to save esds header of length atom_len-8
761 // beginning at stdata[86] to some variable to pass it 773 // beginning at stdata[86] to some variable to pass it
762 // on to the decoder ::atmos 774 // on to the decoder ::atmos
763 break; 775 break;
764 default: 776 default:
767 atom_len); 779 atom_len);
768 } 780 }
769 } 781 }
770 if(!sh->fps) sh->fps=trak->timescale; 782 if(!sh->fps) sh->fps=trak->timescale;
771 sh->frametime=1.0f/sh->fps; 783 sh->frametime=1.0f/sh->fps;
772 #if 0 784
773 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8);
774 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8);
775 #else
776 sh->disp_w=trak->stdata[25]|(trak->stdata[24]<<8); 785 sh->disp_w=trak->stdata[25]|(trak->stdata[24]<<8);
777 sh->disp_h=trak->stdata[27]|(trak->stdata[26]<<8); 786 sh->disp_h=trak->stdata[27]|(trak->stdata[26]<<8);
778 #endif 787 // if image size is zero, fallback to display size
788 if(!sh->disp_w && !sh->disp_h) {
789 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8);
790 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8);
791 }
779 792
780 if(depth&(~15)) printf("*** depht = 0x%X\n",depth); 793 if(depth&(~15)) printf("*** depht = 0x%X\n",depth);
781 794
782 // palettized? 795 // palettized?
783 depth&=31; // flag 32 means grayscale 796 depth&=31; // flag 32 means grayscale