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

Shaka packager doesn't handle non-interleaved multi track fragmented MP4 files correctly. #1213

Closed
duggaraju opened this issue May 31, 2023 · 4 comments · Fixed by #1214 or #1312
Closed
Labels
status: archived Archived and locked; will not be updated

Comments

@duggaraju
Copy link
Contributor

System info

Operating System: Any
Shaka Packager Version:

Issue and steps to reproduce the problem

v2.6.1-634af65-release
Packager Command:
ffmpeg -i test.mp4 -c copy test.ismv // convert mp4 to fragmented mp4
packager "in=test.ismv,stream=audio,out=audio.mp4" "in=test.ismv,stream=video,out=video.mp4" --mpd_output a.mpd

Extra steps to reproduce the problem?
(1)
convert MP4 to fragmented MP4 (alternate audio/video tracks)
ffmpeg -i test.mp4 -c copy test.ismv // convert mp4 to fragmented mp4

(2)
packager "in=test.ismv,stream=audio,out=audio.mp4" "in=test.ismv,stream=video,out=video.mp4" --mpd_output a.mpd

What is the expected result?
the packager succeeds.

What happens instead?
A ton of warnings about timestamps gaps/overlaps and the playback doesn't work.

The issue is that shaka mixes the timestamps of audio and video together due to bug in the TrackRunIterator.

@duggaraju duggaraju changed the title Shaka packager doesn't handle multi track fragmented MP4 files correct. Shaka packager doesn't handle non-interleaved multi track fragmented MP4 files correctly. May 31, 2023
@duggaraju
Copy link
Contributor Author

Shaka assumes that every moof contains all tracks. If the tracks were non interleaved then each moof would only contain a single track and the code would mix up the tiemstamps of the tracks together (treat last audio dts as next video dts and vice versa)

@duggaraju
Copy link
Contributor Author

ffmpeg -i test.mp4 -c copy -movflags cmaf+separate_moof+delay_moov+skip_trailer dashmp4
packager in=dash.mp4,stream=audio,out=audio.mp4 in=dash.mp4,stream=video,out=video.mp4 --mpd_output dash.mpd

ffmpeg -i test.mp4 -c copy -f ismv smooth.mp4
would also created something similar.

@duggaraju
Copy link
Contributor Author

duggaraju commented Jul 26, 2023

@joeyparrish Found the issue and have the fix but wanted to confirm something.
The Flush() test is crashing. It Appends the same fragmented MP4 data twice.
The first time Init() is called the moov has 2 tracks.
But when the second time it is appended, the move is cleared and hence the crash. Not sure if this is a test bug or expected.
The simplest fix is do std::max(moov_->tracks.size(), moof.tracks.size()) but wanted to confirm the same.

@duggaraju
Copy link
Contributor Author

duggaraju commented Jul 26, 2023

Looks like I can't always expect Init() to be called before Init(moof). There is code explicitly to ignore the second moov if it is already parsed and Init() wont be called causing the Flush() test to crash. So to be safe do not assume Init() would be called but instead handle this in Init(moof)

cosmin pushed a commit that referenced this issue Aug 21, 2023
Do not assume that each fragment contains all tracks. 
Use track id instead of index to pick the correct timestamp.

Fixes #1213
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Oct 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
1 participant