gpac / mp4box.js

JavaScript version of GPAC's MP4Box tool
https://gpac.github.io/mp4box.js/
BSD 3-Clause "New" or "Revised" License
1.96k stars 332 forks source link

Issue Reading QT Compressed mdat Box #69

Open mattcarp opened 8 years ago

mattcarp commented 8 years ago

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
cconcolato commented 8 years ago

Hi, Thanks for the report. It would help if you could provide the file. If you can, please upload it here, adding mp4boxjs and the issue number in the file name: https://www.mediafire.com/filedrop/filedrop_hosted.php?drop=eec9e058a9486fe4e99c33021481d9e1826ca9dbc242a6cfaab0fe95da5e5d95

What I understand from the log is that you've fed only one buffer to mp4box, which has a size of 8388608 bytes. In the middle of that buffer, there is a 'mdat' box that starts. It's big and does not end in the buffer. So the parsing stopped. If you want the parsing to continue, you should provide a new buffer that contains the bytes after that box.

The Exception comes from the fact that the file is a QuickTime file, not conformant to the ISO standard. It uses the box 'cmov' which is not supported in mp4box.js. I should make the error more visible and I could try to add support for the box, if I could have a look at that file.

mattcarp commented 8 years ago

Thanks for your reply. I'm uploading the file now. I've seen this on two different examples.

I'm feeding the ~8 meg buffer size, but I see the same issue on the 1 meg buffer. You'll be able to see the same behaviour on the example upload page as well.

This is indeed a .mov file (and also ProRes). However I have another example of a ProRes .mov which works perfectly with MP4Box. That file can be found here: http://www.cinemartin.com/cinec/_Sample_Videos/Red_Cameras/b_CINEC_ProRes422.mov

Thanks very much for having a look.