videojs / mux.js

Lightweight utilities for inspecting and manipulating video container formats.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrectly parsing SIDX box

benjamintoofer opened this issue · comments

Hi, there seems to be a bug with parsing the SIDX box from the mp4. I looked into the function that parses the SIDX and I believe this is where the bug exists.

sidx: function(data) {

The issue seems to be the way the earliestPresentationTime and firstOffset are being parsed. In the ISO/IEC 14496-12:2012 spec, in section 8.16.3.2, the syntax dictates that the properties earliestPresentationTime and firstOffset are 64 bit values if the version is set to the value of 1. They are 32 bit values if the version is 0. It looks like in your code, it assumes that those properties are always parsed as 32 bit values. I know it's not possible to represent a 64 bit integer in Javascript since it is limited to 53 bits. Our solution was to just parse 53 bits and move the index 8 bytes. We also log a warning message that only 53 bits of the value are being parsed.

Shaka Player had to do this as well. Here's our sidx parser, which builds on top of a more general box parser, and checks the version number before extracting either 32 or 64 bits:

https://github.com/google/shaka-player/blob/6e5a0797de42a4b7ade45667552cf1b20cb0f143/lib/media/mp4_segment_index_parser.js#L109-L115

And here's how we deal with 53-bit precision in a 64-bit field, by reading two 32-bit fields and throwing an exception based on the high bits:

https://github.com/google/shaka-player/blob/6e5a0797de42a4b7ade45667552cf1b20cb0f143/lib/util/data_view_reader.js#L146-L184

Apache 2 license, same as mux.js. I hope that helps!

Should be fixed in 5.7.0

Thanks for the detailed write up @joeyparrish I created a new story to fix the 64 bit issues that we likely have.