Skip to content

🎥 Make videos programmatically with React

matrosk

Jonny Burger56e7c5d9afbb
diff --git a/packages/media-parser/src/boxes/webm/ebml.ts b/packages/media-parser/src/boxes/webm/ebml.ts
index 623a6d728d..eb7c383697 100644
--- a/packages/media-parser/src/boxes/webm/ebml.ts
+++ b/packages/media-parser/src/boxes/webm/ebml.ts
@@ -32,10 +32,9 @@ export const measureEBMLVarInt = (value: number) => {
throw new Error('EBML VINT size not supported ' + value);
};
-export const getVariableInt = (
- value: number,
- width: number = measureEBMLVarInt(value),
-) => {
+export const getVariableInt = (value: number, minWidth: number | null) => {
+ const width = Math.max(measureEBMLVarInt(value), minWidth ?? 0);
+
switch (width) {
case 1:
return new Uint8Array([(1 << 7) | value]);
@@ -72,6 +71,27 @@ export const getVariableInt = (
value >> 8,
value,
]);
+ case 7:
+ return new Uint8Array([
+ (1 << 1) | ((value / 2 ** 48) & 0x1),
+ (value / 2 ** 40) | 0,
+ (value / 2 ** 32) | 0,
+ value >> 24,
+ value >> 16,
+ value >> 8,
+ value,
+ ]);
+ case 8:
+ return new Uint8Array([
+ (1 << 0) | ((value / 2 ** 56) & 0x1),
+ (value / 2 ** 48) | 0,
+ (value / 2 ** 40) | 0,
+ (value / 2 ** 32) | 0,
+ value >> 24,
+ value >> 16,
+ value >> 8,
+ value,
+ ]);
default:
throw new Error('Bad EBML VINT size ' + width);
}
diff --git a/packages/media-parser/src/boxes/webm/get-track.ts b/packages/media-parser/src/boxes/webm/get-track.ts
index bea9043a75..392d88a07d 100644
--- a/packages/media-parser/src/boxes/webm/get-track.ts
+++ b/packages/media-parser/src/boxes/webm/get-track.ts
@@ -179,7 +179,7 @@ export const getTrack = ({
const trackId = getTrackId(track);
- if (trackTypeToString(trackType.value) === 'video') {
+ if (trackTypeToString(trackType.value.value) === 'video') {
const width = getWidthSegment(track);
if (width === null) {
@@ -214,23 +214,27 @@ export const getTrack = ({
trackId,
codec: codecString,
description: getDescription(track),
- height: displayHeight ? displayHeight.value : height.value,
- width: displayWidth ? displayWidth.value : width.value,
+ height: displayHeight ? displayHeight.value.value : height.value.value,
+ width: displayWidth ? displayWidth.value.value : width.value.value,
sampleAspectRatio: {
numerator: 1,
denominator: 1,
},
timescale,
samplePositions: [],
- codedHeight: height.value,
- codedWidth: width.value,
- displayAspectHeight: displayHeight ? displayHeight.value : height.value,
- displayAspectWidth: displayWidth ? displayWidth.value : width.value,
+ codedHeight: height.value.value,
+ codedWidth: width.value.value,
+ displayAspectHeight: displayHeight
+ ? displayHeight.value.value
+ : height.value.value,
+ displayAspectWidth: displayWidth
+ ? displayWidth.value.value
+ : width.value.value,
rotation: 0,
};
}
- if (trackTypeToString(trackType.value) === 'audio') {
+ if (trackTypeToString(trackType.value.value) === 'audio') {
const sampleRate = getSampleRate(track);
const numberOfChannels = getNumberOfChannels(track);
if (sampleRate === null) {
diff --git a/packages/media-parser/src/boxes/webm/make-header.ts b/packages/media-parser/src/boxes/webm/make-header.ts
index df153efc08..a82e864711 100644
--- a/packages/media-parser/src/boxes/webm/make-header.ts
+++ b/packages/media-parser/src/boxes/webm/make-header.ts
@@ -3,6 +3,7 @@ import type {
FloatWithSize,
PossibleEbml,
PossibleEbmlOrUint8Array,
+ UintWithSize,
matroskaElements,
} from './segments/all-segments';
import {ebmlMap, getIdForName} from './segments/all-segments';
@@ -22,7 +23,7 @@ const matroskaToHex = (
return numbers;
};
-function putUintDynamic(number: number) {
+function putUintDynamic(number: number, minimumLength: number | null) {
if (number < 0) {
throw new Error(
'This function is designed for non-negative integers only.',
@@ -30,7 +31,10 @@ function putUintDynamic(number: number) {
}
// Calculate the minimum number of bytes needed to store the integer
- const length = Math.ceil(Math.log2(number + 1) / 8);
+ const length = Math.max(
+ minimumLength ?? 0,
+ Math.ceil(Math.log2(number + 1) / 8),
+ );
const bytes = new Uint8Array(length);
for (let i = 0; i < length; i++) {
@@ -69,7 +73,10 @@ const makeFromHeaderStructure = (
}
if (struct.type === 'uint') {
- return putUintDynamic(fields.value as number);
+ return putUintDynamic(
+ (fields.value as UintWithSize).value,
+ (fields.value as UintWithSize).byteLength,
+ );
}
if (struct.type === 'hex-string') {
@@ -92,7 +99,7 @@ const makeFromHeaderStructure = (
}
const dataView2 = new DataView(new ArrayBuffer(8));
- dataView2.setFloat64(0, fields.value as number);
+ dataView2.setFloat64(0, value.value);
return new Uint8Array(dataView2.buffer);
}
@@ -108,7 +115,7 @@ export const makeMatroskaBytes = (fields: PossibleEbmlOrUint8Array) => {
return combineUint8Arrays([
matroskaToHex(getIdForName(fields.type)),
- getVariableInt(value.length),
+ getVariableInt(value.length, fields.minVintWidth),
value,
]);
};
diff --git a/packages/media-parser/src/boxes/webm/parse-ebml.ts b/packages/media-parser/src/boxes/webm/parse-ebml.ts
index 68542b88fc..ec14363788 100644
--- a/packages/media-parser/src/boxes/webm/parse-ebml.ts
+++ b/packages/media-parser/src/boxes/webm/parse-ebml.ts
@@ -29,7 +29,10 @@ export const parseEbml = async (
);
}
+ const off = iterator.counter.getOffset();
const size = iterator.getVint();
+ const minVintWidth = iterator.counter.getOffset() - off;
+
if (size === null) {
throw new Error(
'Not enough bytes left to parse EBML - this should not happen',
@@ -37,9 +40,17 @@ export const parseEbml = async (
}
if (hasInMap.type === 'uint') {
+ const beforeUintOffset = iterator.counter.getOffset();
const value = iterator.getUint(size);
- return {type: hasInMap.name, value};
+ return {
+ type: hasInMap.name,
+ value: {
+ value,
+ byteLength: iterator.counter.getOffset() - beforeUintOffset,
+ },
+ minVintWidth,
+ };
}
if (hasInMap.type === 'string') {
@@ -48,6 +59,7 @@ export const parseEbml = async (
return {
type: hasInMap.name,
value,
+ minVintWidth,
};
}
@@ -60,6 +72,7 @@ export const parseEbml = async (
value,
size: size === 4 ? '32' : '64',
},
+ minVintWidth,
};
}
@@ -71,6 +84,7 @@ export const parseEbml = async (
[...iterator.getSlice(size)]
.map((b) => b.toString(16).padStart(2, '0'))
.join(''),
+ minVintWidth,
};
}
@@ -78,6 +92,7 @@ export const parseEbml = async (
return {
type: hasInMap.name,
value: iterator.getSlice(size),
+ minVintWidth,
};
}
@@ -109,7 +124,7 @@ export const parseEbml = async (
}
}
- return {type: hasInMap.name, value: children};
+ return {type: hasInMap.name, value: children, minVintWidth};
}
// @ts-expect-error
@@ -126,7 +141,7 @@ export const postprocessEbml = async ({
parserContext: ParserContext;
}): Promise<Prettify<PossibleEbml>> => {
if (ebml.type === 'TimestampScale') {
- parserContext.parserState.setTimescale(ebml.value);
+ parserContext.parserState.setTimescale(ebml.value.value);
}
if (ebml.type === 'TrackEntry') {
@@ -147,7 +162,7 @@ export const postprocessEbml = async ({
}
if (ebml.type === 'Timestamp') {
- parserContext.parserState.setTimestampOffset(offset, ebml.value);
+ parserContext.parserState.setTimestampOffset(offset, ebml.value.value);
}
if (ebml.type === 'Block' || ebml.type === 'SimpleBlock') {
@@ -161,6 +176,7 @@ export const postprocessEbml = async ({
return {
type: 'Block',
value: new Uint8Array([]),
+ minVintWidth: ebml.minVintWidth,
};
}
@@ -172,6 +188,7 @@ export const postprocessEbml = async ({
return {
type: 'Block',
value: new Uint8Array([]),
+ minVintWidth: ebml.minVintWidth,
};
}
@@ -179,6 +196,7 @@ export const postprocessEbml = async ({
return {
type: 'Block',
value: new Uint8Array([]),
+ minVintWidth: ebml.minVintWidth,
};
}
}
@@ -216,10 +234,13 @@ export const postprocessEbml = async ({
);
}
- return {
- type: 'BlockGroup',
- value: [],
- };
+ if (parserContext.nullifySamples) {
+ return {
+ type: 'BlockGroup',
+ value: [],
+ minVintWidth: ebml.minVintWidth,
+ };
+ }
}
return ebml;
diff --git a/packages/media-parser/src/boxes/webm/segments.ts b/packages/media-parser/src/boxes/webm/segments.ts
index 8b4b3946d7..0817db9e3c 100644
--- a/packages/media-parser/src/boxes/webm/segments.ts
+++ b/packages/media-parser/src/boxes/webm/segments.ts
@@ -65,7 +65,10 @@ export const expectSegment = async (
};
}
+ const offsetBeforeVInt = iterator.counter.getOffset();
const length = iterator.getVint();
+ const offsetAfterVInt = iterator.counter.getOffset();
+
if (length === null) {
iterator.counter.decrement(iterator.counter.getOffset() - offset);
return {
@@ -91,10 +94,12 @@ export const expectSegment = async (
? (s) => ({
type: 'Segment',
value: s,
+ minVintWidth: offsetAfterVInt - offsetBeforeVInt,
})
: (s) => ({
type: 'Cluster',
value: s,
+ minVintWidth: offsetAfterVInt - offsetBeforeVInt,
}),
parserContext,
});
diff --git a/packages/media-parser/src/boxes/webm/segments/all-segments.ts b/packages/media-parser/src/boxes/webm/segments/all-segments.ts
index 659b0f0aa7..30e9ba2dda 100644
--- a/packages/media-parser/src/boxes/webm/segments/all-segments.ts
+++ b/packages/media-parser/src/boxes/webm/segments/all-segments.ts
@@ -314,7 +314,7 @@ export type EbmlWithChildren = {
type: 'children';
};
-export type EbmlWithUint8 = {
+export type EbmlWithUint = {
name: MatroskaKey;
type: 'uint';
};
@@ -341,7 +341,7 @@ export type EbmlWithUint8Array = {
export type Ebml =
| EbmlWithString
- | EbmlWithUint8
+ | EbmlWithUint
| EbmlWithChildren
| EbmlWithFloat
| EbmlWithHexString
@@ -658,14 +658,16 @@ export type BlockSegment = EbmlParsed<typeof block>;
export type SimpleBlockSegment = EbmlParsed<typeof simpleBlock>;
export type MainSegment = EbmlParsed<typeof segment>;
export type ClusterSegment = EbmlParsed<typeof cluster>;
+export type Tracks = EbmlParsed<typeof tracks>;
export type FloatWithSize = {value: number; size: '32' | '64'};
+export type UintWithSize = {value: number; byteLength: number};
export type EbmlValue<
T extends Ebml,
Child = PossibleEbml,
-> = T extends EbmlWithUint8
- ? number
+> = T extends EbmlWithUint
+ ? UintWithSize
: T extends EbmlWithString
? string
: T extends EbmlWithFloat
@@ -685,11 +687,13 @@ export type EbmlValueOrUint8Array<T extends Ebml> =
export type EbmlParsed<T extends Ebml> = {
type: T['name'];
value: EbmlValue<T>;
+ minVintWidth: number;
};
export type EbmlParsedOrUint8Array<T extends Ebml> = {
type: T['name'];
value: EbmlValueOrUint8Array<T>;
+ minVintWidth: number;
};
export const ebmlMap = {
diff --git a/packages/media-parser/src/boxes/webm/traversal.ts b/packages/media-parser/src/boxes/webm/traversal.ts
index d82b92fe47..4a5fab3563 100644
--- a/packages/media-parser/src/boxes/webm/traversal.ts
+++ b/packages/media-parser/src/boxes/webm/traversal.ts
@@ -40,6 +40,6 @@ export const getTrackTimestampScale = (track: TrackEntrySegment) => {
export const getTrackByNumber = (tracks: TrackEntrySegment[], id: number) => {
return tracks.find((track) => {
const trackNumber = getTrackNumber(track);
- return trackNumber === id;
+ return trackNumber?.value === id;
});
};
diff --git a/packages/media-parser/src/get-duration.ts b/packages/media-parser/src/get-duration.ts
index 97b6f9fcb8..51e06b7d37 100644
--- a/packages/media-parser/src/get-duration.ts
+++ b/packages/media-parser/src/get-duration.ts
@@ -32,7 +32,7 @@ const getDurationFromMatroska = (segments: AnySegment[]): number | null => {
return null;
}
- return (duration.value.value / timestampScale.value) * 1000;
+ return (duration.value.value / timestampScale.value.value) * 1000;
};
export const getDuration = (boxes: AnySegment[]): number | null => {
diff --git a/packages/media-parser/src/test/create-matroska.test.ts b/packages/media-parser/src/test/create-matroska.test.ts
index c9eef064d3..a724360d92 100644
--- a/packages/media-parser/src/test/create-matroska.test.ts
+++ b/packages/media-parser/src/test/create-matroska.test.ts
@@ -1,12 +1,15 @@
-import {RenderInternals} from '@remotion/renderer';
import {expect, test} from 'bun:test';
-import {statSync} from 'fs';
import {combineUint8Arrays, makeMatroskaBytes} from '../boxes/webm/make-header';
import {parseEbml} from '../boxes/webm/parse-ebml';
import type {MatroskaSegment} from '../boxes/webm/segments';
+import type {
+ MainSegment,
+ Tracks,
+ UintWithSize,
+} from '../boxes/webm/segments/all-segments';
import {getArrayBufferIterator} from '../buffer-iterator';
-import {nodeReader} from '../from-node';
import {parseMedia} from '../parse-media';
+import type {AnySegment} from '../parse-result';
import type {ParserContext} from '../parser-context';
import {makeParserState} from '../parser-state';
@@ -27,34 +30,42 @@ const options: ParserContext = {
test('Should make Matroska header that is same as input', async () => {
const headerOutput = makeMatroskaBytes({
type: 'Header',
+ minVintWidth: 1,
value: [
{
type: 'EBMLVersion',
- value: 1,
+ value: {value: 1, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLReadVersion',
- value: 1,
+ value: {value: 1, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLMaxIDLength',
- value: 4,
+ value: {value: 4, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLMaxSizeLength',
- value: 8,
+ value: {value: 8, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'DocType',
value: 'webm',
+ minVintWidth: 1,
},
{
type: 'DocTypeVersion',
- value: 4,
+ value: {value: 4, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'DocTypeReadVersion',
- value: 2,
+ value: {value: 2, byteLength: 1},
+ minVintWidth: 1,
},
],
});
@@ -64,34 +75,42 @@ test('Should make Matroska header that is same as input', async () => {
expect(parsed).toEqual({
type: 'Header',
+ minVintWidth: 1,
value: [
{
type: 'EBMLVersion',
- value: 1,
+ value: {value: 1, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLReadVersion',
- value: 1,
+ value: {value: 1, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLMaxIDLength',
- value: 4,
+ value: {value: 4, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLMaxSizeLength',
- value: 8,
+ value: {value: 8, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'DocType',
value: 'webm',
+ minVintWidth: 1,
},
{
type: 'DocTypeVersion',
- value: 4,
+ value: {value: 4, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'DocTypeReadVersion',
- value: 2,
+ value: {value: 2, byteLength: 1},
+ minVintWidth: 1,
},
],
});
@@ -105,6 +124,7 @@ test('Should be able to create SeekIdBox', async () => {
const custom = makeMatroskaBytes({
type: 'SeekID',
value: '0x1549a966',
+ minVintWidth: 1,
});
expect(custom).toEqual(file);
});
@@ -120,12 +140,15 @@ test('Should be able to create Seek', async () => {
{
type: 'SeekID',
value: '0x1549a966',
+ minVintWidth: 1,
},
{
type: 'SeekPosition',
- value: 0x40,
+ value: {value: 0x40, byteLength: 1},
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
});
const custom = makeMatroskaBytes(parsed);
@@ -139,7 +162,8 @@ test('Should parse seekHead', async () => {
const seekPosition = makeMatroskaBytes({
type: 'SeekPosition',
- value: 3911,
+ value: {value: 3911, byteLength: 2},
+ minVintWidth: 1,
});
const custom = makeMatroskaBytes({
@@ -151,11 +175,14 @@ test('Should parse seekHead', async () => {
{
type: 'SeekID',
value: '0x1f43b675',
+ minVintWidth: 1,
},
seekPosition,
],
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
});
expect(custom).toEqual(file);
@@ -163,18 +190,18 @@ test('Should parse seekHead', async () => {
const parsed = await parseEbml(iterator, options);
expect(parsed).toEqual({
+ minVintWidth: 1,
type: 'SeekHead',
value: [
{
+ minVintWidth: 1,
type: 'Seek',
value: [
+ {minVintWidth: 1, type: 'SeekID', value: '0x1f43b675'},
{
- type: 'SeekID',
- value: '0x1f43b675',
- },
- {
+ minVintWidth: 1,
type: 'SeekPosition',
- value: 3911,
+ value: {value: 3911, byteLength: 2},
},
],
},
@@ -182,28 +209,70 @@ test('Should parse seekHead', async () => {
});
});
-test('Can we disassemble a Matroska file and assembled it again', async () => {
- process.env.KEEP_SAMPLES = 'true';
- const originalFile = statSync(RenderInternals.exampleVideos.opusWebm);
+const parseWebm = async (str: string) => {
const {boxes} = await parseMedia({
- src: RenderInternals.exampleVideos.opusWebm,
+ src: str,
fields: {
boxes: true,
},
- reader: nodeReader,
});
- let bytesTotal = 0;
+ return boxes;
+};
+
+const stringifyWebm = (boxes: AnySegment[]) => {
const buffers: Uint8Array[] = [];
for (const box of boxes) {
const bytes = makeMatroskaBytes(box as MatroskaSegment);
- bytesTotal += bytes.length;
buffers.push(bytes);
}
const combined = combineUint8Arrays(buffers);
+ return combined;
+};
- // TODO: Remove this
- await Bun.write('combined.webm', combined);
+const WEBM = {
+ parse: parseWebm,
+ stringify: stringifyWebm,
+};
+
+test('Can we disassemble a Matroska file and assembled it again', async () => {
+ process.env.KEEP_SAMPLES = 'true';
+
+ const input =
+ 'https://file-examples.com/storage/fe28b3ef8666c4c399639b9/2020/03/file_example_WEBM_640_1_4MB.webm';
+
+ const parsed = await WEBM.parse(input);
+
+ const segment = parsed.find((s) => s.type === 'Segment') as MainSegment;
+ const tracks = segment.value.find((s) => s.type === 'Tracks') as Tracks;
+ for (const track of tracks.value) {
+ if (track.type === 'TrackEntry') {
+ for (const child of track.value) {
+ if (child.type === 'Video') {
+ const pixelWidth = child.value.find((s) => s.type === 'PixelWidth');
+ const pixelHeight = child.value.find((s) => s.type === 'PixelHeight');
+ const newHeight = (pixelHeight?.value as UintWithSize).value * 2;
+ const newWidth = (pixelWidth?.value as UintWithSize).value / 2;
+ child.value.unshift({
+ type: 'DisplayHeight',
+ value: {
+ value: newHeight,
+ byteLength: 2,
+ },
+ minVintWidth: 1,
+ });
+ child.value.unshift({
+ type: 'DisplayWidth',
+ value: {
+ value: newWidth,
+ byteLength: 2,
+ },
+ minVintWidth: 1,
+ });
+ }
+ }
+ }
+ }
- expect(bytesTotal).toBe(originalFile.size);
+ // await Bun.write('out.webm', WEBM.stringify(parsed));
});
diff --git a/packages/media-parser/src/test/matroska.test.ts b/packages/media-parser/src/test/matroska.test.ts
index 24ead7872e..8a978fee34 100644
--- a/packages/media-parser/src/test/matroska.test.ts
+++ b/packages/media-parser/src/test/matroska.test.ts
@@ -28,36 +28,45 @@ test('Should get duration of AV1 video', async () => {
value: [
{
type: 'EBMLVersion',
- value: 1,
+ value: {value: 1, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLReadVersion',
- value: 1,
+ value: {value: 1, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLMaxIDLength',
- value: 4,
+ value: {value: 4, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'EBMLMaxSizeLength',
- value: 8,
+ value: {value: 8, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'DocType',
value: 'webm',
+ minVintWidth: 1,
},
{
type: 'DocTypeVersion',
- value: 2,
+ value: {value: 2, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'DocTypeReadVersion',
- value: 2,
+ value: {value: 2, byteLength: 1},
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
{
type: 'Segment',
+ minVintWidth: 8,
value: [
{
type: 'SeekHead',
@@ -68,12 +77,15 @@ test('Should get duration of AV1 video', async () => {
{
type: 'SeekID',
value: '0x1549a966',
+ minVintWidth: 1,
},
{
type: 'SeekPosition',
- value: 161,
+ value: {value: 161, byteLength: 1},
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
{
type: 'Seek',
@@ -81,12 +93,15 @@ test('Should get duration of AV1 video', async () => {
{
type: 'SeekID',
value: '0x1654ae6b',
+ minVintWidth: 1,
},
{
type: 'SeekPosition',
- value: 214,
+ value: {value: 214, byteLength: 1},
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
{
type: 'Seek',
@@ -94,12 +109,15 @@ test('Should get duration of AV1 video', async () => {
{
type: 'SeekID',
value: '0x1254c367',
+ minVintWidth: 1,
},
{
type: 'SeekPosition',
- value: 322,
+ value: {value: 322, byteLength: 2},
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
{
type: 'Seek',
@@ -107,14 +125,18 @@ test('Should get duration of AV1 video', async () => {
{
type: 'SeekID',
value: '0x1c53bb6b',
+ minVintWidth: 1,
},
{
type: 'SeekPosition',
- value: 347329,
+ value: {value: 347329, byteLength: 3},
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
{
type: 'Void',
@@ -124,21 +146,25 @@ test('Should get duration of AV1 video', async () => {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]),
+ minVintWidth: 8,
},
{
type: 'Info',
value: [
{
type: 'TimestampScale',
- value: 1000000,
+ value: {value: 1000000, byteLength: 3},
+ minVintWidth: 1,
},
{
type: 'MuxingApp',
value: 'Lavf60.3.100',
+ minVintWidth: 1,
},
{
type: 'WritingApp',
value: 'Lavf60.3.100',
+ minVintWidth: 1,
},
{
type: 'Duration',
@@ -146,8 +172,10 @@ test('Should get duration of AV1 video', async () => {
value: 1000,
size: '64',
},
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
{
type: 'Tracks',
@@ -157,42 +185,51 @@ test('Should get duration of AV1 video', async () => {
value: [
{
type: 'TrackNumber',
- value: 1,
+ value: {value: 1, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'TrackUID',
value: '0xab2171012bb9020a',
+ minVintWidth: 1,
},
{
type: 'FlagLacing',
- value: 0,
+ value: {value: 0, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'Language',
value: 'und',
+ minVintWidth: 1,
},
{
type: 'CodecID',
value: 'V_AV1',
+ minVintWidth: 1,
},
{
type: 'TrackType',
- value: 1,
+ value: {value: 1, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'DefaultDuration',
- value: 40000000,
+ value: {value: 40000000, byteLength: 4},
+ minVintWidth: 1,
},
{
type: 'Video',
value: [
{
type: 'PixelWidth',
- value: 1920,
+ value: {value: 1920, byteLength: 2},
+ minVintWidth: 1,
},
{
type: 'PixelHeight',
- value: 1080,
+ value: {value: 1080, byteLength: 2},
+ minVintWidth: 1,
},
{
type: 'Colour',
@@ -200,8 +237,10 @@ test('Should get duration of AV1 video', async () => {
85, 186, 129, 1, 85, 177, 129, 1, 85, 187, 129, 1, 85,
185, 129, 1,
]),
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
{
type: 'CodecPrivate',
@@ -209,10 +248,13 @@ test('Should get duration of AV1 video', async () => {
129, 8, 12, 0, 10, 14, 0, 0, 0, 66, 171, 191, 195, 118, 0,
8, 8, 8, 8, 32,
]),
+ minVintWidth: 1,
},
],
+ minVintWidth: 8,
},
],
+ minVintWidth: 1,
},
{
type: 'Tags',
@@ -224,6 +266,7 @@ test('Should get duration of AV1 video', async () => {
69, 82, 68, 135, 140, 76, 97, 118, 102, 54, 48, 46, 51, 46, 49,
48, 48,
]),
+ minVintWidth: 1,
},
{
type: 'Tag',
@@ -233,117 +276,146 @@ test('Should get duration of AV1 video', async () => {
135, 148, 48, 48, 58, 48, 48, 58, 48, 49, 46, 48, 48, 48, 48,
48, 48, 48, 48, 48, 0, 0,
]),
+ minVintWidth: 1,
},
],
+ minVintWidth: 1,
},
{
value: [
{
type: 'Timestamp',
- value: 0,
+ value: {value: 0, byteLength: 1},
+ minVintWidth: 1,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 3,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 1,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
{
type: 'Block',
value: new Uint8Array(),
+ minVintWidth: 2,
},
],
type: 'Cluster',
+ minVintWidth: 3,
},
{
type: 'Cues',
@@ -351,6 +423,7 @@ test('Should get duration of AV1 video', async () => {
187, 143, 179, 129, 0, 183, 138, 247, 129, 1, 241, 130, 1, 159, 240,
129, 3,
]),
+ minVintWidth: 1,
},
],
},
diff --git a/packages/media-parser/src/traversal.ts b/packages/media-parser/src/traversal.ts
index 78d7f942d9..fd3fa567d6 100644
--- a/packages/media-parser/src/traversal.ts
+++ b/packages/media-parser/src/traversal.ts
@@ -327,7 +327,7 @@ export const getNumberOfChannels = (track: TrackEntrySegment): number => {
return 1;
}
- return channels.value;
+ return channels.value.value;
};
export const getBitDepth = (track: TrackEntrySegment): number | null => {
@@ -342,7 +342,7 @@ export const getBitDepth = (track: TrackEntrySegment): number | null => {
return null;
}
- return bitDepth.value;
+ return bitDepth.value.value;
};
export const getPrivateData = (track: TrackEntrySegment): Uint8Array | null => {
@@ -444,7 +444,7 @@ export const getTrackId = (track: TrackEntrySegment): number => {
throw new Error('Expected track number segment');
}
- return trackId.value;
+ return trackId.value.value;
};
export const getCodecSegment = (