diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index 34e0cafbde..5db1d3f96b 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -392,6 +392,18 @@ Status Segmenter::WriteFrame(bool write_duration) { frame.set_reference_block_timestamp(timestamp_ns); } + // GetRelativeTimecode will return -1 if the relative timecode is too large + // to fit in the frame. + if (cluster_->GetRelativeTimecode(frame.timestamp() / + cluster_->timecode_scale()) < 0) { + const double segment_duration = + static_cast(frame.timestamp()) / kSecondsToNs; + LOG(ERROR) << "Error adding sample to segment: segment too large, " + << segment_duration << " seconds."; + return Status(error::MUXER_FAILURE, + "Error adding sample to segment: segment too large"); + } + if (!cluster_->AddFrame(&frame)) { return Status(error::MUXER_FAILURE, "Error adding sample to segment: Cluster::AddFrame failed");