Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix handling of non-interleaved multi track FMP4 files #1214

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Richard Eklycke <[email protected]>
Sanil Raut <[email protected]>
Sergio Ammirata <[email protected]>
The Chromium Authors <*@chromium.org>
Prakash Duggaraju <[email protected]>
Dennis E. Mungai (Brainiarc7) <[email protected]>
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ Thomas Inskip <[email protected]>
Tim Lansen <[email protected]>
Vincent Nguyen <[email protected]>
Weiguo Shao <[email protected]>
Prakash Duggaraju <[email protected]>
Dennis E. Mungai (Brainiarc7) <[email protected]>
7 changes: 7 additions & 0 deletions packager/media/formats/mp4/mp4_media_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ TEST_F(MP4MediaParserTest, CencWithDecryptionSourceAndSenc) {
EXPECT_EQ(82u, num_samples_);
}

TEST_F(MP4MediaParserTest, NonInterleavedFMP4) {
// Test small, non-interleaved fragment MP4 with one track per fragment.
EXPECT_TRUE(ParseMP4File("BigBuckBunny_10s.ismv", 512));
EXPECT_EQ(2u, num_streams_);
EXPECT_EQ(770u, num_samples_);
}

} // namespace mp4
} // namespace media
} // namespace shaka
9 changes: 5 additions & 4 deletions packager/media/formats/mp4/track_run_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ bool TrackRunIterator::Init() {
bool TrackRunIterator::Init(const MovieFragment& moof) {
runs_.clear();

next_fragment_start_dts_.resize(moof.tracks.size(), 0);
const auto track_count = std::max(moof.tracks.size(), moov_->tracks.size());
next_fragment_start_dts_.resize(track_count, 0);
for (size_t i = 0; i < moof.tracks.size(); i++) {
const TrackFragment& traf = moof.tracks[i];

const auto track_index = traf.header.track_id - 1;
const Track* trak = NULL;
for (size_t t = 0; t < moov_->tracks.size(); t++) {
if (moov_->tracks[t].header.track_id == traf.header.track_id)
Expand Down Expand Up @@ -351,7 +352,7 @@ bool TrackRunIterator::Init(const MovieFragment& moof) {
}

int64_t run_start_dts = traf.decode_time_absent
? next_fragment_start_dts_[i]
? next_fragment_start_dts_[track_index]
: traf.decode_time.decode_time;

// dts is directly adjusted, which then propagates to pts as pts is encoded
Expand Down Expand Up @@ -426,7 +427,7 @@ bool TrackRunIterator::Init(const MovieFragment& moof) {
runs_.push_back(tri);
sample_count_sum += trun.sample_count;
}
next_fragment_start_dts_[i] = run_start_dts;
next_fragment_start_dts_[track_index] = run_start_dts;
}

std::sort(runs_.begin(), runs_.end(), CompareMinTrackRunDataOffset());
Expand Down
Binary file added packager/media/test/data/BigBuckBunny_10s.ismv
Binary file not shown.