diff --git a/packager/media/formats/mp2t/ts_muxer.cc b/packager/media/formats/mp2t/ts_muxer.cc index e3d6447ad4d..9fc56ab5953 100644 --- a/packager/media/formats/mp2t/ts_muxer.cc +++ b/packager/media/formats/mp2t/ts_muxer.cc @@ -34,6 +34,8 @@ Status TsMuxer::Finalize() { Status TsMuxer::AddSample(size_t stream_id, const MediaSample& sample) { DCHECK_EQ(stream_id, 0u); + // The duration of the first sample may have been adjusted, so use + // the duration of the second sample instead. if (num_samples_ < 2) { sample_durations_[num_samples_] = sample.duration() * kTsTimescale / streams().front()->time_scale(); diff --git a/packager/media/formats/mp4/segmenter.cc b/packager/media/formats/mp4/segmenter.cc index 5a8a9147193..1f311d6deee 100644 --- a/packager/media/formats/mp4/segmenter.cc +++ b/packager/media/formats/mp4/segmenter.cc @@ -138,6 +138,8 @@ Status Segmenter::AddSample(size_t stream_id, const MediaSample& sample) { if (!status.ok()) return status; + // The duration of the first sample may have been adjusted, so use + // the duration of the second sample instead. if (num_samples_ < 2) { sample_durations_[num_samples_] = sample.duration(); num_samples_++; diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index ba6f8f7130f..6f584e3d39c 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -161,6 +161,8 @@ Status Segmenter::Finalize() { Status Segmenter::AddSample(const MediaSample& source_sample) { std::shared_ptr sample(source_sample.Clone()); + // The duration of the first sample may have been adjusted, so use + // the duration of the second sample instead. if (num_samples_ < 2) { sample_durations_[num_samples_] = sample->duration(); if (num_samples_ == 0) diff --git a/packager/media/formats/webm/segmenter.h b/packager/media/formats/webm/segmenter.h index b8818e9afd6..e22e668cbcc 100644 --- a/packager/media/formats/webm/segmenter.h +++ b/packager/media/formats/webm/segmenter.h @@ -139,7 +139,7 @@ class Segmenter { uint64_t progress_target_ = 0; uint64_t accumulated_progress_ = 0; uint64_t first_timestamp_ = 0; - uint32_t sample_durations_[2] = {0u, 0u}; + int64_t sample_durations_[2] = {0, 0}; size_t num_samples_ = 0; // The position (in bytes) of the start of the Segment payload in the init // file. This is also the size of the header before the SeekHead.