diff --git a/packager/media/formats/mp4/mp4_media_parser.cc b/packager/media/formats/mp4/mp4_media_parser.cc index 4a02112578..98de99bfa6 100644 --- a/packager/media/formats/mp4/mp4_media_parser.cc +++ b/packager/media/formats/mp4/mp4_media_parser.cc @@ -410,9 +410,12 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { // Calculate duration (based on timescale). int64_t duration = 0; - if (track->media.header.duration > 0) { + if (track->media.header.duration > 0 && + track->media.header.duration != std::numeric_limits::max()) { duration = track->media.header.duration; - } else if (moov_->extends.header.fragment_duration > 0) { + } else if (moov_->extends.header.fragment_duration > 0 && + moov_->extends.header.fragment_duration != + std::numeric_limits::max()) { DCHECK(moov_->header.timescale != 0); duration = Rescale(moov_->extends.header.fragment_duration, moov_->header.timescale, timescale); diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index c7425b8b44..64f0465780 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -248,7 +248,9 @@ Status MP4Muxer::DelayInitializeMuxer() { ftyp->compatible_brands.push_back(FOURCC_cmfc); // Carry over movie extends header duration from init segment. - moov->extends.header.fragment_duration = streams()[0].get()->duration(); + if (streams()[0].get()->duration() > 0) { + moov->extends.header.fragment_duration = streams()[0].get()->duration(); + } } moov->header.creation_time = IsoTimeNow();