diff options
author | popcornmix <popcornmix@gmail.com> | 2016-01-29 20:27:00 +0000 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2016-02-01 00:40:47 +0100 |
commit | def56677e58de9aaa516a738b6469747662ac372 (patch) | |
tree | 10fdcf714880b7d08b3808ad7199caf14239997c | |
parent | 014e4e4499fd5615340d0001f2a0f02382d53718 (diff) | |
download | ffmpeg-def56677e58de9aaa516a738b6469747662ac372.tar.gz |
wtv: Speed up wtv index creation
The index creation is O(N^2) with number of entries (typically thousands).
On a Pi this can take more than 60 seconds to execute for a recording of a few hours.
By replacing with an O(N) loop, this takes virtually zero time
Liked-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavformat/wtvdec.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c index e8f6196a5e..1deb4d9b8c 100644 --- a/libavformat/wtvdec.c +++ b/libavformat/wtvdec.c @@ -1028,21 +1028,23 @@ static int read_header(AVFormatContext *s) pb = wtvfile_open(s, root, root_size, ff_timeline_table_0_entries_Events_le16); if (pb) { int i; + AVIndexEntry *e = wtv->index_entries; + AVIndexEntry *e_end = wtv->index_entries + wtv->nb_index_entries - 1; + uint64_t last_position = 0; while (1) { uint64_t frame_nb = avio_rl64(pb); uint64_t position = avio_rl64(pb); + while (frame_nb > e->size && e <= e_end) { + e->pos = last_position; + e++; + } if (avio_feof(pb)) break; - for (i = wtv->nb_index_entries - 1; i >= 0; i--) { - AVIndexEntry *e = wtv->index_entries + i; - if (frame_nb > e->size) - break; - if (position > e->pos) - e->pos = position; - } + last_position = position; } + e_end->pos = last_position; wtvfile_close(pb); - st->duration = wtv->index_entries[wtv->nb_index_entries - 1].timestamp; + st->duration = e_end->timestamp; } } } |