comparison libmpdemux/demux_mov.c @ 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)
author alex
date Sat, 22 Dec 2001 00:33:35 +0000
parents a5f378f982cc
children 3c6b061ec033
comparison
equal deleted inserted replaced
3651:8148193fee93 3652:65fd971932dc
78 78
79 void mov_build_index(mov_track_t* trak){ 79 void mov_build_index(mov_track_t* trak){
80 int i,j,s; 80 int i,j,s;
81 int last=trak->chunks_size; 81 int last=trak->chunks_size;
82 unsigned int pts=0; 82 unsigned int pts=0;
83
84 #if 0
85 if (trak->chunks_size <= 0)
86 {
87 mp_msg(MSGT_DEMUX, MSGL_WARN, "No chunk offset table, trying to build one!\n");
88
89 trak->chunks_size = trak->samples_size;
90 trak->chunks = realloc(trak->chunks, sizeof(mov_chunk_t)*trak->chunks_size);
91
92 for (i=0; i < trak->chunks_size; i++)
93 trak->chunks[i].pos = -1;
94 }
95 #endif
96
83 mp_msg(MSGT_DEMUX, MSGL_HINT, "MOV track: %d chunks, %d samples\n",trak->chunks_size,trak->samples_size); 97 mp_msg(MSGT_DEMUX, MSGL_HINT, "MOV track: %d chunks, %d samples\n",trak->chunks_size,trak->samples_size);
84 mp_msg(MSGT_DEMUX, MSGL_HINT, "pts=%d scale=%d time=%5.3f\n",trak->length,trak->timescale,(float)trak->length/(float)trak->timescale); 98 mp_msg(MSGT_DEMUX, MSGL_HINT, "pts=%d scale=%d time=%5.3f\n",trak->length,trak->timescale,(float)trak->length/(float)trak->timescale);
85 99
86 // process chunkmap: 100 // process chunkmap:
87 i=trak->chunkmap_size; 101 i=trak->chunkmap_size;
91 trak->chunks[j].desc=trak->chunkmap[i].sdid; 105 trak->chunks[j].desc=trak->chunkmap[i].sdid;
92 trak->chunks[j].size=trak->chunkmap[i].spc; 106 trak->chunks[j].size=trak->chunkmap[i].spc;
93 } 107 }
94 last=trak->chunkmap[i].first; 108 last=trak->chunkmap[i].first;
95 } 109 }
110
111 #if 0
112 for (i=0; i < trak->chunks_size; i++)
113 {
114 /* fixup position */
115 if (trak->chunks[i].pos == -1)
116 if (i > 0)
117 trak->chunks[i].pos = trak->chunks[i-1].pos + trak->chunks[i-1].size;
118 else
119 trak->chunks[i].pos = 0; /* FIXME: set initial pos */
120 }
121 #endif
96 122
97 // calc pts of chunks: 123 // calc pts of chunks:
98 s=0; 124 s=0;
99 for(j=0;j<trak->chunks_size;j++){ 125 for(j=0;j<trak->chunks_size;j++){
100 trak->chunks[j].sample=s; 126 trak->chunks[j].sample=s;
388 } 414 }
389 // read elements: 415 // read elements:
390 for(i=0;i<len;i++) trak->chunks[i].pos=stream_read_dword(demuxer->stream); 416 for(i=0;i<len;i++) trak->chunks[i].pos=stream_read_dword(demuxer->stream);
391 break; 417 break;
392 } 418 }
419 case MOV_FOURCC('c','o','6','4'): {
420 int temp=stream_read_dword(demuxer->stream);
421 int len=stream_read_dword(demuxer->stream);
422 int i;
423 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s64bit chunk offset table! (%d chunks)\n",level,"",len);
424 // extend array if needed:
425 if(len>trak->chunks_size){
426 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len);
427 trak->chunks_size=len;
428 }
429 // read elements:
430 for(i=0;i<len;i++)
431 {
432 int len1=stream_read_dword(demuxer->stream);
433 int len2=stream_read_dword(demuxer->stream);
434
435 mp_msg(MSGT_DEMUX, MSGL_DBG3, "Chunk #%d: len1=%d, len2=%d\n", i, len1, len2);
436
437 #ifndef _LARGEFILE_SOURCE /* is this right ?! -- alex */
438 if (len1)
439 mp_msg(MSGT_DEMUX, MSGL_WARN, "Chunk %d has got 64bit address, but you've MPlayer compiled without LARGEFILE support!\n", i);
440 trak->chunks[i].pos = len2;
441 #else
442 trak->chunks[i].pos = len1+len2; /* also off_t pos -> on 64bit platform off_t MUST be 64bit */
443 #endif
444 }
445 break;
446 }
393 case MOV_FOURCC('s','t','s','s'): { 447 case MOV_FOURCC('s','t','s','s'): {
394 int temp=stream_read_dword(demuxer->stream); 448 int temp=stream_read_dword(demuxer->stream);
395 int entries=stream_read_dword(demuxer->stream); 449 int entries=stream_read_dword(demuxer->stream);
396 int ver = (temp << 24); 450 int ver = (temp << 24);
397 int flags = (temp << 16)|(temp<<8)|temp; 451 int flags = (temp << 16)|(temp<<8)|temp;
499 } 553 }
500 break; 554 break;
501 } 555 }
502 case MOV_TRAK_VIDEO: { 556 case MOV_TRAK_VIDEO: {
503 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); 557 sh_video_t* sh=new_sh_video(demuxer,priv->track_db);
558 int depth = trak->stdata[43+32]; /* requested by Mike Melanson for Apple RLE decoder -- alex */
504 sh->format=trak->fourcc; 559 sh->format=trak->fourcc;
505 if(!sh->fps) sh->fps=trak->timescale; 560 if(!sh->fps) sh->fps=trak->timescale;
506 sh->frametime=1.0f/sh->fps; 561 sh->frametime=1.0f/sh->fps;
507 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8); 562 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8);
508 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); 563 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8);
512 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); 567 memset(sh->bih,0,sizeof(BITMAPINFOHEADER));
513 sh->bih->biSize=40; 568 sh->bih->biSize=40;
514 sh->bih->biWidth=sh->disp_w; 569 sh->bih->biWidth=sh->disp_w;
515 sh->bih->biHeight=sh->disp_h; 570 sh->bih->biHeight=sh->disp_h;
516 sh->bih->biPlanes=0; 571 sh->bih->biPlanes=0;
517 sh->bih->biBitCount=16; 572 sh->bih->biBitCount=depth;
518 sh->bih->biCompression=trak->fourcc; 573 sh->bih->biCompression=trak->fourcc;
519 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight; 574 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight;
520 575
521 mp_msg(MSGT_DEMUX, MSGL_INFO, "Image size: %d x %d\n",sh->disp_w,sh->disp_h); 576 mp_msg(MSGT_DEMUX, MSGL_INFO, "Image size: %d x %d (%dbits)\n",sh->disp_w,sh->disp_h,sh->bih->biBitCount);
522 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43); 577 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43);
523 578
524 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){ 579 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){
525 // (auto)selected video track: 580 // (auto)selected video track:
526 demuxer->video->id=priv->track_db; 581 demuxer->video->id=priv->track_db;
816 trak->samplesize); 871 trak->samplesize);
817 x=trak->chunks[trak->pos].size*trak->samplesize; 872 x=trak->chunks[trak->pos].size*trak->samplesize;
818 } 873 }
819 else 874 else
820 x=trak->chunks[trak->pos].size; 875 x=trak->chunks[trak->pos].size;
821 printf("X = %d\n", x); 876 // printf("X = %d\n", x);
822 if(trak->stdata_len>=36){ 877 if(trak->stdata_len>=36){
823 // extended stsd header - works for CBR MP3: 878 // extended stsd header - works for CBR MP3:
824 x/=(trak->stdata[30]<<8)+trak->stdata[31]; // samples/packet 879 x/=(trak->stdata[30]<<8)+trak->stdata[31]; // samples/packet
825 // x*=(trak->stdata[34]<<8)+trak->stdata[35]; // bytes/packet 880 // x*=(trak->stdata[34]<<8)+trak->stdata[35]; // bytes/packet
826 x*=(trak->stdata[38]<<8)+trak->stdata[39]; // bytes/frame 881 x*=(trak->stdata[38]<<8)+trak->stdata[39]; // bytes/frame