diff --git a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java index c918fc5790c..d678a836d72 100644 --- a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java +++ b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java @@ -968,6 +968,26 @@ private static long parseTfdt(ParsableByteArray tfdt) { return version == 1 ? tfdt.readUnsignedLongToLong() : tfdt.readUnsignedInt(); } + private static boolean isEdtsListDurationForEntireMediaTimeline(Track track) { + // Currently we only support a single edit that moves the entire media timeline (indicated by + // duration == 0 or (editListDurationUs + editListMediaTimeUs) >= track duration. + // Other uses of edit lists are uncommon and unsupported. + if (track.editListDurations == null + || track.editListDurations.length != 1 + || track.editListMediaTimes == null) { + return false; + } + if (track.editListDurations[0] == 0) { + return true; + } + long editListEndMediaTimeUs = + Util.scaleLargeTimestamp( + track.editListDurations[0] + track.editListMediaTimes[0], + C.MICROS_PER_SECOND, + track.movieTimescale); + return editListEndMediaTimeUs >= track.durationUs; + } + /** * Parses a trun atom (defined in 14496-12). * @@ -1015,11 +1035,8 @@ private static int parseTrun( // ensure that the first frame's presentation timestamp is zero. long edtsOffset = 0; - // Currently we only support a single edit that moves the entire media timeline (indicated by - // duration == 0). Other uses of edit lists are uncommon and unsupported. - if (track.editListDurations != null - && track.editListDurations.length == 1 - && track.editListDurations[0] == 0) { + // Currently we only support a single edit that moves the entire media timeline. + if (isEdtsListDurationForEntireMediaTimeline(track)) { edtsOffset = castNonNull(track.editListMediaTimes)[0]; }