From 36a7c7d9356a029092cdc12a3275fb89f7d7866d Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Wed, 8 Aug 2018 10:57:58 -0700 Subject: [PATCH] Adjust timestamps in fMP4 if there is an initial composition offset In some ISO-BMFF files, there is an initial non-zero composition offset, but there is no EditList present. This is against ISO-BMFF spec recommentation [1] and we believe in most cases it is just missing the EditList. [1] 14496-12:2015 8.6.6.1 It is recommended that such an edit be used to establish a presentation time of 0 for the first presented sample, when composition offsets are used. Issue: #112. Change-Id: I178d5ec9d8c294c9f70aac4f4dd6254c824e2255 --- packager/media/formats/mp4/track_run_iterator.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packager/media/formats/mp4/track_run_iterator.cc b/packager/media/formats/mp4/track_run_iterator.cc index 2a0dbd1eaa..1fc60d20db 100644 --- a/packager/media/formats/mp4/track_run_iterator.cc +++ b/packager/media/formats/mp4/track_run_iterator.cc @@ -681,8 +681,15 @@ int64_t TrackRunIterator::GetTimestampAdjustment(const Movie& movie, } else { CompositionOffsetIterator composition_offset_iter( track.media.information.sample_table.composition_time_to_sample); - if (composition_offset_iter.IsValid()) - composition_offset = composition_offset_iter.sample_offset(); + if (!composition_offset_iter.IsValid()) { + // This is the init (sub)segment of a fragmented mp4, which does not + // contain any samples. Exit with 0 adjustment and without storing + // |timestamp_adjustment|. This function will be called again later + // with track fragment |traf|. |timestamp_adjustment| will be computed + // and stored then. + return 0; + } + composition_offset = composition_offset_iter.sample_offset(); } int64_t decode_time = 0;