summaryrefslogtreecommitdiff
path: root/libavformat/mov.c
diff options
context:
space:
mode:
authorSasi Inguva <isasi@google.com>2017-02-15 12:07:55 -0800
committerMichael Niedermayer <michael@niedermayer.cc>2017-02-20 17:15:36 +0100
commit7e538c947547b04267f0b307b0e7d96a84d558e0 (patch)
tree007d214c49cdc6678da03d1f0398d9e205c686d0 /libavformat/mov.c
parent15ccaa344c4f645ae791aafecdef3d886e196127 (diff)
lavf/mov.c: Correct keyframe search in edit list to return the very first keyframe/frame with matching timestamp. Fixes ticket#5904
Signed-off-by: Sasi Inguva <isasi@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/mov.c')
-rw-r--r--libavformat/mov.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index b5181775e7..2a7cbfe142 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2847,11 +2847,23 @@ static int64_t find_prev_closest_index(AVStream *st,
AVIndexEntry *e_keep = st->index_entries;
int nb_keep = st->nb_index_entries;
int64_t found = -1;
+ int64_t i = 0;
st->index_entries = e_old;
st->nb_index_entries = nb_old;
found = av_index_search_timestamp(st, timestamp, flag | AVSEEK_FLAG_BACKWARD);
+ // Keep going backwards in the index entries until the timestamp is the same.
+ if (found >= 0) {
+ for (i = found; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp;
+ i--) {
+ if ((flag & AVSEEK_FLAG_ANY) ||
+ (e_old[i - 1].flags & AVINDEX_KEYFRAME)) {
+ found = i - 1;
+ }
+ }
+ }
+
/* restore AVStream state*/
st->index_entries = e_keep;
st->nb_index_entries = nb_keep;