Vanilagy / mp4-muxer

MP4 multiplexer in pure TypeScript with support for WebCodecs API, video & audio.
https://vanilagy.github.io/mp4-muxer/demo
MIT License
419 stars 32 forks source link

VP9-encoded MP4 causes `Invalid typed array length: -4` error when passed to MP4Box.js #55

Closed lucadalli closed 4 months ago

lucadalli commented 4 months ago

Error is easily observed by attempting to load a VP9 MP4 encoded by mp4-muxer (cyan video attached below) into the MP4Box.js online demo and checking browser console. Compare it to the VP9 MP4 muxed by ffmpeg.wasm (Big Buck Bunny video attached) which does not trigger the same error and successfully loads within the demo.

This minimal reproduction repo demonstrates the error and shows how the two videos were muxed.

https://github.com/Vanilagy/mp4-muxer/assets/39853447/5e673cc4-7916-4582-8e5e-da10a23e8842

https://github.com/Vanilagy/mp4-muxer/assets/39853447/ae803655-c867-44d3-8da3-bbf7e5a70660

Vanilagy commented 4 months ago

@lucadalli Thank you for the detailed bug report and code to reproduce it, I really appreciate it!

This was indeed a plain oversight on my side. The boxes used to store decoder config information differ when using VP9 or AV1, so I had to manually implement them. The change is live in v4.3.2, please try it out and confirm the fix!

lucadalli commented 4 months ago

@Vanilagy Minimal repro now runs without errors. Thank you so much!

tiuvi commented 3 months ago

Great fix, I just had this error today, I'm currently using the library to decode mp4 with mp4box and mediatrackprocessor, pass it through webcodecs and repackage it. https://tiuvi.com/videoEditorWebCodecs