Skip to content

Commit

Permalink
[TS] Calculate frame rate using the second sample
Browse files Browse the repository at this point in the history
Related to #751.
  • Loading branch information
koln67 committed Sep 2, 2020
1 parent 4c0d38b commit 562040e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Expand Up @@ -5,7 +5,7 @@

#EXT-X-MEDIA:TYPE=AUDIO,URI="bear-640x360-ec3-audio.m3u8",GROUP-ID="default-audio-group",NAME="stream_0",AUTOSELECT=YES,CHANNELS="2"

#EXT-X-STREAM-INF:BANDWIDTH=1216655,AVERAGE-BANDWIDTH=1104925,CODECS="avc1.64001e,ec-3",RESOLUTION=640x360,FRAME-RATE=9.990,AUDIO="default-audio-group"
#EXT-X-STREAM-INF:BANDWIDTH=1216655,AVERAGE-BANDWIDTH=1104925,CODECS="avc1.64001e,ec-3",RESOLUTION=640x360,FRAME-RATE=29.970,AUDIO="default-audio-group"
bear-640x360-ec3-video.m3u8

#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=217180,AVERAGE-BANDWIDTH=157213,CODECS="avc1.64001e",RESOLUTION=640x360,URI="bear-640x360-ec3-video-iframe.m3u8"
10 changes: 6 additions & 4 deletions packager/media/formats/mp2t/ts_muxer.cc
Expand Up @@ -34,10 +34,12 @@ Status TsMuxer::Finalize() {

Status TsMuxer::AddSample(size_t stream_id, const MediaSample& sample) {
DCHECK_EQ(stream_id, 0u);
if (sample_duration_ == 0) {
sample_duration_ = sample.duration() * kTsTimescale / streams().front()->time_scale();
if (muxer_listener())
muxer_listener()->OnSampleDurationReady(sample_duration_);
if (num_samples_ < 2) {
sample_durations_[num_samples_] = sample.duration() * kTsTimescale /
streams().front()->time_scale();
if (num_samples_ == 1 && muxer_listener())
muxer_listener()->OnSampleDurationReady(sample_durations_[num_samples_]);
num_samples_++;
}
return segmenter_->AddSample(sample);
}
Expand Down
3 changes: 2 additions & 1 deletion packager/media/formats/mp2t/ts_muxer.h
Expand Up @@ -35,7 +35,8 @@ class TsMuxer : public Muxer {
void FireOnMediaEndEvent();

std::unique_ptr<TsSegmenter> segmenter_;
int64_t sample_duration_ = 0;
int64_t sample_durations_[2];
int64_t num_samples_ = 0;

DISALLOW_COPY_AND_ASSIGN(TsMuxer);
};
Expand Down

0 comments on commit 562040e

Please sign in to comment.