avi->stream_index= -1;
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags){    AVIContext *avi = s->priv_data;    AVStream *st;    int i, index;    int64_t pos;    if (!avi->index_loaded) {        /* we only load the index on demand */        avi_load_index(s);        avi->index_loaded = 1;    }    assert(stream_index>= 0);    st = s->streams[stream_index];    index= av_index_search_timestamp(st, timestamp, flags);    if(index<0)        return -1;        /* find the position */    pos = st->index_entries[index].pos;    timestamp = st->index_entries[index].timestamp;//    av_log(NULL, AV_LOG_DEBUG, "XX %Ld %d %Ld\n", timestamp, index, st->index_entries[index].timestamp);    for(i = 0; i < s->nb_streams; i++) {        AVStream *st2 = s->streams[i];        AVIStream *ast2 = st2->priv_data;        if (st2->nb_index_entries <= 0)            continue;        //        assert(st2->codec.block_align);        assert(st2->time_base.den == ast2->rate);        assert(st2->time_base.num == ast2->scale);        index = av_index_search_timestamp(                st2,                 av_rescale(timestamp, st2->time_base.den*(int64_t)st->time_base.num, st->time_base.den * (int64_t)st2->time_base.num),                flags | AVSEEK_FLAG_BACKWARD);        if(index<0)            index=0;#if 1        while(index>0 && st2->index_entries[index].pos > pos)            index--;        while(index+1 < st2->nb_index_entries && st2->index_entries[index].pos < pos)            index++;#endif//        av_log(NULL, AV_LOG_DEBUG, "%Ld %d %Ld\n", timestamp, index, st2->index_entries[index].timestamp);        /* extract the current frame number */        ast2->frame_offset = st2->index_entries[index].timestamp;        if(ast2->sample_size)            ast2->frame_offset *=ast2->sample_size;    }    if (avi->dv_demux)        dv_flush_audio_packets(avi->dv_demux);    /* do the seek */    pos += avi->movi_list;    url_fseek(&s->pb, pos, SEEK_SET);    return 0;}