[TS] Calculate frame rate using the second sample

Related to #751.
This commit is contained in:
koln67 2020-09-02 21:27:02 +00:00 committed by GitHub
parent 4c0d38bde3
commit 562040e000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -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-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 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" #EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=217180,AVERAGE-BANDWIDTH=157213,CODECS="avc1.64001e",RESOLUTION=640x360,URI="bear-640x360-ec3-video-iframe.m3u8"

View File

@ -34,10 +34,12 @@ Status TsMuxer::Finalize() {
Status TsMuxer::AddSample(size_t stream_id, const MediaSample& sample) { Status TsMuxer::AddSample(size_t stream_id, const MediaSample& sample) {
DCHECK_EQ(stream_id, 0u); DCHECK_EQ(stream_id, 0u);
if (sample_duration_ == 0) { if (num_samples_ < 2) {
sample_duration_ = sample.duration() * kTsTimescale / streams().front()->time_scale(); sample_durations_[num_samples_] = sample.duration() * kTsTimescale /
if (muxer_listener()) streams().front()->time_scale();
muxer_listener()->OnSampleDurationReady(sample_duration_); if (num_samples_ == 1 && muxer_listener())
muxer_listener()->OnSampleDurationReady(sample_durations_[num_samples_]);
num_samples_++;
} }
return segmenter_->AddSample(sample); return segmenter_->AddSample(sample);
} }

View File

@ -35,7 +35,8 @@ class TsMuxer : public Muxer {
void FireOnMediaEndEvent(); void FireOnMediaEndEvent();
std::unique_ptr<TsSegmenter> segmenter_; 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); DISALLOW_COPY_AND_ASSIGN(TsMuxer);
}; };