Issue Reading QT Compressed mdat Box

Open
#69 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
20/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale

Research direction

The error occurs while parsing the mdat box in mp4.js. Start at the check around line 2520 (if (start + size > stream.getEndPosition())) and follow how MultiBufferStream computes the end position for large files. Reproduce with an MP4 whose mdat sits at the end and is larger than the initial buffer; success is the box parsing without the 'not found in buffered data' error. No tests are named in the issue.

Written by the indexing model from the issue text.

Description

enhancement

Hi. I have a 3.8 gig MP4 file, which plays fine in the Quicktime player. However it produces the below error message in MP4Box when it hits the mdat box, which is at the end of the file. This occurs when using the demo page as well as in my own implementation. Some numbers:

Overall file size: 3818408565
Start position of mdat: 45329
Size of mdat: 3818363236
End position (stream.getEndPosition()): 8388608

I believe the relevant error messages are:

[BoxParser] Not enough data in stream to parse the entire "mdat" box
[MultiBufferStream] Position 3818408565 not found in buffered data

The situation is set up when the following returns false (looks like end position is wrong?):

    if (start + size > stream.getEndPosition()) { //...

Below are the full logs. Any ideas? I'm happy to help however I can, and thanks for the great library.

Logs:

Appending buffer with offset 0
mp4.js:25 [0:00:03.759] [MP4Box] Processing buffer (fileStart: 0)
mp4.js:20 [0:00:03.759] [MultiBufferStream] Appending new buffer (fileStart: 0 - Length: 8388608)
mp4.js:20 [0:00:03.760] [MultiBufferStream] 1 stored buffer(s) (0/8388608 bytes): [0-8388607]
mp4.js:20 [0:00:03.761] [MultiBufferStream] Stream ready for parsing
mp4.js:20 [0:00:03.761] [MultiBufferStream] 1 stored buffer(s) (0/8388608 bytes): [0-8388607]
mp4.js:20 [0:00:03.761] [MultiBufferStream] Found position in existing buffer #0
mp4.js:20 [0:00:03.762] [MultiBufferStream] Repositioning parser at buffer position: 0
mp4.js:20 [0:00:03.763] [BoxParser] Found box of type ftyp and size 32 at position 0
mp4.js:20 [0:00:03.764] [MultiBufferStream] 1 stored buffer(s) (32/8388608 bytes): [0-8388607]
mp4.js:20 [0:00:03.764] [BoxParser] Found box of type moov and size 40266 at position 32
mp4.js:20 [0:00:03.765] [BoxParser] Found box of type cmov and size 40258 at position 40
mp4.js:30 [0:00:03.765] [BoxParser] Unknown box type: cmov
mp4.js:30 [0:00:03.765] [BoxParser] cmov box writing not yet implemented, keeping unparsed data in memory for later write
mp4.js:20 [0:00:03.766] [MultiBufferStream] 1 stored buffer(s) (40298/8388608 bytes): [0-8388607]
mp4.js:20 [0:00:03.767] [BoxParser] Found box of type free and size 5023 at position 40298
mp4.js:30 [0:00:03.767] [BoxParser] free box writing not yet implemented, keeping unparsed data in memory for later write
mp4.js:20 [0:00:03.767] [MultiBufferStream] 1 stored buffer(s) (45321/8388608 bytes): [0-8388607]
mp4.js:20 [0:00:03.768] [BoxParser] Found box of type wide and size 8 at position 45321
mp4.js:30 [0:00:03.768] [BoxParser] Unknown box type: wide
mp4.js:30 [0:00:03.768] [BoxParser] wide box writing not yet implemented, keeping unparsed data in memory for later write
mp4.js:20 [0:00:03.768] [MultiBufferStream] 1 stored buffer(s) (45329/8388608 bytes): [0-8388607]
mp4.js:20 [0:00:03.769] [BoxParser] Found box of type mdat and size 3818363236 at position 45329
mp4.js:2520 are start + size greater than end position?
mp4.js:2521 start: 45329 size: 3818363236 endPosition: 8388608
mp4.js:20 [0:00:03.769] [MultiBufferStream] Found position in existing buffer #0
mp4.js:20 [0:00:03.770] [MultiBufferStream] Repositioning parser at buffer position: 45329
mp4.js:30 [0:00:03.770] [BoxParser] Not enough data in stream to parse the entire "mdat" box
mp4.js:5253 the box:
mp4.js:5254 B…r.Box {type: "mdat", size: 3818363236}
mp4.js:20 [0:00:03.773] [MultiBufferStream] 1 stored buffer(s) (45337/8388608 bytes): [0-8388607]
mp4.js:20 [0:00:03.775] [MultiBufferStream] 1 stored buffer(s) (8388608/8388608 bytes): [0-8388607]
mp4.js:20 [0:00:07.269] [MultiBufferStream] Position 3818408565 not found in buffered data
mp4.js:6418 Uncaught TypeError: Cannot read property 'duration' of undefined
Dominant language
TypeScript
Stars
2.5k
Forks
390
Avg merge
1d 17h
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gpac/mp4box.js

All issues in gpac/mp4box.js

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.