Mercurial > mplayer.hg
changeset 564:747759a4a28f
seeking in raw/broken avi files (rebuilding index chunk)
author | arpi_esp |
---|---|
date | Sat, 21 Apr 2001 20:44:41 +0000 |
parents | 5eb28ba8a96a |
children | 6e747808386e |
files | aviheader.c mplayer.c |
diffstat | 2 files changed, 42 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/aviheader.c Sat Apr 21 20:43:59 2001 +0000 +++ b/aviheader.c Sat Apr 21 20:44:41 2001 +0000 @@ -1,7 +1,7 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) -void read_avi_header(int no_index){ +void read_avi_header(int index_mode){ sh_audio_t *sh_audio=NULL; sh_video_t *sh_video=NULL; int stream_id=-1; @@ -76,7 +76,7 @@ } break; } - case ckidAVINEWINDEX: if(!no_index){ + case ckidAVINEWINDEX: if(index_mode){ avi_header.idx_size=size2>>4; if(verbose>=1) printf("Reading INDEX block, %d chunks for %d frames\n", avi_header.idx_size,avi_header.avih.dwTotalFrames); @@ -92,6 +92,44 @@ } +if(avi_header.idx_size==0 && index_mode==1){ + // build index for file: + stream_reset(demuxer->stream); + stream_seek(demuxer->stream,avi_header.movi_start); + + avi_header.idx_pos=0; + avi_header.idx=NULL; + + while(1){ + int id,len,skip; + AVIINDEXENTRY* idx; + demuxer->filepos=stream_tell(demuxer->stream); + if(demuxer->filepos>=avi_header.movi_end) break; + id=stream_read_dword_le(demuxer->stream); + len=stream_read_dword_le(demuxer->stream); + if(id==mmioFOURCC('L','I','S','T')){ + id=stream_read_dword_le(demuxer->stream); // list type + continue; + } + if(stream_eof(demuxer->stream)) break; + if(avi_header.idx_pos<=avi_header.idx_size){ + avi_header.idx_size+=32; + avi_header.idx=realloc(avi_header.idx,avi_header.idx_size*sizeof(AVIINDEXENTRY)); + if(!avi_header.idx){avi_header.idx_pos=0; break;} // error! + } + idx=&avi_header.idx[avi_header.idx_pos++]; + idx->ckid=id; + idx->dwFlags=AVIIF_KEYFRAME; // FIXME + idx->dwChunkOffset=demuxer->filepos; + idx->dwChunkLength=len; + if(verbose>=2) printf("0x%08X 0x%08X %.4s\n",demuxer->filepos,id,&id); + skip=(len+1)&(~1); // total bytes in this chunk + stream_skip(demuxer->stream,skip); + } + avi_header.idx_size=avi_header.idx_pos; + printf("AVI: Generated index table for %d chunks!\n",avi_header.idx_size); +} + } #undef MIN
--- a/mplayer.c Sat Apr 21 20:43:59 2001 +0000 +++ b/mplayer.c Sat Apr 21 20:44:41 2001 +0000 @@ -475,7 +475,7 @@ #ifdef VCD_CACHE int vcd_cache_size=128; #endif -int no_index=0; +int index_mode=-1; // -1=untouched 0=don't use index 1=use (geneate) index #ifdef AVI_SYNC_BPS int pts_from_bps=1; #else @@ -720,7 +720,7 @@ switch(file_format){ case DEMUXER_TYPE_AVI: { //---- AVI header: - read_avi_header(no_index); + read_avi_header(index_mode); stream_reset(demuxer->stream); stream_seek(demuxer->stream,avi_header.movi_start); avi_header.idx_pos=0;