mp4box.js icon indicating copy to clipboard operation
mp4box.js copied to clipboard

Write pssh boxes to generated moov box

Open tbranyen opened this issue 5 years ago • 4 comments

Write the pssh boxes to the generated moov box when writing out during segmentation initialization. This is required otherwise Chrome will not trigger an onEncrypted event.

tbranyen avatar Apr 04 '19 17:04 tbranyen

While this triggers the onEncrypted event, it does not seem to produce the correct ArrayBuffer value that is required to set the mediaKeys. I'll keep iterating on this branch.

tbranyen avatar Apr 04 '19 17:04 tbranyen

I compared the init pssh data with and without mp4box:

  • Without: 678
  • With: 618

Looks like a loss of 60 bytes.


More notes:

  • When reading the boxes layout using the mp4box file reader I counted the byte lengths, and when added together reached the correct 678 bytes
  • Looking at the parsed boxes in the moov box, I see 20 bytes missing from each pssh box, but yet in the visualizer they look to have the correct lengths

Found the missing 20 bytes, looks like the default write will obviously miss pssh-specific metadata, in this case it's the system id which gets saved as hex, but written back as a uint8 array. This accounts for the offset.

tbranyen avatar Apr 04 '19 19:04 tbranyen

Trying to follow this format, but hitting some roadblocks. Will attempt to get pssh writing done by EOD.

var pssh = [
    0x00, 0x00, 0x00, 0x44, 0x70, 0x73, 0x73, 0x68, // BMFF box header (68 bytes, 'pssh')
    0x01, 0x00, 0x00, 0x00,                         // Full box header (version = 1, flags = 0)
    0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02, // SystemID
    0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b,
    0x00, 0x00, 0x00, 0x02,                         // KID_count (2)
    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // First KID ("0123456789012345")
    0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
    0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, // Second KID ("ABCDEFGHIJKLMNOP")
    0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
    0x00, 0x00, 0x00, 0x00,                         // Size of Data (0)
];

tbranyen avatar Apr 04 '19 20:04 tbranyen

Got it working! I had to compare the data using a hex editor since the spec defined a different format. My guess is that this code will need to be reworked a little and can defer to @cconcolato to help with that. This gets me unblocked for now at least.

tbranyen avatar Apr 05 '19 00:04 tbranyen