Repository navigation
Detect a non-optimized MP4 from the mdat header - #155
Closed
chrizzchrizz wants to merge 1 commit into
Closed
chrizzchrizz wants to merge 1 commit into
chrizzchrizz wants to merge 1 commit into
Conversation
A non-optimized MP4 (moov after mdat) was only recognized once the whole mdat had been received, so a remote stream downloaded almost the entire file before fetching the moov and streaming the file a second time. The mdat header already gives the moov offset.
Contributor
Author
|
Closing as a duplicate of #151, which has the same fix and was opened first. I added my measurements and offered the fixture-based tests there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A non-optimized MP4 (moov after mdat) was only recognized once the whole mdat had been received.
checkIsOptimizedrecords an mdat whose header has arrived but whose content is still incomplete, yet in that branch it only decides the optimized case (moov before mdat). The.needsRestructureresult is returned only from the complete-atom path, i.e. after the entire mdat is in the buffer.For a remote stream,
RemoteMp4Restructure.optimizeIfNeededtherefore downloads almost the whole file before it fetches the moov, and then streams the file a second time from the mdat offset. Over a slow connection this delays the start by many seconds. Logs from an app (Amperfy) over a VPN at about 0.5 MB/s:Change
When the mdat header has been read before any moov, the mdat size already gives the moov offset (
atomOffset + atomSize), so.needsRestructureis returned right away. The mdat atom is added toatomsfirst, becauserestructureMoovlooks it up there.FileAudioSourceuses the same check, so local files benefit too.Testing
New
Mp4RestructureTestswith two small fixtures: a 1 s AAC file fromafconvert(moov at the start), and the same file with the moov moved behind the mdat and its chunk offsets adjusted (moov at the end). The tests check that:Without the change, the three tests for the non-optimized file fail. The full test suite passes on macOS.