🎥 Make videos programmatically with React
parse void
Jonny Burger3e44f8fe5131
diff --git a/packages/video-parser/src/boxes/webm/segments.ts b/packages/video-parser/src/boxes/webm/segments.tsindex 6c21e6f3ee..73fa32b9dd 100644--- a/packages/video-parser/src/boxes/webm/segments.ts+++ b/packages/video-parser/src/boxes/webm/segments.ts@@ -10,13 +10,16 @@ import {} from './segments/seek-position';import type {UnknownSegment} from './segments/unknown';import {parseUnknownSegment} from './segments/unknown';+import type {VoidSegment} from './segments/void';+import {parseVoidSegment} from './segments/void';export type MatroskaSegment =| MainSegment| UnknownSegment| SeekHeadSegment| SeekSegment- | SeekPositionSegment;+ | SeekPositionSegment+ | VoidSegment;export const expectSegment = (iterator: BufferIterator) => {const segmentId = iterator.getMatroskaSegmentId();@@ -37,6 +40,10 @@ export const expectSegment = (iterator: BufferIterator) => {return parseSeekPositionSegment(iterator);}+ if (segmentId === '0xec') {+ return parseVoidSegment(iterator);+ }+const length = iterator.getVint(8);const child = parseUnknownSegment(iterator, segmentId, length);return child;diff --git a/packages/video-parser/src/boxes/webm/segments/void.ts b/packages/video-parser/src/boxes/webm/segments/void.tsnew file mode 100644index 0000000000..6bcc0ed078--- /dev/null+++ b/packages/video-parser/src/boxes/webm/segments/void.ts@@ -0,0 +1,16 @@+import type {BufferIterator} from '../../../read-and-increment-offset';++export type VoidSegment = {+ type: 'void-segment';+ length: number;+};++export const parseVoidSegment = (iterator: BufferIterator): VoidSegment => {+ const length = iterator.getVint(8);+ iterator.discard(length);++ return {+ type: 'void-segment',+ length,+ };+};diff --git a/packages/video-parser/src/read-and-increment-offset.ts b/packages/video-parser/src/read-and-increment-offset.tsindex 48c4413586..e3a675d74e 100644--- a/packages/video-parser/src/read-and-increment-offset.ts+++ b/packages/video-parser/src/read-and-increment-offset.ts@@ -55,11 +55,26 @@ export const getArrayBufferIterator = (return new TextDecoder().decode(atom);},getMatroskaSegmentId: () => {- const firstTwo = getSlice(2);+ const first = getSlice(1);+ const firstOneString = `0x${Array.from(new Uint8Array(first))+ .map((b) => {+ return b.toString(16).padStart(2, '0');+ })+ .join('')}`;++ // Catch void block+ const knownIdsWithOneLength = ['0xec'];+ if (knownIdsWithOneLength.includes(firstOneString)) {+ return firstOneString;+ }++ const firstTwo = getSlice(1);const knownIdsWithTwoLength = ['0x4dbb', '0x53ac', '0xec01'];- const firstTwoString = `0x${Array.from(new Uint8Array(firstTwo))+ const firstTwoString = `${firstOneString}${Array.from(+ new Uint8Array(firstTwo),+ ).map((b) => {return b.toString(16).padStart(2, '0');})diff --git a/packages/video-parser/src/test/duration.test.ts b/packages/video-parser/src/test/duration.test.tsindex 9d2761fc1a..d421a9a4d6 100644--- a/packages/video-parser/src/test/duration.test.ts+++ b/packages/video-parser/src/test/duration.test.ts@@ -20,7 +20,6 @@ test('Should get duration of HEVC video', async () => {test('Should get duration of AV1 video', async () => {const parsed = await parseVideo(exampleVideos.av1, Infinity);- console.log(JSON.stringify(parsed));// TODO: AV1 duration is not yet supportedexpect(parsed).toEqual([{@@ -53,8 +52,12 @@ test('Should get duration of AV1 video', async () => {],},{- id: '0xec01',+ length: 88,+ type: 'void-segment',+ },+ {type: 'unknown-segment',+ id: '0x1549a966',},],},