Skip to content

🎥 Make videos programmatically with React

parse more of matroska

Jonny Burgerbbb193624d0d
diff --git a/packages/video-parser/src/boxes/webm/segments.ts b/packages/video-parser/src/boxes/webm/segments.ts
index d3fae0f299..54111d806b 100644
--- a/packages/video-parser/src/boxes/webm/segments.ts
+++ b/packages/video-parser/src/boxes/webm/segments.ts
@@ -17,6 +17,8 @@ import type {UnknownSegment} from './segments/unknown';
import {parseUnknownSegment} from './segments/unknown';
import type {VoidSegment} from './segments/void';
import {parseVoidSegment} from './segments/void';
+import type {WritingAppSegment} from './segments/writing';
+import {parseWritingSegment} from './segments/writing';
export type MatroskaSegment =
| MainSegment
@@ -27,7 +29,8 @@ export type MatroskaSegment =
| VoidSegment
| InfoSegment
| TimestampScaleSegment
- | MuxingAppSegment;
+ | MuxingAppSegment
+ | WritingAppSegment;
export const expectSegment = (iterator: BufferIterator) => {
const segmentId = iterator.getMatroskaSegmentId();
@@ -64,6 +67,10 @@ export const expectSegment = (iterator: BufferIterator) => {
return parseMuxingSegment(iterator);
}
+ if (segmentId === '0x57418c') {
+ return parseWritingSegment(iterator);
+ }
+
const length = iterator.getVint(8);
const child = parseUnknownSegment(iterator, segmentId, length);
return child;
diff --git a/packages/video-parser/src/boxes/webm/segments/writing.ts b/packages/video-parser/src/boxes/webm/segments/writing.ts
new file mode 100644
index 0000000000..a511827b68
--- /dev/null
+++ b/packages/video-parser/src/boxes/webm/segments/writing.ts
@@ -0,0 +1,17 @@
+import type {BufferIterator} from '../../../read-and-increment-offset';
+
+export type WritingAppSegment = {
+ type: 'writing-app-segment';
+ value: string;
+};
+
+export const parseWritingSegment = (
+ iterator: BufferIterator,
+): WritingAppSegment => {
+ const value = iterator.getByteString(12);
+
+ return {
+ type: 'writing-app-segment',
+ value,
+ };
+};
diff --git a/packages/video-parser/src/read-and-increment-offset.ts b/packages/video-parser/src/read-and-increment-offset.ts
index 0905c6add8..8fbc9efdbb 100644
--- a/packages/video-parser/src/read-and-increment-offset.ts
+++ b/packages/video-parser/src/read-and-increment-offset.ts
@@ -84,7 +84,7 @@ export const getArrayBufferIterator = (
return firstTwoString;
}
- const knownIdsWithThreeLength = ['0x4d808c'];
+ const knownIdsWithThreeLength = ['0x4d808c', '0x57418c'];
const firstThree = getSlice(1);
diff --git a/packages/video-parser/src/test/duration.test.ts b/packages/video-parser/src/test/duration.test.ts
index 89eb5d9c14..0001f0ee1f 100644
--- a/packages/video-parser/src/test/duration.test.ts
+++ b/packages/video-parser/src/test/duration.test.ts
@@ -68,14 +68,18 @@ test('Should get duration of AV1 video', async () => {
value: 'Lavf60.3.100',
},
{
- id: '0x57418c4c',
+ type: 'writing-app-segment',
+ value: 'Lavf60.3.100',
+ },
+ {
+ id: '0x44898840',
type: 'unknown-segment',
},
],
},
{
type: 'unknown-segment',
- id: '0x89262876',
+ id: '0x0173c588',
},
],
},