gpac / mp4box.js

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

this.ext incorrectly parsed in MP4BoxOutputFile.addTrack({avcDecoderConfigRecord}) #308

Open vjeux opened 1 year ago

vjeux commented 1 year ago

If you run the following code:

const MP4BoxOutputFile = MP4Box.createFile();
const trackID = MP4BoxOutputFile.addTrack({
  width,
  height,
  brands: ['mp42', 'isom'],
  timescale: 90000,
  language: 21956,
  name: 'VideoHandler',

  // https://gist.github.com/uupaa/8493378ec15f644a3d2b
  avcDecoderConfigRecord: (new Uint8Array([
    1, // configurationVersion
    77, // AVCProfileIndication
    0, // profile_compatibility
    40, // AVCLevelIndication
    0b111111 << 2 ^ // reserved
      3, // lengthSizeMinusOne
    0b111 << 5 ^ // reserved

      1, // numOfSequenceParameterSets
    0, 27, // sequenceParameterSetLength
    39, 77, 0, 40, 137, 139, 96, 60, 1, 19, 242, 224, 33, 129, 128, 2, 238, 0, 0, 187, 130, 247, 190, 15, 132, 66, 55, // sequenceParameterSetNALUnit

    1, // numOfPictureParameterSets
    0, 4, // pictureParameterSetLength
    40, 238, 31, 32, // pictureParameterSetNALUnit

    // ???
    0, 0, 0, 16, 115, 116, 116, 115
  ])).buffer,
});

I would expect this.ext to be [0, 0, 0, 16, 115, 116, 116, 115]. But this.ext isn't there.

I've tracked the issue there:

The avcC box is created here: https://github.com/gpac/mp4box.js/blob/master/src/isofile-advanced-creation.js#L86

which calls the parse function but this.size and this.hdr_size are undefined. https://github.com/gpac/mp4box.js/blob/master/src/parsing/avcC.js#L10

So toparse here is NaN and it doesn't add the ext. https://github.com/gpac/mp4box.js/blob/master/src/parsing/avcC.js#L27

In practice the ext data is probably garbage anyway in my case (I'm still trying to understand the file format) but figured I would mention it here if you think it should be fixed.