diff --git a/libavformat/asf.c b/libavformat/asf.c index e22e6e3940..29af3172a4 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -813,7 +813,7 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, assert((asf_st->packet_pos - s->data_offset) % asf->packet_size == 0); pos= asf_st->packet_pos; - av_add_index_entry(s->streams[i], pos, pts, pos - start_pos[i] + 1, AVINDEX_KEYFRAME); + av_add_index_entry(s->streams[i], pos, pkt->size, pts, pos - start_pos[i] + 1, AVINDEX_KEYFRAME); start_pos[i]= asf_st->packet_pos + 1; if(pkt->stream_index == stream_index) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 8786d62f22..f95462eb62 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -208,8 +208,8 @@ typedef struct AVIndexEntry { int64_t pos; int64_t timestamp; #define AVINDEX_KEYFRAME 0x0001 -/* the following 2 flags indicate that the next/prev keyframe is known, and scaning for it isnt needed */ - int flags; + int flags:2; + int size:30; //yeah trying to keep the size of this small to reduce memory requirements (its 24 vs 32 byte due to possible 8byte align) int min_distance; /* min distance between this and the previous keyframe, used to avoid unneeded searching */ } AVIndexEntry; @@ -641,7 +641,7 @@ void av_set_pts_info(AVStream *s, int pts_wrap_bits, int av_find_default_stream_index(AVFormatContext *s); int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags); int av_add_index_entry(AVStream *st, - int64_t pos, int64_t timestamp, int distance, int flags); + int64_t pos, int64_t timestamp, int size, int distance, int flags); int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags); /* media file output */ diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 86e2e9244a..2fede84528 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -55,6 +55,7 @@ typedef struct { } AVIContext; static int avi_load_index(AVFormatContext *s); +static int guess_ni_flag(AVFormatContext *s); #ifdef DEBUG static void print_tag(const char *str, unsigned int tag, int size) @@ -118,12 +119,14 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ for(i=0; icum_len, 0, (len<0) ? 0 : AVINDEX_KEYFRAME); + int key= len >= 0; len &= 0x7FFFFFFF; +//av_log(s, AV_LOG_ERROR, "pos:%Ld, len:%X\n", pos, len); + av_add_index_entry(st, pos, ast->cum_len, len, 0, key ? AVINDEX_KEYFRAME : 0); + if(ast->sample_size) ast->cum_len += len / ast->sample_size; else @@ -412,6 +415,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) if(!avi->index_loaded) avi_load_index(s); avi->index_loaded = 1; + avi->non_interleaved |= guess_ni_flag(s); return 0; } @@ -699,7 +703,7 @@ static int avi_read_idx1(AVFormatContext *s, int size) if(last_pos == pos) avi->non_interleaved= 1; else - av_add_index_entry(st, pos, ast->cum_len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0); + av_add_index_entry(st, pos, ast->cum_len, len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0); if(ast->sample_size) ast->cum_len += len / ast->sample_size; else @@ -768,7 +772,6 @@ static int avi_load_index(AVFormatContext *s) } } the_end: - avi->non_interleaved |= guess_ni_flag(s); url_fseek(pb, pos, SEEK_SET); return 0; } diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 2474a37741..b3eafe459d 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -1541,7 +1541,7 @@ static int mpegps_read_pes_header(AVFormatContext *s, int i; for(i=0; inb_streams; i++){ if(startcode == s->streams[i]->id) { - av_add_index_entry(s->streams[i], *ppos, dts, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); + av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); } } } diff --git a/libavformat/nut.c b/libavformat/nut.c index 790f9bd910..eb96923f49 100644 --- a/libavformat/nut.c +++ b/libavformat/nut.c @@ -1192,6 +1192,7 @@ static int decode_frame_header(NUTContext *nut, int *key_frame_ret, int64_t *pts s->streams[stream_id], frame_start, pts, + 0, frame_start - nut->stream[stream_id].last_sync_pos, AVINDEX_KEYFRAME); nut->stream[stream_id].last_sync_pos= frame_start; diff --git a/libavformat/rm.c b/libavformat/rm.c index 748d3f209f..c9c1b2aaa4 100644 --- a/libavformat/rm.c +++ b/libavformat/rm.c @@ -982,7 +982,7 @@ resync: if(flags&2){ pkt->flags |= PKT_FLAG_KEY; if((seq&0x7F) == 1) - av_add_index_entry(st, pos, timestamp, 0, AVINDEX_KEYFRAME); + av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME); } } @@ -1054,7 +1054,7 @@ static int64_t rm_read_dts(AVFormatContext *s, int stream_index, if((flags&2) && (seq&0x7F) == 1){ // av_log(s, AV_LOG_DEBUG, "%d %d-%d %Ld %d\n", flags, stream_index2, stream_index, dts, seq); - av_add_index_entry(st, pos, dts, 0, AVINDEX_KEYFRAME); + av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME); if(stream_index2 == stream_index) break; } diff --git a/libavformat/utils.c b/libavformat/utils.c index fd645853d6..10c3a4a560 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1131,7 +1131,7 @@ static void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t time * @param timestamp timestamp in the timebase of the given stream */ int av_add_index_entry(AVStream *st, - int64_t pos, int64_t timestamp, int distance, int flags) + int64_t pos, int64_t timestamp, int size, int distance, int flags) { AVIndexEntry *entries, *ie; int index; @@ -1168,6 +1168,7 @@ int av_add_index_entry(AVStream *st, ie->pos = pos; ie->timestamp = timestamp; ie->min_distance= distance; + ie->size= size; ie->flags = flags; return index; @@ -1193,7 +1194,7 @@ static void av_build_index_raw(AVFormatContext *s) if (pkt->stream_index == 0 && st->parser && (pkt->flags & PKT_FLAG_KEY)) { av_add_index_entry(st, st->parser->frame_offset, pkt->dts, - 0, AVINDEX_KEYFRAME); + 0, 0, AVINDEX_KEYFRAME); } av_free_packet(pkt); }