comparison libmpdemux/demux_mov.c @ 5067:54fe37e1f1a7

some cleanup, fixes for video header parsing. finally we get the coded size instead of display size\!
author arpi
date Thu, 14 Mar 2002 02:26:49 +0000
parents d8b465e3fd88
children 3d558414320f
comparison
equal deleted inserted replaced
5066:b3d900e9a215 5067:54fe37e1f1a7
74 // 74 //
75 int tkdata_len; // track data 75 int tkdata_len; // track data
76 unsigned char* tkdata; 76 unsigned char* tkdata;
77 int stdata_len; // stream data 77 int stdata_len; // stream data
78 unsigned char* stdata; 78 unsigned char* stdata;
79 //
79 int samples_size; 80 int samples_size;
80 mov_sample_t* samples; 81 mov_sample_t* samples;
81 int chunks_size; 82 int chunks_size;
82 mov_chunk_t* chunks; 83 mov_chunk_t* chunks;
83 int chunkmap_size; 84 int chunkmap_size;
345 for(i=0;i<count;i++){ 346 for(i=0;i<count;i++){
346 off_t pos=stream_tell(demuxer->stream); 347 off_t pos=stream_tell(demuxer->stream);
347 off_t len=stream_read_dword(demuxer->stream); 348 off_t len=stream_read_dword(demuxer->stream);
348 unsigned int fourcc=stream_read_dword_le(demuxer->stream); 349 unsigned int fourcc=stream_read_dword_le(demuxer->stream);
349 if(len<8) break; // error 350 if(len<8) break; // error
350 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s desc #%d: %.4s",level,"",i,&fourcc); 351 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s desc #%d: %.4s (%d bytes)\n",level,"",i,&fourcc,len-16);
351 if(!i){ 352 if(!i){
352 trak->fourcc=fourcc; 353 trak->fourcc=fourcc;
353 // read codec data 354 // read type specific (audio/video/time/text etc) header
355 // NOTE: trak type is not yet known at this point :(((
354 trak->stdata_len=len-8; 356 trak->stdata_len=len-8;
355 trak->stdata=malloc(trak->stdata_len); 357 trak->stdata=malloc(trak->stdata_len);
356 stream_read(demuxer->stream,trak->stdata,trak->stdata_len); 358 stream_read(demuxer->stream,trak->stdata,trak->stdata_len);
357 if(trak->type==MOV_TRAK_VIDEO && trak->stdata_len>43){
358 mp_msg(MSGT_DEMUX,MSGL_V," '%.*s'",trak->stdata_len-43,trak->stdata+43);
359 }
360 } 359 }
361 mp_msg(MSGT_DEMUX,MSGL_V,"\n");
362 if(fourcc!=trak->fourcc && i) 360 if(fourcc!=trak->fourcc && i)
363 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC); 361 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC);
364 if(!stream_seek(demuxer->stream,pos+len)) break; 362 if(!stream_seek(demuxer->stream,pos+len)) break;
365 } 363 }
366 break; 364 break;
547 mov_build_index(trak); 545 mov_build_index(trak);
548 switch(trak->type){ 546 switch(trak->type){
549 case MOV_TRAK_AUDIO: { 547 case MOV_TRAK_AUDIO: {
550 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db); 548 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db);
551 sh->format=trak->fourcc; 549 sh->format=trak->fourcc;
550
551 // stdata[]:
552 // 8 short version
553 // 10 short revision
554 // 12 int vendor_id
555 // 16 short channels
556 // 18 short samplesize
557 // 20 short compression_id
558 // 22 short packet_size (==0)
559 // 24 int sample_rate
560 // ---- qt3.0+
561 // 28 int samples_per_packet
562 // 32 int bytes_per_packet
563 // 36 int bytes_per_frame
564 // 40 int bytes_per_sample
565
552 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio bits: %d chans: %d\n",trak->stdata[19],trak->stdata[17]); 566 mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio bits: %d chans: %d\n",trak->stdata[19],trak->stdata[17]);
553 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s\n",&trak->fourcc); 567 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s\n",&trak->fourcc);
554 #if 0 568 #if 0
555 { FILE* f=fopen("stdata.dat","wb"); 569 { FILE* f=fopen("stdata.dat","wb");
556 fwrite(trak->stdata,trak->stdata_len,1,f); 570 fwrite(trak->stdata,trak->stdata_len,1,f);
576 break; 590 break;
577 } 591 }
578 case MOV_TRAK_VIDEO: { 592 case MOV_TRAK_VIDEO: {
579 int i, entry; 593 int i, entry;
580 int flag, start, count_flag, end, palette_count; 594 int flag, start, count_flag, end, palette_count;
581 int hdr_ptr = 43+33; // the byte just after depth 595 int hdr_ptr = 76; // the byte just after depth
582 unsigned char *palette_map; 596 unsigned char *palette_map;
583 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); 597 sh_video_t* sh=new_sh_video(demuxer,priv->track_db);
584 int depth = trak->stdata[43+32]; /* requested by Mike Melanson for Apple RLE decoder -- alex */ 598 int depth = trak->stdata[75]|(trak->stdata[74]<<8);
585 sh->format=trak->fourcc; 599 sh->format=trak->fourcc;
600
601 // stdata[]:
602 // 8 short version
603 // 10 short revision
604 // 12 int vendor_id
605 // 16 int temporal_quality
606 // 20 int spatial_quality
607 // 24 short width
608 // 26 short height
609 // 28 int h_dpi
610 // 32 int v_dpi
611 // 36 int 0
612 // 40 short frames_per_sample
613 // 42 char[32] compressor_name
614 // 74 short depth
615 // 76 short color_table_id
616
586 if(!sh->fps) sh->fps=trak->timescale; 617 if(!sh->fps) sh->fps=trak->timescale;
587 sh->frametime=1.0f/sh->fps; 618 sh->frametime=1.0f/sh->fps;
619 #if 0
588 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8); 620 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8);
589 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); 621 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8);
622 #else
623 sh->disp_w=trak->stdata[25]|(trak->stdata[24]<<8);
624 sh->disp_h=trak->stdata[27]|(trak->stdata[26]<<8);
625 #endif
626
627 if(depth&(~15)) printf("*** depht = 0x%X\n",depth);
590 628
591 // palettized? 629 // palettized?
592 if ((depth == 2) || (depth == 4) || (depth == 8) || 630 depth&=31; // flag 32 means grayscale
593 (depth == 34) || (depth == 36) || (depth == 40)) 631 if ((depth == 2) || (depth == 4) || (depth == 8))
594 palette_count = (1 << (depth & 0x0F)); 632 palette_count = (1 << depth);
595 else 633 else
596 palette_count = 0; 634 palette_count = 0;
597 635
598 // emulate BITMAPINFOHEADER: 636 // emulate BITMAPINFOHEADER:
599 if (palette_count) 637 if (palette_count)
653 sh->bih->biPlanes=0; 691 sh->bih->biPlanes=0;
654 sh->bih->biBitCount=depth; 692 sh->bih->biBitCount=depth;
655 sh->bih->biCompression=trak->fourcc; 693 sh->bih->biCompression=trak->fourcc;
656 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight; 694 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight;
657 695
658 mp_msg(MSGT_DEMUX, MSGL_INFO, "Image size: %d x %d (%dbits)\n",sh->disp_w,sh->disp_h,sh->bih->biBitCount); 696 mp_msg(MSGT_DEMUX, MSGL_INFO, "Image size: %d x %d (%d bpp)\n",sh->disp_w,sh->disp_h,sh->bih->biBitCount);
659 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43); 697 if(trak->tkdata_len>81)
698 mp_msg(MSGT_DEMUX, MSGL_INFO, "Display size: %d x %d\n",
699 trak->tkdata[77]|(trak->tkdata[76]<<8),
700 trak->tkdata[81]|(trak->tkdata[80]<<8));
701 mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata[42]&31,trak->stdata+43);
660 702
661 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){ 703 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){
662 // (auto)selected video track: 704 // (auto)selected video track:
663 demuxer->video->id=priv->track_db; 705 demuxer->video->id=priv->track_db;
664 demuxer->video->sh=sh; sh->ds=demuxer->video; 706 demuxer->video->sh=sh; sh->ds=demuxer->video;