🎥 Make videos programmatically with React
new object structure
Jonny Burger35fbe24c2ca3
diff --git a/packages/it-tests/src/rendering/base64-audio.test.ts b/packages/it-tests/src/rendering/base64-audio.test.tsindex 18adc0dd19..837405d26a 100644--- a/packages/it-tests/src/rendering/base64-audio.test.ts+++ b/packages/it-tests/src/rendering/base64-audio.test.ts@@ -25,12 +25,12 @@ test("Should be able to render a MP3 audio file", async () => {const exists = fs.existsSync(outputPath);expect(exists).toBe(true);- const info = await RenderInternals.callFf(- "ffprobe",- [outputPath],- false,- "info"- );+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [outputPath],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("mp3");expect(data).toContain("stereo");diff --git a/packages/it-tests/src/rendering/frame-accuracy-gif.test.ts b/packages/it-tests/src/rendering/frame-accuracy-gif.test.tsindex bd3ff55eb4..13ad85262e 100644--- a/packages/it-tests/src/rendering/frame-accuracy-gif.test.ts+++ b/packages/it-tests/src/rendering/frame-accuracy-gif.test.ts@@ -35,9 +35,9 @@ const getMissedFramesforCodec = async () => {});- await RenderInternals.callFf(- "ffmpeg",- [+ await RenderInternals.callFf({+ bin: "ffmpeg",+ args: ["-i",outputPath,"-f",@@ -45,9 +45,9 @@ const getMissedFramesforCodec = async () => {path.join(outputDir, "out%2d.jpeg"),"-y",],- false,- "info"- );+ indent: false,+ logLevel: "info",+ });let missedFrames = 0;diff --git a/packages/it-tests/src/rendering/render-scale.test.ts b/packages/it-tests/src/rendering/render-scale.test.tsindex 3e5a2e060a..8a2ff2547e 100644--- a/packages/it-tests/src/rendering/render-scale.test.ts+++ b/packages/it-tests/src/rendering/render-scale.test.ts@@ -38,12 +38,12 @@ test("Should be able to render video with scale 2", async () => {const exists = fs.existsSync(outputPath);expect(exists).toBe(true);- const info = await RenderInternals.callFf(- "ffprobe",- [outputPath],- false,- "info"- );+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [outputPath],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("Video: h264");expect(data).toContain("yuv420p");@@ -77,12 +77,12 @@ test("Should be able to render video with scale 0.1", async () => {const exists = fs.existsSync(outputPath);expect(exists).toBe(true);- const info = await RenderInternals.callFf(- "ffprobe",- [outputPath],- false,- "info"- );+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [outputPath],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("Video: h264");expect(data).toContain("yuv420p");diff --git a/packages/it-tests/src/rendering/rendering.test.ts b/packages/it-tests/src/rendering/rendering.test.tsindex d609938d47..2c7519a0b7 100644--- a/packages/it-tests/src/rendering/rendering.test.ts+++ b/packages/it-tests/src/rendering/rendering.test.ts@@ -35,12 +35,12 @@ test("Should be able to render video with custom port", async () => {const exists = fs.existsSync(outputPath);expect(exists).toBe(true);- const info = await RenderInternals.callFf(- "ffprobe",- [outputPath],- false,- "info"- );+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [outputPath],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("Video: h264");expect(data).toContain("yuv420p");@@ -141,7 +141,12 @@ test("Should render a ProRes video", async () => {const exists = fs.existsSync(out);expect(exists).toBe(true);- const info = await RenderInternals.callFf("ffprobe", [out], false, "info");+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [out],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data.includes("prores (4444)") || data.includes("prores (ap4h")).toBe(true@@ -163,7 +168,12 @@ test("Should render a still image if single frame specified", async () => {expect(task.exitCode).toBe(0);expect(fs.existsSync(outImg)).toBe(true);- const info = await RenderInternals.callFf("ffprobe", [outImg], false, "info");+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [outImg],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("Video: png");await fs.promises.rm(outDir, {@@ -185,7 +195,12 @@ test("Should be able to render a WAV audio file", async () => {const exists = fs.existsSync(out);expect(exists).toBe(true);- const info = await RenderInternals.callFf("ffprobe", [out], false, "info");+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [out],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("pcm_s16le");expect(data).toContain("2 channels");@@ -210,7 +225,12 @@ test("Should be able to render a MP3 audio file", async () => {const exists = fs.existsSync(out);expect(exists).toBe(true);- const info = await RenderInternals.callFf("ffprobe", [out], false, "info");+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [out],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("mp3");expect(data).toContain("stereo");@@ -235,7 +255,12 @@ test("Should be able to render a AAC audio file", async () => {const exists = fs.existsSync(out);expect(exists).toBe(true);- const info = await RenderInternals.callFf("ffprobe", [out], false, "info");+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [out],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("aac");expect(data).toContain("stereo");@@ -257,12 +282,12 @@ test("Should render a video with GIFs", async () => {expect(task.exitCode).toBe(0);expect(fs.existsSync(outputPath)).toBe(true);- const info = await RenderInternals.callFf(- "ffprobe",- [outputPath],- false,- "info"- );+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [outputPath],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("Video: h264");expect(data).not.toContain("bt709");@@ -284,7 +309,12 @@ test("Should render a video with Offline Audio-context", async () => {expect(task.exitCode).toBe(0);expect(fs.existsSync(out)).toBe(true);- const info = await RenderInternals.callFf("ffprobe", [out], false, "info");+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [out],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("Stream #0:0: Audio: mp3");expect(data).toContain("48000 Hz, stereo");@@ -301,7 +331,12 @@ test("Should succeed to render an audio file that doesn't have any audio inputs"});expect(task.exitCode).toBe(0);- const info = await RenderInternals.callFf("ffprobe", [out], false, "info");+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [out],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("Duration: 00:00:00.36");expect(data).toContain("Audio: mp3, 48000 Hz");@@ -356,12 +391,12 @@ test("Dynamic duration should work, and render from inside src/", async () => {expect(task.exitCode).toBe(0);expect(fs.existsSync(outputPath)).toBe(true);- const info = await RenderInternals.callFf(- "ffprobe",- [outputPath],- false,- "info"- );+ const info = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [outputPath],+ indent: false,+ logLevel: "info",+ });const data = info.stderr;expect(data).toContain("Video: h264");const expectedDuration = (randomDuration / 30).toFixed(2);diff --git a/packages/it-tests/src/ssr/render-frames.test.ts b/packages/it-tests/src/ssr/render-frames.test.tsindex 0877d5fada..225d393cfc 100644--- a/packages/it-tests/src/ssr/render-frames.test.ts+++ b/packages/it-tests/src/ssr/render-frames.test.ts@@ -48,7 +48,6 @@ test("Legacy SSR way of rendering videos should still work", async () => {});await stitchFramesToVideo({- dir: framesDir,assetsInfo,force: true,fps: reactSvg.fps,@@ -58,12 +57,12 @@ test("Legacy SSR way of rendering videos should still work", async () => {codec: "h264",});expect(fs.existsSync(outPath)).toBe(true);- const probe = await RenderInternals.callFf(- "ffprobe",- [outPath],- false,- "info"- );+ const probe = await RenderInternals.callFf({+ bin: "ffprobe",+ args: [outPath],+ indent: false,+ logLevel: "info",+ });expect(probe.stderr).toMatch(/Video: h264/);RenderInternals.deleteDirectory(framesDir);diff --git a/packages/lambda/src/test/integration/renders/gif.test.ts b/packages/lambda/src/test/integration/renders/gif.test.tsindex 31601ada4b..95ba85c4d6 100644--- a/packages/lambda/src/test/integration/renders/gif.test.ts+++ b/packages/lambda/src/test/integration/renders/gif.test.ts@@ -99,11 +99,11 @@ test('Should make a distributed GIF', async () => {await new Promise<void>((resolve) => {file.pipe(createWriteStream('gif.gif')).on('close', () => resolve());});- const probe = await RenderInternals.callFf(- 'ffprobe',- ['gif.gif'],- false,- 'info',- );+ const probe = await RenderInternals.callFf({+ bin: 'ffprobe',+ args: ['gif.gif'],+ indent: false,+ logLevel: 'info',+ });expect(probe.stderr).toMatch(/Video: gif, bgra, 1080x1080/);}, 90000);diff --git a/packages/lambda/src/test/integration/renders/other-bucket.test.ts b/packages/lambda/src/test/integration/renders/other-bucket.test.tsindex 7c9546ebe4..3991055d3f 100644--- a/packages/lambda/src/test/integration/renders/other-bucket.test.ts+++ b/packages/lambda/src/test/integration/renders/other-bucket.test.ts@@ -99,8 +99,14 @@ test('Should be able to render to another bucket', async () => {expectedBucketOwner: 'abc',region: 'eu-central-1',});- const probe = await RenderInternals.callFf('ffprobe', ['-'], false, 'info', {- stdin: file,+ const probe = await RenderInternals.callFf({+ bin: 'ffprobe',+ args: ['-'],+ indent: false,+ logLevel: 'info',+ options: {+ stdin: file,+ },});expect(probe.stderr).toMatch(/Stream #0:0/);expect(probe.stderr).toMatch(/Video: h264/);diff --git a/packages/lambda/src/test/integration/renders/silent-audio.test.ts b/packages/lambda/src/test/integration/renders/silent-audio.test.tsindex 1d962eaef1..28edf8c2f2 100644--- a/packages/lambda/src/test/integration/renders/silent-audio.test.ts+++ b/packages/lambda/src/test/integration/renders/silent-audio.test.ts@@ -96,8 +96,14 @@ test('Should add silent audio if there is no audio', async () => {expectedBucketOwner: 'abc',region: 'eu-central-1',});- const probe = await RenderInternals.callFf('ffprobe', ['-'], false, 'info', {- stdin: file,+ const probe = await RenderInternals.callFf({+ bin: 'ffprobe',+ args: ['-'],+ indent: false,+ logLevel: 'info',+ options: {+ stdin: file,+ },});expect(probe.stderr).toMatch(/Stream #0:0/);expect(probe.stderr).toMatch(/Video: h264/);diff --git a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts b/packages/lambda/src/test/integration/renders/transparent-webm.test.tsindex 19b58edb11..8f83dea660 100644--- a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts+++ b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts@@ -108,7 +108,12 @@ test('Should make a transparent video', async () => {await new Promise<void>((resolve) => {file.on('close', () => resolve());});- const probe = await RenderInternals.callFf('ffprobe', [out], false, 'info');+ const probe = await RenderInternals.callFf({+ bin: 'ffprobe',+ args: [out],+ indent: false,+ logLevel: 'info',+ });expect(probe.stderr).toMatch(/ALPHA_MODE(\s+): 1/);expect(probe.stderr).toMatch(/Video: vp8, yuv420p/);expect(probe.stderr).toMatch(/Audio: opus, 48000 Hz/);diff --git a/packages/renderer/src/assets/get-audio-channels.ts b/packages/renderer/src/assets/get-audio-channels.tsindex 9064ed439e..e93782c955 100644--- a/packages/renderer/src/assets/get-audio-channels.ts+++ b/packages/renderer/src/assets/get-audio-channels.ts@@ -22,7 +22,7 @@ export const getAudioChannelsAndDurationWithoutCache = async (.reduce<(string | null)[]>((acc, val) => acc.concat(val), []).filter(Boolean) as string[];- const task = await callFf('ffprobe', args, indent, logLevel);+ const task = await callFf({bin: 'ffprobe', args, indent, logLevel});const channels = task.stdout.match(/channels=([0-9]+)/);const duration = task.stdout.match(/duration=([0-9.]+)/);diff --git a/packages/renderer/src/call-ffmpeg.ts b/packages/renderer/src/call-ffmpeg.tsindex 425cf11806..e39c678cad 100644--- a/packages/renderer/src/call-ffmpeg.ts+++ b/packages/renderer/src/call-ffmpeg.ts@@ -5,12 +5,19 @@ import {getExecutablePath} from './compositor/get-executable-path';import type {LogLevel} from './log-level';import {truthy} from './truthy';-export const callFf = (- bin: 'ffmpeg' | 'ffprobe',- args: (string | null)[],- indent: boolean,- logLevel: LogLevel,-) => {+export const callFf = ({+ args,+ bin,+ indent,+ logLevel,+ options,+}: {+ bin: 'ffmpeg' | 'ffprobe';+ args: (string | null)[];+ indent: boolean;+ logLevel: LogLevel;+ options?: execa.Options<string>;+}) => {const executablePath = getExecutablePath(bin, indent, logLevel);if (!process.env.READ_ONLY_FS) {chmodSync(executablePath, 0o755);@@ -18,5 +25,6 @@ export const callFf = (return execa(executablePath, args.filter(truthy), {cwd: path.dirname(executablePath),+ ...options,});};diff --git a/packages/renderer/src/combine-videos.ts b/packages/renderer/src/combine-videos.tsindex 916b44be6a..a798612bf9 100644--- a/packages/renderer/src/combine-videos.ts+++ b/packages/renderer/src/combine-videos.ts@@ -86,7 +86,12 @@ export const combineVideos = async (options: Options) => {Log.verbose({indent, logLevel}, 'Combining command: ', command);try {- const task = callFf('ffmpeg', command, options.indent, options.logLevel);+ const task = callFf({+ bin: 'ffmpeg',+ args: command,+ indent: options.indent,+ logLevel: options.logLevel,+ });task.stderr?.on('data', (data: Buffer) => {if (onProgress) {const parsed = parseFfmpegProgress(data.toString('utf8'));diff --git a/packages/renderer/src/create-silent-audio.ts b/packages/renderer/src/create-silent-audio.tsindex 87d74cf56e..282638c8ae 100644--- a/packages/renderer/src/create-silent-audio.ts+++ b/packages/renderer/src/create-silent-audio.ts@@ -13,9 +13,9 @@ export const createSilentAudio = async ({indent: boolean;logLevel: LogLevel;}) => {- await callFf(- 'ffmpeg',- [+ await callFf({+ bin: 'ffmpeg',+ args: ['-f','lavfi','-i',@@ -30,5 +30,5 @@ export const createSilentAudio = async ({],indent,logLevel,- );+ });};diff --git a/packages/renderer/src/guess-extension-for-media.ts b/packages/renderer/src/guess-extension-for-media.tsindex 791e6d8463..cd015102e2 100644--- a/packages/renderer/src/guess-extension-for-media.ts+++ b/packages/renderer/src/guess-extension-for-media.ts@@ -10,7 +10,12 @@ export const guessExtensionForVideo = async ({indent: boolean;logLevel: LogLevel;}) => {- const {stderr} = await callFf('ffprobe', [src], indent, logLevel);+ const {stderr} = await callFf({+ bin: 'ffprobe',+ args: [src],+ indent,+ logLevel,+ });if (stderr.includes('Audio: mp3,')) {return 'mp3';}diff --git a/packages/renderer/src/merge-audio-track.ts b/packages/renderer/src/merge-audio-track.tsindex 33ec6fb162..ae3f2cf165 100644--- a/packages/renderer/src/merge-audio-track.ts+++ b/packages/renderer/src/merge-audio-track.ts@@ -101,7 +101,7 @@ const mergeAudioTrackUnlimited = async ({].filter(truthy).flat(2);- const task = callFf('ffmpeg', args, indent, logLevel);+ const task = callFf({bin: 'ffmpeg', args, indent, logLevel});await task;cleanup();};diff --git a/packages/renderer/src/preprocess-audio-track.ts b/packages/renderer/src/preprocess-audio-track.tsindex daedac95af..452e8b0f35 100644--- a/packages/renderer/src/preprocess-audio-track.ts+++ b/packages/renderer/src/preprocess-audio-track.ts@@ -64,7 +64,7 @@ const preprocessAudioTrackUnlimited = async ({['-y', outName],].flat(2);- await callFf('ffmpeg', args, indent, logLevel);+ await callFf({bin: 'ffmpeg', args, indent, logLevel});cleanup();return {outName, filter};diff --git a/packages/renderer/src/prespawn-ffmpeg.ts b/packages/renderer/src/prespawn-ffmpeg.tsindex b75d56dd02..414813a266 100644--- a/packages/renderer/src/prespawn-ffmpeg.ts+++ b/packages/renderer/src/prespawn-ffmpeg.ts@@ -131,12 +131,12 @@ export const prespawnFfmpeg = (options: PreStitcherOptions) => {? options.ffmpegOverride({type: 'pre-stitcher', args: ffmpegString}): ffmpegString;- const task = callFf(- 'ffmpeg',- finalFfmpegString,- options.indent,- options.logLevel,- );+ const task = callFf({+ bin: 'ffmpeg',+ args: finalFfmpegString,+ indent: options.indent,+ logLevel: options.logLevel,+ });options.signal(() => {task.kill();diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 781c6167ea..71a75a205e 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -369,9 +369,9 @@ const innerStitchFramesToVideo = async ();}- const ffmpegTask = callFf(- 'ffmpeg',- [+ const ffmpegTask = callFf({+ bin: 'ffmpeg',+ args: ['-i',audio,'-c:a',@@ -383,7 +383,7 @@ const innerStitchFramesToVideo = async (].filter(NoReactInternals.truthy),indent,logLevel,- );+ });cancelSignal?.(() => {ffmpegTask.kill();@@ -485,7 +485,12 @@ const innerStitchFramesToVideo = async (finalFfmpegString.join(' '),);- const task = callFf('ffmpeg', finalFfmpegString, indent, logLevel);+ const task = callFf({+ bin: 'ffmpeg',+ args: finalFfmpegString,+ indent,+ logLevel,+ });cancelSignal?.(() => {task.kill();});