Skip to content

Commit

Permalink
Fix handling of non-interleaved multi track FMP4 files
Browse files Browse the repository at this point in the history
Donot assume that each fragment contains all tracks.
Use track id instead of index to pick the correct timestamp.
  • Loading branch information
duggaraju committed Jul 26, 2023
1 parent 80e0240 commit 5a870a7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ Richard Eklycke <[email protected]>
Sanil Raut <[email protected]>
Sergio Ammirata <[email protected]>
The Chromium Authors <*@chromium.org>
Prakash Duggaraju <[email protected]>
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ Thomas Inskip <[email protected]>
Tim Lansen <[email protected]>
Vincent Nguyen <[email protected]>
Weiguo Shao <[email protected]>
Prakash Duggaraju <[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.

0 comments on commit 5a870a7

Please sign in to comment.