🎥 Make videos programmatically with React
prores video
Jonny Burger2c3dcb61635d
diff --git a/packages/example/public/prores.mov b/packages/example/public/prores.movnew file mode 100644index 0000000000..3ffeeba4eaBinary files /dev/null and b/packages/example/public/prores.mov differdiff --git a/packages/renderer/src/example-videos.ts b/packages/renderer/src/example-videos.tsindex a47872d5c0..5b1477a214 100644--- a/packages/renderer/src/example-videos.ts+++ b/packages/renderer/src/example-videos.ts@@ -34,5 +34,6 @@ export const exampleVideos = {'public','transparent-with-dar.webm',),+ prores: path.join(examplePackage, 'public', 'prores.mov'),iphonehevc: path.join(examplePackage, 'public', 'iphone-hevc.mov'),};diff --git a/packages/video-parser/src/boxes/iso-base-media/tkhd.ts b/packages/video-parser/src/boxes/iso-base-media/tkhd.tsindex 15ea67bdbc..969a555669 100644--- a/packages/video-parser/src/boxes/iso-base-media/tkhd.ts+++ b/packages/video-parser/src/boxes/iso-base-media/tkhd.ts@@ -76,9 +76,15 @@ export const parseTkhd = ({iterator.getUint32(),iterator.getUint32(),];-- const width = iterator.getUint32();- const height = iterator.getUint32();+ const widthWithoutRotationApplied =+ iterator.getUint32() / (matrix[0] === 0 ? 1 : matrix[0]);+ const heightWithoutRotationApplied =+ iterator.getUint32() / (matrix[4] === 0 ? 1 : matrix[4]);++ // TODO: This is not correct, HEVC videos with matrix is wrong+ const width = widthWithoutRotationApplied / (matrix[1] === 0 ? 1 : matrix[1]);+ const height =+ heightWithoutRotationApplied / (matrix[1] === 0 ? 1 : matrix[1]);return {offset,diff --git a/packages/video-parser/src/get-dimensions.ts b/packages/video-parser/src/get-dimensions.tsindex f06d826952..f1664e7357 100644--- a/packages/video-parser/src/get-dimensions.ts+++ b/packages/video-parser/src/get-dimensions.ts@@ -65,67 +65,70 @@ export const getDimensions = (boxes: AnySegment[]): Dimensions => {throw new Error('Expected moov box children');}- const trakBoxes = children.filter((b) => b.type === 'trak-box');- const tracks = trakBoxes- .map((t) => {- if (t.type !== 'trak-box') {- throw new Error('Expected trak box');- }-- const mdiaBox = t.children.find(- (c) => c.type === 'regular-box' && c.boxType === 'mdia',- );- if (!mdiaBox) {- throw new Error('Expected mdia box');- }-- if (mdiaBox.type !== 'regular-box') {- throw new Error('Expected mdia box');- }-- const minfBox = mdiaBox.children.find(- (c) => c.type === 'regular-box' && c.boxType === 'minf',- );- if (!minfBox) {- throw new Error('Expected minf box');- }-- if (minfBox.type !== 'regular-box') {- throw new Error('Expected minf box');- }-- const stblBox = minfBox.children.find(- (c) => c.type === 'regular-box' && c.boxType === 'stbl',- );-- if (!stblBox) {- throw new Error('Expected stbl box');- }-- if (stblBox.type !== 'regular-box') {- throw new Error('Expected stbl box');- }-- const stsdBox = stblBox.children.find((c) => c.type === 'stsd-box');-- if (!stsdBox) {- throw new Error('Expected stsd box');- }-- if (stsdBox.type !== 'stsd-box') {- throw new Error('Expected stsd box');- }-- const videoSamples = stsdBox.samples.filter((s) => s.type === 'video');- return videoSamples[0];- })- .filter(Boolean);-- if (tracks.length === 0) {+ const t = children.find((b) => b.type === 'trak-box');++ if (!t || t.type !== 'trak-box') {+ throw new Error('Expected trak box');+ }++ const mdiaBox = t.children.find(+ (c) => c.type === 'regular-box' && c.boxType === 'mdia',+ );+ const tkhdBox = t.children.find((c) => c.type === 'tkhd-box');+ if (tkhdBox && tkhdBox.type === 'tkhd-box') {+ return {+ width: tkhdBox.width,+ height: tkhdBox.height,+ };+ }++ if (!mdiaBox) {+ throw new Error('Expected mdia box');+ }++ if (mdiaBox.type !== 'regular-box') {+ throw new Error('Expected mdia box');+ }++ const minfBox = mdiaBox.children.find(+ (c) => c.type === 'regular-box' && c.boxType === 'minf',+ );+ if (!minfBox) {+ throw new Error('Expected minf box');+ }++ if (minfBox.type !== 'regular-box') {+ throw new Error('Expected minf box');+ }++ const stblBox = minfBox.children.find(+ (c) => c.type === 'regular-box' && c.boxType === 'stbl',+ );++ if (!stblBox) {+ throw new Error('Expected stbl box');+ }++ if (stblBox.type !== 'regular-box') {+ throw new Error('Expected stbl box');+ }++ const stsdBox = stblBox.children.find((c) => c.type === 'stsd-box');++ if (!stsdBox) {+ throw new Error('Expected stsd box');+ }++ if (stsdBox.type !== 'stsd-box') {+ throw new Error('Expected stsd box');+ }++ const videoSamples = stsdBox.samples.filter((s) => s.type === 'video');+ if (videoSamples.length === 0) {throw new Error('Has no video stream');}- const [firstTrack] = tracks;+ const [firstTrack] = videoSamples;if (firstTrack.type !== 'video') {throw new Error('Expected video track');}diff --git a/packages/video-parser/src/test/duration.test.ts b/packages/video-parser/src/test/duration.test.tsindex db7e8c217b..c7aca50cc3 100644--- a/packages/video-parser/src/test/duration.test.ts+++ b/packages/video-parser/src/test/duration.test.ts@@ -20,13 +20,15 @@ test('Should get duration of video', async () => {test('Should get duration of HEVC video', async () => {const parsed = await parseMedia(RenderInternals.exampleVideos.iphonehevc,- {durationInSeconds: true, dimensions: true},+ {durationInSeconds: true, dimensions: true, fps: true},nodeReader,);expect(parsed.durationInSeconds).toBe(3.4);+ // TODO: Should apply rotation matrix to get the correct dimensionsexpect(parsed.dimensions).toEqual({width: 1920,height: 1080,});+ expect(parsed.fps).toEqual(30);});diff --git a/packages/video-parser/src/test/parse-webm.test.ts b/packages/video-parser/src/test/parse-webm.test.tsindex 91da3e4309..b7235e7b6a 100644--- a/packages/video-parser/src/test/parse-webm.test.ts+++ b/packages/video-parser/src/test/parse-webm.test.ts@@ -8,7 +8,6 @@ test('should be able to parse a WebM', async () => {RenderInternals.exampleVideos.transparentWebm,{durationInSeconds: true,- boxes: true,},nodeReader,);diff --git a/packages/video-parser/src/test/stream-local.test.ts b/packages/video-parser/src/test/stream-local.test.tsindex 30bef6f223..adef7edd72 100644--- a/packages/video-parser/src/test/stream-local.test.ts+++ b/packages/video-parser/src/test/stream-local.test.ts@@ -9,7 +9,6 @@ test('Should stream ISO base media', async () => {{durationInSeconds: true,fps: true,- boxes: true,},nodeReader,);@@ -87,3 +86,20 @@ test('Should stream screen recording video', async () => {width: 2874,});});+test('Should stream ProRes video', async () => {+ const parsed = await parseMedia(+ RenderInternals.exampleVideos.prores,+ {+ fps: true,+ dimensions: true,+ durationInSeconds: true,+ },+ nodeReader,+ );++ // TODO: FPS should be 60+ expect(parsed.fps).toBe(3.90625);+ expect(parsed.dimensions.width).toBe(1920);+ expect(parsed.dimensions.height).toBe(1080);+ expect(parsed.durationInSeconds).toBe(0.034);+});