oeuillot / node-matroska

Matroska library written for nodejs
GNU General Public License v3.0
26 stars 12 forks source link

matroska 2.2.4 breaks ts-ebml #12

Open jony89 opened 2 years ago

jony89 commented 2 years ago

while upgrading my app, and using ts-ebml in order to extract the record time from buffer, I got the wrong time.

not 100% sure what went wrong, but it's definitely due to moving from 2.2.3 to 2.2.4 of matroska.

https://www.npmjs.com/package/matroska/v/2.2.4

That's the code that breaks (it's being used by many):


const injectMetadata = async (blob) => {
  const decoder = new Decoder();
  const reader = new Reader();
  reader.logging = false;
  reader.drop_default_duration = false;

  const buffer = await readAsArrayBuffer(blob);
  if (!buffer) throw new Error('could not inject metadata');

  // fix for chrome 92+ with mac. getting error https://github.com/legokichi/ts-ebml/issues/33
  const validEmlType = ['m', 'u', 'i', 'f', 's', '8', 'b', 'd']; // This is from elm type of the lib
  const elms = decoder.decode(buffer)?.filter(elm => validEmlType.includes(elm.type));

  elms.forEach((elm) => { reader.read(elm); });
  reader.stop();

  const refinedMetadataBuf = tools.makeMetadataSeekable(
    reader.metadatas, reader.duration, reader.cues,
  );
  const body = buffer.slice(reader.metadataSize);
  return new Blob([refinedMetadataBuf, body], { type: blob.type });
};

so there is no specific error, but the record duration is totally wrong.

davedoesdev commented 2 years ago

Update of element names to v4 should have changed the major version so dependencies didn't break. https://github.com/legokichi/ts-ebml/pull/41#issuecomment-1168265375