1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 17:12:36 +00:00

seeking in raw/broken avi files (rebuilding index chunk)

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@565 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
arpi_esp 2001-04-21 20:44:41 +00:00
parent d09bcd1c65
commit 4307f59b9c
2 changed files with 42 additions and 4 deletions

View File

@ -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 @@ while(1){
}
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 @@ while(1){
}
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

View File

@ -475,7 +475,7 @@ int vcd_track=0;
#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 @@ d_dvdsub=demuxer->sub;
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;