🎥 Make videos programmatically with React
progress
Jonny Burger693784259e5b
diff --git a/packages/video-parser/src/boxes/webm/segments.ts b/packages/video-parser/src/boxes/webm/segments.tsindex 9c1a541868..6c21e6f3ee 100644--- a/packages/video-parser/src/boxes/webm/segments.ts+++ b/packages/video-parser/src/boxes/webm/segments.ts@@ -37,5 +37,7 @@ export const expectSegment = (iterator: BufferIterator) => {return parseSeekPositionSegment(iterator);}- return parseUnknownSegment(iterator, segmentId, iterator.getVint(8));+ const length = iterator.getVint(8);+ const child = parseUnknownSegment(iterator, segmentId, length);+ return child;};diff --git a/packages/video-parser/src/boxes/webm/segments/main.ts b/packages/video-parser/src/boxes/webm/segments/main.tsindex f6da17e40d..adaccf39d8 100644--- a/packages/video-parser/src/boxes/webm/segments/main.ts+++ b/packages/video-parser/src/boxes/webm/segments/main.ts@@ -1,5 +1,6 @@import type {BufferIterator} from '../../../read-and-increment-offset';-import {expectSegment, type MatroskaSegment} from '../segments';+import {type MatroskaSegment} from '../segments';+import {expectChildren} from './parse-children';export type MainSegment = {type: 'main-segment';@@ -7,12 +8,12 @@ export type MainSegment = {};export const parseMainSegment = (iterator: BufferIterator): MainSegment => {- iterator.getVint(8);+ const length = iterator.getVint(8);- const children = expectSegment(iterator);+ const children = expectChildren(iterator, length);return {type: 'main-segment',- children: [children],+ children,};};diff --git a/packages/video-parser/src/boxes/webm/segments/parse-children.ts b/packages/video-parser/src/boxes/webm/segments/parse-children.tsindex e950f812e8..02d5735178 100644--- a/packages/video-parser/src/boxes/webm/segments/parse-children.ts+++ b/packages/video-parser/src/boxes/webm/segments/parse-children.ts@@ -12,6 +12,9 @@ export const expectChildren = (while (iterator.counter.getOffset() < startOffset + length) {const child = expectSegment(iterator);children.push(child);+ if (child.type === 'unknown-segment') {+ break;+ }}return children;diff --git a/packages/video-parser/src/read-and-increment-offset.ts b/packages/video-parser/src/read-and-increment-offset.tsindex 608edb227b..48c4413586 100644--- a/packages/video-parser/src/read-and-increment-offset.ts+++ b/packages/video-parser/src/read-and-increment-offset.ts@@ -57,7 +57,7 @@ export const getArrayBufferIterator = (getMatroskaSegmentId: () => {const firstTwo = getSlice(2);- const knownIdsWithTwoLength = ['0x4dbb', '0x53ac'];+ const knownIdsWithTwoLength = ['0x4dbb', '0x53ac', '0xec01'];const firstTwoString = `0x${Array.from(new Uint8Array(firstTwo)).map((b) => {@@ -81,6 +81,10 @@ export const getArrayBufferIterator = (const d = [...Array.from(new Uint8Array(getSlice(bytes)))];const totalLength = d[0];+ if (totalLength === 0) {+ return 0;+ }+// Calculate the actual length of the data based on the first set bitlet actualLength = 0;while (((totalLength >> (7 - actualLength)) & 0x01) === 0) {diff --git a/packages/video-parser/src/test/duration.test.ts b/packages/video-parser/src/test/duration.test.tsindex 72084001eb..9d2761fc1a 100644--- a/packages/video-parser/src/test/duration.test.ts+++ b/packages/video-parser/src/test/duration.test.ts@@ -52,6 +52,10 @@ test('Should get duration of AV1 video', async () => {},],},+ {+ id: '0xec01',+ type: 'unknown-segment',+ },],},]);