Skip to content

🎥 Make videos programmatically with React

support for esds segment

Jonny Burger278056f679ec
diff --git a/packages/media-parser/src/boxes/iso-base-media/stsd/samples.ts b/packages/media-parser/src/boxes/iso-base-media/stsd/samples.ts
index b8e1832fb9..702f24f3e1 100644
--- a/packages/media-parser/src/boxes/iso-base-media/stsd/samples.ts
+++ b/packages/media-parser/src/boxes/iso-base-media/stsd/samples.ts
@@ -1,4 +1,6 @@
import type {BufferIterator} from '../../../buffer-iterator';
+import type {AnySegment} from '../../../parse-result';
+import {parseBoxes} from '../process-box';
type SampleBase = {
format: string;
@@ -21,6 +23,7 @@ type AudioSample = SampleBase & {
bytesPerPacket: number | null;
bytesPerFrame: number | null;
bitsPerSample: number | null;
+ children: AnySegment[];
};
type VideoSample = SampleBase & {
@@ -164,7 +167,16 @@ export const processSample = ({
const bytesRemainingInBox =
boxSize - (iterator.counter.getOffset() - fileOffset);
- iterator.discard(bytesRemainingInBox);
+ const children = parseBoxes({
+ iterator,
+ allowIncompleteBoxes: false,
+ maxBytes: bytesRemainingInBox,
+ initialBoxes: [],
+ });
+
+ if (children.status === 'incomplete') {
+ throw new Error('Incomplete boxes are not allowed');
+ }
return {
sample: {
@@ -185,6 +197,7 @@ export const processSample = ({
bytesPerPacket: null,
bytesPerFrame: null,
bitsPerSample: null,
+ children: children.segments,
},
};
}
@@ -202,7 +215,17 @@ export const processSample = ({
const bytesRemainingInBox =
boxSize - (iterator.counter.getOffset() - fileOffset);
- iterator.discard(bytesRemainingInBox);
+
+ const children = parseBoxes({
+ iterator,
+ allowIncompleteBoxes: false,
+ maxBytes: bytesRemainingInBox,
+ initialBoxes: [],
+ });
+
+ if (children.status === 'incomplete') {
+ throw new Error('Incomplete boxes are not allowed');
+ }
return {
sample: {
@@ -223,6 +246,7 @@ export const processSample = ({
bytesPerPacket,
bytesPerFrame,
bitsPerSample,
+ children: children.segments,
},
};
}
@@ -245,6 +269,7 @@ export const processSample = ({
const bytesRemainingInBox =
boxSize - (iterator.counter.getOffset() - fileOffset);
+
iterator.discard(bytesRemainingInBox);
return {
diff --git a/packages/media-parser/src/options.ts b/packages/media-parser/src/options.ts
index fbdabcb094..043e54e463 100644
--- a/packages/media-parser/src/options.ts
+++ b/packages/media-parser/src/options.ts
@@ -10,7 +10,7 @@ export type KnownVideoCodecs =
| 'av1'
| 'prores';
-export type KnownAudioCodecs = 'aac' | 'aiff' | 'opus' | 'pcm';
+export type KnownAudioCodecs = 'aac' | 'mp3' | 'aiff' | 'opus' | 'pcm';
export type Options<
EnableDimensions extends boolean,
diff --git a/packages/media-parser/src/test/matroska.test.ts b/packages/media-parser/src/test/matroska.test.ts
index 8cc4b8cd9d..c7104297f6 100644
--- a/packages/media-parser/src/test/matroska.test.ts
+++ b/packages/media-parser/src/test/matroska.test.ts
@@ -137,22 +137,21 @@ test('Should get duration of AV1 video', async () => {
{
type: 'color-segment',
},
- {
- id: '0x0163a294',
- type: 'unknown-segment',
- },
],
},
{
- id: '0x0c000a0e',
- type: 'unknown-segment',
+ codecPrivateData: [
+ 129, 8, 12, 0, 10, 14, 0, 0, 0, 66, 171, 191, 195, 118, 0,
+ 8, 8, 8, 8, 32,
+ ],
+ type: 'codec-private-segment',
},
],
},
],
},
{
- id: '0x',
+ id: '0x1254c367',
type: 'unknown-segment',
},
],