aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorJacob Trimble <modmaker-at-google.com@ffmpeg.org>2017-07-27 10:34:32 -0700
committerMichael Niedermayer <michael@niedermayer.cc>2017-08-18 03:02:11 +0200
commitf4544163b27615ecfff1b42d6acdb3672ac92399 (patch)
tree0c754d94e0210d8651436a1378ec8c092d8b3511 /libavformat
parent7fb4b0368de18fc150e72a9190a4c87827d2d9d2 (diff)
downloadffmpeg-f4544163b27615ecfff1b42d6acdb3672ac92399.tar.gz
libavformat/mov: Fix inserting frames before current_frame.
When using streaming input, it may be possible to see frames that appear before the current_frame. When these frames are inserted into the index, the current_frame needs to be updated so it is still pointing at the same frame. Signed-off-by: Jacob Trimble <modmaker@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/mov.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c02caf6719..522ce60c2d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4262,7 +4262,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
int64_t dts;
int data_offset = 0;
unsigned entries, first_sample_flags = frag->flags;
- int flags, distance, i, err;
+ int flags, distance, i, err, old_nb_index_entries;
for (i = 0; i < c->fc->nb_streams; i++) {
if (c->fc->streams[i]->id == frag->track_id) {
@@ -4355,13 +4355,19 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES));
if (keyframe)
distance = 0;
+ old_nb_index_entries = st->nb_index_entries;
err = av_add_index_entry(st, offset, dts, sample_size, distance,
keyframe ? AVINDEX_KEYFRAME : 0);
if (err < 0) {
av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n");
+ } else if (err <= sc->current_sample && err + 1 != st->nb_index_entries &&
+ st->nb_index_entries != old_nb_index_entries) {
+ // if we inserted a new item before the current sample, move the
+ // counter ahead so it is still pointing to the same sample.
+ sc->current_sample++;
}
- av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %u, offset %"PRIx64", dts %"PRId64", "
- "size %u, distance %d, keyframe %d\n", st->index, sc->sample_count+i,
+ av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
+ "size %u, distance %d, keyframe %d\n", st->index, err,
offset, dts, sample_size, distance, keyframe);
distance++;
dts += sample_duration;