--- main.orig/mplayer.h 2003-04-07 12:03:37.000000000 -0400 +++ main/mplayer.h 2003-10-12 12:31:07.000000000 -0400 @@ -43,6 +43,7 @@ extern int stream_cache_size; extern int force_ni; extern int index_mode; +extern char *index_file; extern int autosync; // libmpcodecs: --- main.orig/cfg-common.h 2003-09-05 20:23:44.000000000 -0400 +++ main/cfg-common.h 2003-10-12 12:31:07.000000000 -0400 @@ -74,6 +74,8 @@ {"noidx", &index_mode, CONF_TYPE_FLAG, 0, -1, 0, NULL}, {"idx", &index_mode, CONF_TYPE_FLAG, 0, -1, 1, NULL}, {"forceidx", &index_mode, CONF_TYPE_FLAG, 0, -1, 2, NULL}, + {"saveidx", &index_mode, CONF_TYPE_FLAG, 0, -1, 3, NULL}, + {"idxfile", &index_file, CONF_TYPE_STRING, 0, 0, 0, NULL }, // select audio/videosubtitle stream {"aid", &audio_id, CONF_TYPE_INT, CONF_RANGE, 0, 8192, NULL}, --- main.orig/libmpdemux/demuxer.h 2003-08-29 04:03:56.000000000 -0400 +++ main/libmpdemux/demuxer.h 2003-10-12 12:31:07.000000000 -0400 @@ -265,6 +265,7 @@ // AVI demuxer params: extern int index_mode; // -1=untouched 0=don't use index 1=use (geneate) index +extern char *index_file; extern int force_ni; extern int pts_from_bps; --- main.orig/libmpdemux/demux_avi.c 2003-08-27 18:30:54.000000000 -0400 +++ main/libmpdemux/demux_avi.c 2003-10-12 12:31:07.000000000 -0400 @@ -425,6 +425,7 @@ // AVI demuxer parameters: int index_mode=-1; // -1=untouched 0=don't use index 1=use (geneate) index +char *index_file=NULL; int force_ni=0; // force non-interleaved AVI parsing void read_avi_header(demuxer_t *demuxer,int index_mode); --- main.orig/libmpdemux/aviheader.c 2002-11-01 12:46:43.000000000 -0500 +++ main/libmpdemux/aviheader.c 2003-10-12 22:43:34.000000000 -0400 @@ -2,6 +2,7 @@ #include #include #include +#include #include "config.h" #include "mp_msg.h" @@ -299,7 +300,42 @@ } -if(index_mode>=2 || (priv->idx_size==0 && index_mode==1)){ +/* Read a saved index file */ +if (index_mode != 3 && index_file) { + FILE *fp; + char magic[6]; + unsigned int i; + + if ((fp = fopen(index_file, "r")) == NULL) { + mp_msg(MSGT_HEADER,MSGL_ERR, "** Can't read index file %s: %s\n", index_file, strerror(errno)); + return; + } + fread(&magic, 5, 1, fp); + if (strncmp(magic, "MPIDX", 5)) { + mp_msg(MSGT_HEADER,MSGL_ERR, "** %s is not a valid MPlayer index file\n", index_file); + return; + } + fread(&priv->idx_size, sizeof(priv->idx_size), 1, fp); + priv->idx=malloc(priv->idx_size*sizeof(AVIINDEXENTRY)); + if (!priv->idx) { + mp_msg(MSGT_HEADER,MSGL_ERR, "** Could not allocate memory for index data from %s\n", index_file); + priv->idx_size = 0; + return; + } + + for (i=0; iidx_size;i++) { + AVIINDEXENTRY *idx; + idx=&((AVIINDEXENTRY *)priv->idx)[i]; + fread(idx, sizeof(AVIINDEXENTRY), 1, fp); + if (feof(fp)) { + mp_msg(MSGT_HEADER,MSGL_ERR, "** Premature end of index file %s\n", index_file); + free(priv->idx); + priv->idx_size = 0; + return; + } + } + fclose(fp); +} else if(index_mode>=2 || (priv->idx_size==0 && index_mode==1)){ // build index for file: stream_reset(demuxer->stream); stream_seek(demuxer->stream,demuxer->movi_start); @@ -381,8 +417,32 @@ priv->idx_size=priv->idx_pos; mp_msg(MSGT_HEADER,MSGL_INFO,"AVI: Generated index table for %d chunks!\n",priv->idx_size); if(verbose>=2) print_index(priv->idx,priv->idx_size); -} + /* Write generated index to a file */ + if (index_mode == 3) { + FILE *fp; + unsigned int i; + + if (!index_file) { + mp_msg(MSGT_HEADER,MSGL_ERR, "** Need to specify -idxfile when using -saveidx\n"); + return; + } + if ((fp=fopen(index_file, "w")) == NULL) { + mp_msg(MSGT_HEADER,MSGL_ERR, "** Couldn't write index file %s: %s\n", index_file, strerror(errno)); + return; + } + fwrite("MPIDX", 5, 1, fp); + fwrite(&priv->idx_size, sizeof(priv->idx_size), 1, fp); + for (i=0; iidx_size; i++) { + AVIINDEXENTRY *idx = &((AVIINDEXENTRY *)priv->idx)[i]; + fwrite(idx, sizeof(AVIINDEXENTRY), 1, fp); + } + fclose(fp); + mp_msg(MSGT_HEADER,MSGL_INFO, "Saved index file: %s\n", index_file); + return; + } + +} } #undef MIN --- main.orig/DOCS/en/mplayer.1 2003-10-08 14:38:23.000000000 -0400 +++ main/DOCS/en/mplayer.1 2003-10-12 22:08:53.000000000 -0400 @@ -768,6 +768,16 @@ You can only use this option if the underlying media supports seeking (i.e. not with stdin, pipe, etc). .TP +.B \-idxfile +The file name written to or read from for the INDEX data. When +specified in conjunction with -saveidx, MPlayer will force generation of +the AVI index and write it to filename. When -saveidx is not specified +on the command line, MPlayer will read the index from filename and use +this data for seeking. This data will override any index data contained +in the AVI itself. Further, MPlayer won't prevent you from loading an +index file generated from a different AVI, but this is sure to cause +unfavorable results. +.TP .B \-ipv4-only-proxy Skip the proxy for IPv6 addresses. It will still be used for IPv4 connections. @@ -875,6 +885,18 @@ This option may be useful if you have a broken Internet connection that does not pass incoming UDP packets (see http://www.live.com/mplayer/). .TP +.B \-saveidx +Force rebuilding of INDEX and output to a separate file specified with +-idxfile. Currently this only works with AVI files. Although you can +use MEncoder to fix files without indexes, MPlayer does not support +seeking in AVI files bigger than 2G. (This is a limitation of the AVI +format, and although there exists an extension to index beyond 2G, +MPlayer doesn't support this extension.) After the index file is +created, MPlayer will begin to play the video. If you want to automate +index file generation (after encoding a large file off a TV capture +card, for example), you can specify -frames 0 to prevent MPlayer from +playing the video after generating the index. +.TP .B \-sb (see \-ss option too) Seek to byte position. Useful for playback from CDROM images / .VOB files with junk at the beginning.