From fe6c4f0c47d4390bead6e226cb12b45584b76301 Mon Sep 17 00:00:00 2001 From: Sasi Inguva Date: Tue, 29 May 2018 15:36:07 -0700 Subject: lavf/mov.c: Set st->start_time for video streams explicitly. If start_time is not set, ffmpeg takes the duration from the global movie instead of the per stream duration. Signed-off-by: Sasi Inguva Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'libavformat') diff --git a/libavformat/mov.c b/libavformat/mov.c index cab7247cc5..4ad19122b3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3673,11 +3673,15 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // If the minimum pts turns out to be greater than zero after fixing the index, then we subtract the // dts by that amount to make the first pts zero. - if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && msc->min_corrected_pts > 0) { - av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts); - for (i = 0; i < st->nb_index_entries; ++i) { - st->index_entries[i].timestamp -= msc->min_corrected_pts; + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (msc->min_corrected_pts > 0) { + av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts); + for (i = 0; i < st->nb_index_entries; ++i) { + st->index_entries[i].timestamp -= msc->min_corrected_pts; + } } + // Start time should be equal to zero or the duration of any empty edits. + st->start_time = empty_edits_sum_duration; } // Update av stream length, if it ends up shorter than the track's media duration @@ -4013,6 +4017,14 @@ static void mov_build_index(MOVContext *mov, AVStream *st) mov_fix_index(mov, st); } + // Update start time of the stream. + if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries > 0) { + st->start_time = st->index_entries[0].timestamp + sc->dts_shift; + if (sc->ctts_data) { + st->start_time += sc->ctts_data[0].duration; + } + } + mov_estimate_video_delay(mov, st); } -- cgit v1.2.3