🎥 Make videos programmatically with React
fixed the tests or maybe just broke everything
Jonny Burger49a874842098
diff --git a/packages/media-parser/src/boxes/iso-base-media/make-track.ts b/packages/media-parser/src/boxes/iso-base-media/make-track.tsindex 78627d9d88..d7ce4f1a1f 100644--- a/packages/media-parser/src/boxes/iso-base-media/make-track.ts+++ b/packages/media-parser/src/boxes/iso-base-media/make-track.ts@@ -6,6 +6,7 @@ import {getSampleRate,} from '../../get-audio-codec';import {+ getFpsFromMp4TrakBox,getTimescaleAndDuration,trakBoxContainsAudio,trakBoxContainsVideo,@@ -130,6 +131,7 @@ export const makeBaseMediaTrack = (transferCharacteristics: null,},codecWithoutConfig: getVideoCodecFromIsoTrak(trakBox),+ fps: getFpsFromMp4TrakBox(trakBox),};return track;};diff --git a/packages/media-parser/src/boxes/webm/make-track.ts b/packages/media-parser/src/boxes/webm/make-track.tsindex b12d83fa3b..f4ecd7988b 100644--- a/packages/media-parser/src/boxes/webm/make-track.ts+++ b/packages/media-parser/src/boxes/webm/make-track.ts@@ -333,6 +333,7 @@ export const getTrack = ({codecWithoutConfig: getMatroskaVideoCodecWithoutConfigString({codecSegment: codec,}),+ fps: null,};}diff --git a/packages/media-parser/src/get-fps.ts b/packages/media-parser/src/get-fps.tsindex 7c7d0457c6..2866c93336 100644--- a/packages/media-parser/src/get-fps.ts+++ b/packages/media-parser/src/get-fps.ts@@ -74,25 +74,13 @@ export const getTimescaleAndDuration = (return null;};-export const getFps = (segments: AnySegment[]) => {- const moovBox = getMoovBox(segments);- if (!moovBox) {- return null;- }-- const trackBoxes = getTraks(moovBox);-- const trackBox = trackBoxes.find(trakBoxContainsVideo);- if (!trackBox) {- return null;- }-- const timescaleAndDuration = getTimescaleAndDuration(trackBox);+export const getFpsFromMp4TrakBox = (trakBox: TrakBox) => {+ const timescaleAndDuration = getTimescaleAndDuration(trakBox);if (!timescaleAndDuration) {return null;}- const sttsBox = getSttsBox(trackBox);+ const sttsBox = getSttsBox(trakBox);if (!sttsBox) {return null;}@@ -104,6 +92,22 @@ export const getFps = (segments: AnySegment[]) => {});};+export const getFps = (segments: AnySegment[]) => {+ const moovBox = getMoovBox(segments);+ if (!moovBox) {+ return null;+ }++ const trackBoxes = getTraks(moovBox);++ const trackBox = trackBoxes.find(trakBoxContainsVideo);+ if (!trackBox) {+ return null;+ }++ return getFpsFromMp4TrakBox(trackBox);+};+export const hasFps = (boxes: AnySegment[]): boolean => {try {return getFps(boxes) !== null;diff --git a/packages/media-parser/src/get-tracks.ts b/packages/media-parser/src/get-tracks.tsindex 4dcc6da677..85b7ec1c51 100644--- a/packages/media-parser/src/get-tracks.ts+++ b/packages/media-parser/src/get-tracks.ts@@ -61,6 +61,7 @@ export type VideoTrack = {trakBox: TrakBox | null;codecPrivate: Uint8Array | null;color: VideoTrackColorParams;+ fps: number | null;};export type AudioTrack = {diff --git a/packages/media-parser/src/test/mdhd.test.ts b/packages/media-parser/src/test/mdhd.test.tsindex 0a01c0dcc6..dd9f6239f5 100644--- a/packages/media-parser/src/test/mdhd.test.ts+++ b/packages/media-parser/src/test/mdhd.test.ts@@ -2,9 +2,8 @@ import {expect, test} from 'bun:test';import {createMdhd} from '../create/iso-base-media/mdia/create-mdhd';const reference = new Uint8Array([- 0x00, 0x00, 0x00, 0x20, 0x6d, 0x64, 0x68, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00,- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5f, 0x90, 0x00, 0x05,- 0x7e, 0x40, 0x55, 0xc4, 0x00, 0x00,+ 0, 0, 0, 32, 109, 100, 104, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 95,+ 144, 1, 238, 98, 128, 85, 196, 0, 0,]);test('mdhd', () => {diff --git a/packages/media-parser/src/test/parse-esds.test.ts b/packages/media-parser/src/test/parse-esds.test.tsindex d95a698daf..5642e84efd 100644--- a/packages/media-parser/src/test/parse-esds.test.ts+++ b/packages/media-parser/src/test/parse-esds.test.ts@@ -37,11 +37,10 @@ test('Parse ESDS box', () => {upStream: 0,avgBitrate: 320000,maxBitrate: 320000,- decoderSpecificConfigs: [- {- type: 'unknown-decoder-specific-config',- },- ],+ decoderSpecificConfigs: [],+ },+ {+ type: 'sl-config-descriptor',},],});@@ -90,11 +89,11 @@ test('Parse two ESDS', () => {type: 'mp4a-specific-config',asBytes: new Uint8Array([17, 144]),},- {- type: 'unknown-decoder-specific-config',- },],},+ {+ type: 'sl-config-descriptor',+ },],});});diff --git a/packages/media-parser/src/test/stbl.test.ts b/packages/media-parser/src/test/stbl.test.tsindex d40226b456..e6795a5dd6 100644--- a/packages/media-parser/src/test/stbl.test.ts+++ b/packages/media-parser/src/test/stbl.test.ts@@ -56,8 +56,8 @@ const sample = new Uint8Array([0, 0, 0, 1, 0, 0, 35, 40, 0, 0, 0, 1, 0, 0, 11, 184, 0, 0, 0, 1, 0, 0, 35, 40,0, 0, 0, 1, 0, 0, 11, 184, 0, 0, 0, 1, 0, 0, 35, 40, 0, 0, 0, 1, 0, 0, 11,184, 0, 0, 0, 1, 0, 0, 35, 40, 0, 0, 0, 1, 0, 0, 11, 184, 0, 0, 0, 40, 115,- 116, 115, 99, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 0,- 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 244, 115, 116, 115, 122, 0, 0, 0, 0,+ 116, 115, 99, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0,+ 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 244, 115, 116, 115, 122, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 120, 0, 0, 30, 78, 0, 0, 12, 118, 0, 0, 6, 88, 0, 0, 3,102, 0, 0, 2, 226, 0, 0, 11, 254, 0, 0, 3, 26, 0, 0, 11, 220, 0, 0, 3, 185, 0,0, 2, 211, 0, 0, 13, 169, 0, 0, 3, 117, 0, 0, 10, 226, 0, 0, 21, 209, 0, 0,@@ -114,21 +114,20 @@ test('Create a full stbl atom', () => {0xb2, 0xc0, 0x01, 0x00, 0x06, 0x68, 0xeb, 0xe0, 0x8c, 0xb2, 0x2c, 0xfd,0xf8, 0xf8, 0x00,]);- expect(- createStbl({- samplePositions: exampleVideoSamplePositions,- codecSpecificData: createAvc1Data({- pasp: createPasp(1, 1),- avccBox: createAvccBox(privateData),- width: 640,- height: 360,- horizontalResolution: 72,- verticalResolution: 72,- compressorName: '',- depth: 24,- type: 'avc1-data',- }),- isVideo: true,+ const result = createStbl({+ samplePositions: exampleVideoSamplePositions,+ codecSpecificData: createAvc1Data({+ pasp: createPasp(1, 1),+ avccBox: createAvccBox(privateData),+ width: 640,+ height: 360,+ horizontalResolution: 72,+ verticalResolution: 72,+ compressorName: '',+ depth: 24,+ type: 'avc1-data',}),- ).toEqual(sample);+ isVideo: true,+ });+ expect(result).toEqual(sample);});diff --git a/packages/media-parser/src/test/stream-local.test.ts b/packages/media-parser/src/test/stream-local.test.tsindex 67b4f2b7ca..9c4f7487a5 100644--- a/packages/media-parser/src/test/stream-local.test.ts+++ b/packages/media-parser/src/test/stream-local.test.ts@@ -159,6 +159,7 @@ test('Should stream AV1', async () => {primaries: 'bt709',},codecWithoutConfig: 'av1',+ fps: null,});expect(parsed.audioTracks.length).toBe(0);expect(videoTracks).toBe(1);@@ -322,6 +323,7 @@ test('Should stream variable fps video', async () => {primaries: null,},codecWithoutConfig: 'vp8',+ fps: null,});expect(parsed.audioTracks.length).toBe(1);expect(parsed.audioTracks[0]).toEqual({@@ -625,6 +627,7 @@ test('Stretched VP8', async () => {primaries: null,},codecWithoutConfig: 'vp8',+ fps: null,});});diff --git a/packages/media-parser/src/test/stream-samples.test.ts b/packages/media-parser/src/test/stream-samples.test.tsindex e022095442..90e46966e8 100644--- a/packages/media-parser/src/test/stream-samples.test.ts+++ b/packages/media-parser/src/test/stream-samples.test.ts@@ -52,6 +52,7 @@ test('Stream samples', async () => {primaries: null,},codecWithoutConfig: 'h264',+ fps: 30,});expect(getSamplePositionsFromTrack(trakBox as TrakBox, null));diff --git a/packages/media-parser/src/test/stsc.test.ts b/packages/media-parser/src/test/stsc.test.tsindex b9df36db33..1af3961184 100644--- a/packages/media-parser/src/test/stsc.test.ts+++ b/packages/media-parser/src/test/stsc.test.ts@@ -1,55 +1,55 @@const reference = new Uint8Array([- 0, 0, 4, 228, 115, 116, 115, 99, 0, 0, 0, 0, 0, 0, 0, 103, 0, 0, 0, 1, 0, 0,- 0, 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 2,- 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, 2, 0, 0,- 0, 1, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 1,- 0, 0, 0, 10, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 11, 0, 0, 0, 2, 0, 0, 0, 1, 0,- 0, 0, 12, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 13, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0,- 0, 14, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 15, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0,- 16, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 17, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 19,- 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 21, 0,- 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 22, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 23, 0, 0,- 0, 1, 0, 0, 0, 1, 0, 0,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0, 0, 95, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,+ 0, 96, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 98, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 99, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 100, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 101, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 102, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 103, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 106, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 107, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 108, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 109, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 110, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 111, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 112, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 114, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 115, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 116, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,+ 117, 0, 0, 0, 7, 0, 0, 0, 1,]);import {expect, test} from 'bun:test';@@ -58,5 +58,6 @@ import {createStsc} from '../create/iso-base-media/trak/mdia/minf/stbl/create-sttest('stsc', () => {expect(reference.byteLength).toBe(1252);- expect(createStsc(exampleAudioSamplePositions)).toEqual(reference);+ const result = createStsc(exampleAudioSamplePositions);+ expect(result).toEqual(reference);});diff --git a/packages/media-parser/src/test/stsd.test.ts b/packages/media-parser/src/test/stsd.test.tsindex d30d9dce44..e43aebba5f 100644--- a/packages/media-parser/src/test/stsd.test.ts+++ b/packages/media-parser/src/test/stsd.test.ts@@ -118,12 +118,12 @@ test('Should be able to parse a STSD audio box correctly', async () => {type: 'mp4a-specific-config',asBytes: new Uint8Array([18, 16]),},- {- type: 'unknown-decoder-specific-config',- },],upStream: 0,},+ {+ type: 'sl-config-descriptor',+ },],esId: 0,sizeOfInstance: 34,diff --git a/packages/webcodecs/src/can-reencode-video-track.ts b/packages/webcodecs/src/can-reencode-video-track.tsindex 442259af7b..a2d7abed6c 100644--- a/packages/webcodecs/src/can-reencode-video-track.ts+++ b/packages/webcodecs/src/can-reencode-video-track.ts@@ -14,6 +14,7 @@ export const canReencodeVideoTrack = async ({codec: videoCodec,height: track.displayAspectHeight,width: track.displayAspectWidth,+ fps: track.fps,});const videoDecoderConfig =await getVideoDecoderConfigWithHardwareAcceleration(track);diff --git a/packages/webcodecs/src/choose-correct-avc1-profile.ts b/packages/webcodecs/src/choose-correct-avc1-profile.tsnew file mode 100644index 0000000000..704837e47a--- /dev/null+++ b/packages/webcodecs/src/choose-correct-avc1-profile.ts@@ -0,0 +1,64 @@+export const chooseCorrectAvc1Profile = ({+ width,+ height,+ fps,+}: {+ width: number;+ height: number;+ fps: number | null;+}) => {+ // 0x42 = Baseline profile+ // 0x4D = Main profile+ // 0x58 = Extended profile+ // 0x64 = High profile+ // According to Wikipedia, 0x64 is the most widely supported profile.+ // So we always choose 0x64.+ /**+ Ignoring lower levels of <720p, let's only support Players that can play 720p and above.+ • Level 3.1 = 1F (hex) -> 1,280×[email protected] (5)+ • Level 3.2 = 20 (hex) -> 1,280×1,[email protected] (4)+ • Level 4.0 = 28 (hex) -> 2,048×1,[email protected] (4)+ • Level 4.1 = 29 (hex) -> 2,048×1,[email protected] (4)+ • Level 4.2 = 2A (hex) -> 2,048×1,[email protected] (4)+ • Level 5.0 = 32 (hex) -> 3,672×1,[email protected] (5)+ • Level 5.1 = 33 (hex) -> 4,096×2,[email protected] (5)+ • Level 5.2 = 34 (hex) -> 4,096×2,[email protected] (5)+ • Level 6.0 = 3C (hex) -> 8,192×4,[email protected] (5)+ • Level 6.1 = 3D (hex) -> 8,192×4,[email protected] (5)+ • Level 6.2 = 3E (hex) -> 8,192×4,[email protected] (5)+ */+ const profiles = [+ {level: '3.1', hex: '1F', width: 1280, height: 720, fps: 30.0},+ {level: '3.2', hex: '20', width: 1280, height: 1024, fps: 42.2},+ {level: '4.0', hex: '28', width: 2048, height: 1024, fps: 30.0},+ {level: '4.1', hex: '29', width: 2048, height: 1024, fps: 30.0},+ {level: '4.2', hex: '2A', width: 2048, height: 1080, fps: 60.0},+ {level: '5.0', hex: '32', width: 3672, height: 1536, fps: 26.7},+ {level: '5.1', hex: '33', width: 4096, height: 2304, fps: 26.7},+ {level: '5.2', hex: '34', width: 4096, height: 2304, fps: 56.3},+ {level: '6.0', hex: '3C', width: 8192, height: 4320, fps: 30.2},+ {level: '6.1', hex: '3D', width: 8192, height: 4320, fps: 60.4},+ {level: '6.2', hex: '3E', width: 8192, height: 4320, fps: 120.8},+ ];+ const profile = profiles.find((p) => {+ if (width > p.width) {+ return false;+ }++ if (height > p.height) {+ return false;+ }++ // if has no fps, use 60 as a conservative fallback+ const fallbackFps = fps ?? 60;+ return fallbackFps <= p.fps;+ });++ if (!profile) {+ throw new Error(+ `No suitable AVC1 profile found for ${width}x${height}@${fps}fps`,+ );+ }++ return `avc1.6400${profile.hex}`;+};diff --git a/packages/webcodecs/src/on-video-track.ts b/packages/webcodecs/src/on-video-track.tsindex 4c752484fc..f4bf15d692 100644--- a/packages/webcodecs/src/on-video-track.ts+++ b/packages/webcodecs/src/on-video-track.ts@@ -95,6 +95,7 @@ export const makeVideoTrackHandler =codec: videoOperation.videoCodec,height: track.displayAspectHeight,width: track.displayAspectWidth,+ fps: track.fps,});const videoDecoderConfig =await getVideoDecoderConfigWithHardwareAcceleration(track);diff --git a/packages/webcodecs/src/video-encoder-config.ts b/packages/webcodecs/src/video-encoder-config.tsindex 779dc2b382..c9c5d8c482 100644--- a/packages/webcodecs/src/video-encoder-config.ts+++ b/packages/webcodecs/src/video-encoder-config.ts@@ -1,13 +1,16 @@+import {chooseCorrectAvc1Profile} from './choose-correct-avc1-profile';import type {ConvertMediaVideoCodec} from './codec-id';export const getVideoEncoderConfig = async ({- width,- height,codec,+ height,+ width,+ fps,}: {width: number;height: number;codec: ConvertMediaVideoCodec;+ fps: number | null;}): Promise<VideoEncoderConfig | null> => {if (typeof VideoEncoder === 'undefined') {return null;@@ -16,8 +19,7 @@ export const getVideoEncoderConfig = async ({const config: VideoEncoderConfig = {codec:codec === 'h264'- ? // avc1.42001f must correspond with the CodecPrivate data string- 'avc1.42001f'+ ? chooseCorrectAvc1Profile({fps, height, width}): codec === 'vp9'? 'vp09.00.10.08': codec,