🎥 Make videos programmatically with React
add LD_LIBRARY_PATH when spawning ffmpeg
Jonny Burger279927b8a46e
diff --git a/packages/it-tests/src/rendering/base64-audio.test.ts b/packages/it-tests/src/rendering/base64-audio.test.tsindex 35f6c40679..add3fff82b 100644--- a/packages/it-tests/src/rendering/base64-audio.test.ts+++ b/packages/it-tests/src/rendering/base64-audio.test.ts@@ -25,11 +25,7 @@ test("Should be able to render a MP3 audio file", async () => {const exists = fs.existsSync(outputPath);expect(exists).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [outputPath],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [outputPath]);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 cc15bf6679..a54b685de4 100644--- a/packages/it-tests/src/rendering/frame-accuracy-gif.test.ts+++ b/packages/it-tests/src/rendering/frame-accuracy-gif.test.ts@@ -37,18 +37,14 @@ const getMissedFramesforCodec = async () => {console.log(outputPath);- await execa(- await RenderInternals.getExecutablePath("ffmpeg"),- [- "-i",- outputPath,- "-f",- "image2",- path.join(outputDir, "out%2d.jpeg"),- "-y",- ],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ await RenderInternals.callFf("ffmpeg", [+ "-i",+ outputPath,+ "-f",+ "image2",+ path.join(outputDir, "out%2d.jpeg"),+ "-y",+ ]);let missedFrames = 0;diff --git a/packages/it-tests/src/rendering/frame-accuracy-video.test.ts b/packages/it-tests/src/rendering/frame-accuracy-video.test.tsindex 4f98053ed8..c24cbc6353 100644--- a/packages/it-tests/src/rendering/frame-accuracy-video.test.ts+++ b/packages/it-tests/src/rendering/frame-accuracy-video.test.ts@@ -27,20 +27,14 @@ const getMissedFramesforCodec = async () => {});- await execa(- await RenderInternals.getExecutablePath("ffmpeg"),- [- "-i",- outputPath,- "-f",- "image2",- path.join(outputDir, "out%3d.jpeg"),- "-y",- ],- {- cwd: RenderInternals.getExecutablePath("ffmpeg-cwd"),- }- );+ await RenderInternals.callFf("ffmpeg", [+ "-i",+ outputPath,+ "-f",+ "image2",+ path.join(outputDir, "out%3d.jpeg"),+ "-y",+ ]);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 b7e067b09e..d5b3288738 100644--- a/packages/it-tests/src/rendering/render-scale.test.ts+++ b/packages/it-tests/src/rendering/render-scale.test.ts@@ -38,13 +38,7 @@ test("Should be able to render video with scale 2", async () => {const exists = fs.existsSync(outputPath);expect(exists).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [outputPath],- {- cwd: RenderInternals.getExecutablePath("ffmpeg-cwd"),- }- );+ const info = await RenderInternals.callFf("ffprobe", [outputPath]);const data = info.stderr;expect(data).toContain("Video: h264");expect(data).toContain("yuv420p");@@ -78,11 +72,7 @@ test("Should be able to render video with scale 0.1", async () => {const exists = fs.existsSync(outputPath);expect(exists).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [outputPath],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [outputPath]);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 c351e2cd6b..22f9995913 100644--- a/packages/it-tests/src/rendering/rendering.test.ts+++ b/packages/it-tests/src/rendering/rendering.test.ts@@ -34,11 +34,7 @@ test("Should be able to render video with custom port", async () => {const exists = fs.existsSync(outputPath);expect(exists).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [outputPath],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [outputPath]);const data = info.stderr;expect(data).toContain("Video: h264");expect(data).toContain("yuv420p");@@ -138,11 +134,7 @@ test("Should render a ProRes video", async () => {const exists = fs.existsSync(out);expect(exists).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [out],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [out]);const data = info.stderr;expect(data.includes("prores (4444)") || data.includes("prores (ap4h")).toBe(true@@ -164,11 +156,7 @@ 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 execa(- await RenderInternals.getExecutablePath("ffprobe"),- [outImg],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [outImg]);const data = info.stderr;expect(data).toContain("Video: png");expect(data).toContain("png_pipe");@@ -191,11 +179,7 @@ test("Should be able to render a WAV audio file", async () => {const exists = fs.existsSync(out);expect(exists).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [out],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [out]);const data = info.stderr;expect(data).toContain("pcm_s16le");expect(data).toContain("2 channels");@@ -220,11 +204,7 @@ test("Should be able to render a MP3 audio file", async () => {const exists = fs.existsSync(out);expect(exists).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [out],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [out]);const data = info.stderr;expect(data).toContain("mp3");expect(data).toContain("stereo");@@ -250,13 +230,7 @@ test("Should be able to render a AAC audio file", async () => {const exists = fs.existsSync(out);expect(exists).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [out],- {- cwd: RenderInternals.getExecutablePath("ffmpeg-cwd"),- }- );+ const info = await RenderInternals.callFf("ffprobe", [out]);const data = info.stderr;expect(data).toContain("aac");expect(data).toContain("stereo");@@ -280,11 +254,7 @@ test("Should render a video with GIFs", async () => {expect(task.exitCode).toBe(0);expect(fs.existsSync(outputPath)).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [outputPath],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [outputPath]);const data = info.stderr;expect(data).toContain("Video: h264");@@ -307,11 +277,7 @@ test("Should render a video with Offline Audio-context", async () => {expect(task.exitCode).toBe(0);expect(fs.existsSync(out)).toBe(true);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [out],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [out]);const data = info.stderr;expect(data).toContain("Stream #0:0: Audio: mp3");expect(data).toContain("48000 Hz, stereo");@@ -329,11 +295,7 @@ test("Should succeed to render an audio file that doesn't have any audio inputs"});expect(task.exitCode).toBe(0);- const info = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [out],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const info = await RenderInternals.callFf("ffprobe", [out]);const data = info.stderr;expect(data).toContain("Duration: 00:00:00.36");expect(data).toContain("Audio: mp3, 48000 Hz");@@ -382,13 +344,7 @@ 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 execa(- await RenderInternals.getExecutablePath("ffprobe"),- [outputPath],- {- cwd: RenderInternals.getExecutablePath("ffmpeg-cwd"),- }- );+ const info = await RenderInternals.callFf("ffprobe", [outputPath]);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 5e731bea9c..3fd4171bec 100644--- a/packages/it-tests/src/ssr/render-frames.test.ts+++ b/packages/it-tests/src/ssr/render-frames.test.ts@@ -58,11 +58,7 @@ test("Legacy SSR way of rendering videos should still work", async () => {codec: "h264",});expect(fs.existsSync(outPath)).toBe(true);- const probe = await execa(- await RenderInternals.getExecutablePath("ffprobe"),- [outPath],- { cwd: RenderInternals.getExecutablePath("ffmpeg-cwd") }- );+ const probe = await RenderInternals.callFf("ffprobe", [outPath]);expect(probe.stderr).toMatch(/Video: h264/);await puppeteerInstance.close();});diff --git a/packages/lambda/src/test/integration/renders/gif.test.ts b/packages/lambda/src/test/integration/renders/gif.test.tsindex 0db2c68234..06d7737ee6 100644--- a/packages/lambda/src/test/integration/renders/gif.test.ts+++ b/packages/lambda/src/test/integration/renders/gif.test.ts@@ -93,10 +93,6 @@ test('Should make a distributed GIF', async () => {await new Promise<void>((resolve) => {file.pipe(createWriteStream('gif.gif')).on('close', () => resolve());});- const probe = await RenderInternals.execa(- await RenderInternals.getExecutablePath('ffprobe'),- ['gif.gif'],- {cwd: RenderInternals.getExecutablePath('ffmpeg-cwd')}- );+ const probe = await RenderInternals.callFf('ffprobe', ['gif.gif']);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 975334dd84..c0900f1ab2 100644--- a/packages/lambda/src/test/integration/renders/other-bucket.test.ts+++ b/packages/lambda/src/test/integration/renders/other-bucket.test.ts@@ -93,14 +93,9 @@ test('Should be able to render to another bucket', async () => {expectedBucketOwner: 'abc',region: 'eu-central-1',});- const probe = await RenderInternals.execa(- await RenderInternals.getExecutablePath('ffprobe'),- ['-'],- {- stdin: file,- cwd: RenderInternals.getExecutablePath('ffmpeg-cwd'),- }- );+ const probe = await RenderInternals.callFf('ffprobe', ['-'], {+ stdin: file,+ });expect(probe.stderr).toMatch(/Stream #0:0/);expect(probe.stderr).toMatch(/Video: h264/);expect(probe.stderr).toMatch(/Stream #0:1/);diff --git a/packages/lambda/src/test/integration/renders/silent-audio.test.ts b/packages/lambda/src/test/integration/renders/silent-audio.test.tsindex c90149131c..0d68c4522d 100644--- a/packages/lambda/src/test/integration/renders/silent-audio.test.ts+++ b/packages/lambda/src/test/integration/renders/silent-audio.test.ts@@ -90,14 +90,9 @@ test('Should add silent audio if there is no audio', async () => {expectedBucketOwner: 'abc',region: 'eu-central-1',});- const probe = await RenderInternals.execa(- await RenderInternals.getExecutablePath('ffprobe'),- ['-'],- {- stdin: file,- cwd: RenderInternals.getExecutablePath('ffmpeg-cwd'),- }- );+ const probe = await RenderInternals.callFf('ffprobe', ['-'], {+ stdin: file,+ });expect(probe.stderr).toMatch(/Stream #0:0/);expect(probe.stderr).toMatch(/Video: h264/);expect(probe.stderr).toMatch(/Stream #0:1/);diff --git a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts b/packages/lambda/src/test/integration/renders/transparent-webm.test.tsindex 1d5c2727c2..06538acdf1 100644--- a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts+++ b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts@@ -104,11 +104,7 @@ test('Should make a transparent video', async () => {await new Promise<void>((resolve) => {file.on('close', () => resolve());});- const probe = await RenderInternals.execa(- await RenderInternals.getExecutablePath('ffprobe'),- [out],- {cwd: RenderInternals.getExecutablePath('ffmpeg-cwd')}- );+ const probe = await RenderInternals.callFf('ffprobe', [out]);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 43f41e4c2b..bcb76ef0f3 100644--- a/packages/renderer/src/assets/get-audio-channels.ts+++ b/packages/renderer/src/assets/get-audio-channels.ts@@ -1,5 +1,4 @@-import execa from 'execa';-import {getExecutablePath} from '../compositor/get-executable-path';+import {callFf} from '../call-ffmpeg';import {pLimit} from '../p-limit';import type {AudioChannelsAndDurationResultCache,@@ -25,9 +24,7 @@ async function getAudioChannelsAndDurationUnlimited(.reduce<(string | null)[]>((acc, val) => acc.concat(val), []).filter(Boolean) as string[];- const task = await execa(getExecutablePath('ffprobe'), args, {- cwd: getExecutablePath('ffmpeg-cwd'),- });+ const task = await callFf('ffprobe', args);const channels = task.stdout.match(/channels=([0-9]+)/);const duration = task.stdout.match(/duration=([0-9.]+)/);diff --git a/packages/renderer/src/assets/get-video-stream-duration.ts b/packages/renderer/src/assets/get-video-stream-duration.tsindex 945c70f928..2f86fa09ac 100644--- a/packages/renderer/src/assets/get-video-stream-duration.ts+++ b/packages/renderer/src/assets/get-video-stream-duration.ts@@ -1,5 +1,4 @@-import execa from 'execa';-import {getExecutablePath} from '../compositor/get-executable-path';+import {RenderInternals} from '..';import {pLimit} from '../p-limit';import type {DownloadMap, VideoDurationResult} from './download-map';@@ -58,9 +57,7 @@ export async function getVideoStreamDurationwithoutCache({src}: {src: string}) {.reduce<(string | null)[]>((acc, val) => acc.concat(val), []).filter(Boolean) as string[];- const task = await execa(getExecutablePath('ffprobe'), args, {- cwd: getExecutablePath('ffmpeg-cwd'),- });+ const task = await RenderInternals.callFf('ffprobe', args);const result: VideoDurationResult = parseVideoStreamDuration(task.stdout);diff --git a/packages/renderer/src/call-ffmpeg.ts b/packages/renderer/src/call-ffmpeg.tsnew file mode 100644index 0000000000..8783760df5--- /dev/null+++ b/packages/renderer/src/call-ffmpeg.ts@@ -0,0 +1,27 @@+import execa from 'execa';+import path from 'path';+import {getExecutablePath} from './compositor/get-executable-path';+import {truthy} from './truthy';++export const callFfExtraOptions = () => {+ return {+ cwd: getExecutablePath('ffmpeg-cwd'),+ env:+ process.platform === 'darwin'+ ? undefined+ : {+ LD_LIBRARY_PATH: path.join(getExecutablePath('ffmpeg-cwd'), 'lib'),+ },+ };+};++export const callFf = (+ bin: 'ffmpeg' | 'ffprobe',+ args: (string | null)[],+ options?: execa.Options<string>+) => {+ return execa(getExecutablePath(bin), args.filter(truthy), {+ ...callFfExtraOptions(),+ ...options,+ });+};diff --git a/packages/renderer/src/combine-videos.ts b/packages/renderer/src/combine-videos.tsindex a4bb3c5d70..7b07b80088 100644--- a/packages/renderer/src/combine-videos.ts+++ b/packages/renderer/src/combine-videos.ts@@ -1,6 +1,5 @@// Combine multiple video chunks, useful for decentralized rendering-import execa from 'execa';import {rmdirSync, rmSync, writeFileSync} from 'fs';import {join} from 'path';import type {AudioCodec} from './audio-codec';@@ -8,8 +7,8 @@ import {getDefaultAudioCodec,mapAudioCodecToFfmpegAudioCodecName,} from './audio-codec';+import {callFf} from './call-ffmpeg';import type {Codec} from './codec';-import {getExecutablePath} from './compositor/get-executable-path';import {isAudioCodec} from './is-audio-codec';import {parseFfmpegProgress} from './parse-ffmpeg-progress';import {truthy} from './truthy';@@ -47,8 +46,8 @@ export const combineVideos = async (options: Options) => {audioCodec ?? getDefaultAudioCodec({codec, preferLossless: false});try {- const task = execa(- getExecutablePath('ffmpeg'),+ const task = callFf(+ 'ffmpeg',[isAudioCodec(codec) ? null : '-r',isAudioCodec(codec) ? null : String(fps),@@ -77,8 +76,7 @@ export const combineVideos = async (options: Options) => {codec === 'h264' ? 'faststart' : null,'-y',output,- ].filter(truthy),- {cwd: getExecutablePath('ffmpeg-cwd')}+ ].filter(truthy));task.stderr?.on('data', (data: Buffer) => {if (onProgress) {diff --git a/packages/renderer/src/compositor/compose.ts b/packages/renderer/src/compositor/compose.tsindex 46f5aa8c33..208c43c30c 100644--- a/packages/renderer/src/compositor/compose.ts+++ b/packages/renderer/src/compositor/compose.ts@@ -2,6 +2,7 @@ import {spawn} from 'child_process';import {createHash} from 'crypto';import {copyFile} from 'fs/promises';import type {DownloadMap} from '../assets/download-map';+import {callFfExtraOptions} from '../call-ffmpeg';import {getExecutablePath} from './get-executable-path';import type {CliInput,@@ -50,7 +51,7 @@ export const compose = async ({};await new Promise<void>((resolve, reject) => {- const child = spawn(bin, {cwd: getExecutablePath('ffmpeg-cwd')});+ const child = spawn(bin, {...callFfExtraOptions()});child.stdin.write(JSON.stringify(payload));child.stdin.end();diff --git a/packages/renderer/src/compositor/get-executable-path.ts b/packages/renderer/src/compositor/get-executable-path.tsindex 843a2e5f72..3ad5d84923 100644--- a/packages/renderer/src/compositor/get-executable-path.ts+++ b/packages/renderer/src/compositor/get-executable-path.ts@@ -8,7 +8,7 @@ function isMusl() {export const getExecutablePath = (type: 'compositor' | 'ffmpeg' | 'ffprobe' | 'ffmpeg-cwd'-) => {+): string => {const key =type === 'compositor'? 'binaryPath'diff --git a/packages/renderer/src/convert-to-pcm.ts b/packages/renderer/src/convert-to-pcm.tsindex da3c43abe0..c428fafe0b 100644--- a/packages/renderer/src/convert-to-pcm.ts+++ b/packages/renderer/src/convert-to-pcm.ts@@ -1,5 +1,4 @@-import execa from 'execa';-import {getExecutablePath} from './compositor/get-executable-path';+import {RenderInternals} from '.';import {DEFAULT_SAMPLE_RATE} from './sample-rate';export const convertToPcm = async ({@@ -9,19 +8,13 @@ export const convertToPcm = async ({input: string;outName: string;}) => {- await execa(- getExecutablePath('ffmpeg'),- [- '-i',- input,- '-c:a',- 'pcm_s16le',- '-ar',- String(DEFAULT_SAMPLE_RATE),- outName,- ],- {- cwd: getExecutablePath('ffmpeg-cwd'),- }- );+ await RenderInternals.callFf('ffmpeg', [+ '-i',+ input,+ '-c:a',+ 'pcm_s16le',+ '-ar',+ String(DEFAULT_SAMPLE_RATE),+ outName,+ ]);};diff --git a/packages/renderer/src/create-silent-audio.ts b/packages/renderer/src/create-silent-audio.tsindex f0abf43b9c..da474a6c52 100644--- a/packages/renderer/src/create-silent-audio.ts+++ b/packages/renderer/src/create-silent-audio.ts@@ -1,5 +1,4 @@-import execa from 'execa';-import {getExecutablePath} from './compositor/get-executable-path';+import {RenderInternals} from '.';import {DEFAULT_SAMPLE_RATE} from './sample-rate';export const createSilentAudio = async ({@@ -9,23 +8,17 @@ export const createSilentAudio = async ({numberOfSeconds: number;outName: string;}) => {- await execa(- getExecutablePath('ffmpeg'),- [- '-f',- 'lavfi',- '-i',- `anullsrc=r=${DEFAULT_SAMPLE_RATE}`,- '-c:a',- 'pcm_s16le',- '-t',- String(numberOfSeconds),- '-ar',- String(DEFAULT_SAMPLE_RATE),- outName,- ],- {- cwd: getExecutablePath('ffmpeg-cwd'),- }- );+ await RenderInternals.callFf('ffmpeg', [+ '-f',+ 'lavfi',+ '-i',+ `anullsrc=r=${DEFAULT_SAMPLE_RATE}`,+ '-c:a',+ 'pcm_s16le',+ '-t',+ String(numberOfSeconds),+ '-ar',+ String(DEFAULT_SAMPLE_RATE),+ outName,+ ]);};diff --git a/packages/renderer/src/ensure-presentation-timestamp.ts b/packages/renderer/src/ensure-presentation-timestamp.tsindex 72e8fae20e..832e22e0c0 100644--- a/packages/renderer/src/ensure-presentation-timestamp.ts+++ b/packages/renderer/src/ensure-presentation-timestamp.ts@@ -1,7 +1,6 @@-import execa from 'execa';import path from 'path';+import {RenderInternals} from '.';import type {DownloadMap} from './assets/download-map';-import {getExecutablePath} from './compositor/get-executable-path';import {guessExtensionForVideo} from './guess-extension-for-media';import {truthy} from './truthy';@@ -45,24 +44,18 @@ export const ensurePresentationTimestampWithoutCache = async ({src,});- await execa(- getExecutablePath('ffmpeg'),- [- '-i',- src,- '-fflags',- '+genpts+igndts',- '-vcodec',- 'copy',- '-acodec',- 'copy',- output,- '-y',- ],- {- cwd: getExecutablePath('ffmpeg-cwd'),- }- );+ await RenderInternals.callFf('ffmpeg', [+ '-i',+ src,+ '-fflags',+ '+genpts+igndts',+ '-vcodec',+ 'copy',+ '-acodec',+ 'copy',+ output,+ '-y',+ ]);return output;};diff --git a/packages/renderer/src/extract-frame-from-video.ts b/packages/renderer/src/extract-frame-from-video.tsindex 91d1fe3e51..87648a2ba0 100644--- a/packages/renderer/src/extract-frame-from-video.ts+++ b/packages/renderer/src/extract-frame-from-video.ts@@ -1,8 +1,7 @@-import execa from 'execa';import type {OffthreadVideoImageFormat} from 'remotion';+import {RenderInternals} from '.';import type {DownloadMap} from './assets/download-map';import {getVideoStreamDuration} from './assets/get-video-stream-duration';-import {getExecutablePath} from './compositor/get-executable-path';import {determineResizeParams} from './determine-resize-params';import {determineVcodecFfmpegFlags} from './determine-vcodec-ffmpeg-flags';import {ensurePresentationTimestamps} from './ensure-presentation-timestamp';@@ -146,8 +145,8 @@ const extractFrameFromVideoFn = async ({}const ffmpegTimestamp = frameToFfmpegTimestamp(time);- const {stdout, stderr} = execa(- getExecutablePath('ffmpeg'),+ const {stdout, stderr} = RenderInternals.callFf(+ 'ffmpeg',['-ss',ffmpegTimestamp,@@ -165,7 +164,6 @@ const extractFrameFromVideoFn = async ({].filter(truthy),{buffer: false,- cwd: getExecutablePath('ffmpeg-cwd'),});diff --git a/packages/renderer/src/get-frame-of-video-slow.ts b/packages/renderer/src/get-frame-of-video-slow.tsindex 3c347540d2..49ac52c9ab 100644--- a/packages/renderer/src/get-frame-of-video-slow.ts+++ b/packages/renderer/src/get-frame-of-video-slow.ts@@ -1,9 +1,8 @@// Uses no seeking, therefore the whole video has to be decoded. This is a last resort and should only happen// if the video is corrupted-import execa from 'execa';import type {OffthreadVideoImageFormat} from 'remotion';+import {RenderInternals} from '.';import type {SpecialVCodecForTransparency} from './assets/download-map';-import {getExecutablePath} from './compositor/get-executable-path';import {determineResizeParams} from './determine-resize-params';import {determineVcodecFfmpegFlags} from './determine-vcodec-ffmpeg-flags';import {truthy} from './truthy';@@ -45,9 +44,7 @@ export const getFrameOfVideoSlow = async ({'-',].filter(truthy);- const {stdout, stderr} = execa(getExecutablePath('ffmpeg'), command, {- cwd: getExecutablePath('ffmpeg-cwd'),- });+ const {stdout, stderr} = RenderInternals.callFf('ffmpeg', command);if (!stderr) {throw new Error('unexpectedly did not get stderr');diff --git a/packages/renderer/src/get-video-info.ts b/packages/renderer/src/get-video-info.tsindex 9ad0f7d314..e989e4fa1b 100644--- a/packages/renderer/src/get-video-info.ts+++ b/packages/renderer/src/get-video-info.ts@@ -1,7 +1,6 @@-import execa from 'execa';+import {RenderInternals} from '.';import type {DownloadMap, Vp9Result} from './assets/download-map';import {calculateDisplayVideoSize} from './calculate-sar-dar-pixels';-import {getExecutablePath} from './compositor/get-executable-path';import {pLimit} from './p-limit';const limit = pLimit(1);@@ -11,9 +10,7 @@ export async function getVideoInfoUncached({}: {src: string;}): Promise<Vp9Result> {- const task = await execa(getExecutablePath('ffprobe'), [src], {- cwd: getExecutablePath('ffmpeg-cwd'),- });+ const task = await RenderInternals.callFf('ffprobe', [src]);const isVp9 = task.stderr.includes('Video: vp9');const isVp8 = task.stderr.includes('Video: vp8');diff --git a/packages/renderer/src/guess-extension-for-media.ts b/packages/renderer/src/guess-extension-for-media.tsindex 02da232b1e..5216ecf546 100644--- a/packages/renderer/src/guess-extension-for-media.ts+++ b/packages/renderer/src/guess-extension-for-media.ts@@ -1,10 +1,7 @@-import execa from 'execa';-import {getExecutablePath} from './compositor/get-executable-path';+import {callFf} from './call-ffmpeg';export const guessExtensionForVideo = async ({src}: {src: string}) => {- const {stderr} = await execa(getExecutablePath('ffprobe'), [src], {- cwd: getExecutablePath('ffmpeg-cwd'),- });+ const {stderr} = await callFf('ffprobe', [src]);if (stderr.includes('mp3,')) {return 'mp3';diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.tsindex 3a1844b7ee..7e6f9da924 100644--- a/packages/renderer/src/index.ts+++ b/packages/renderer/src/index.ts@@ -4,6 +4,7 @@ import {cleanDownloadMap, makeDownloadMap} from './assets/download-map';import {getDefaultAudioCodec, validAudioCodecs} from './audio-codec';import {DEFAULT_BROWSER} from './browser';import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';+import {callFf} from './call-ffmpeg';import {canUseParallelEncoding} from './can-use-parallel-encoding';import {checkNodeVersionAndWarnAboutRosetta} from './check-apple-silicon';import {DEFAULT_CODEC, validCodecs} from './codec';@@ -154,6 +155,7 @@ export const RenderInternals = {makeFileExtensionMap,defaultCodecsForFileExtension,getExecutablePath,+ callFf,};// Warn of potential performance issues with Apple Silicon (M1 chip under Rosetta)diff --git a/packages/renderer/src/merge-audio-track.ts b/packages/renderer/src/merge-audio-track.tsindex 4b6e44aae5..068b0b53b0 100644--- a/packages/renderer/src/merge-audio-track.ts+++ b/packages/renderer/src/merge-audio-track.ts@@ -1,8 +1,7 @@-import execa from 'execa';import path from 'path';import type {DownloadMap} from './assets/download-map';+import {callFf} from './call-ffmpeg';import {chunk} from './chunk';-import {getExecutablePath} from './compositor/get-executable-path';import {convertToPcm} from './convert-to-pcm';import {createFfmpegComplexFilter} from './create-ffmpeg-complex-filter';import {createSilentAudio} from './create-silent-audio';@@ -84,9 +83,7 @@ const mergeAudioTrackUnlimited = async ({].filter(truthy).flat(2);- const task = execa(getExecutablePath('ffmpeg'), args, {- cwd: getExecutablePath('ffmpeg-cwd'),- });+ const task = callFf('ffmpeg', args);await task;cleanup();};diff --git a/packages/renderer/src/preprocess-audio-track.ts b/packages/renderer/src/preprocess-audio-track.tsindex c06ba22c60..1eacc95b0a 100644--- a/packages/renderer/src/preprocess-audio-track.ts+++ b/packages/renderer/src/preprocess-audio-track.ts@@ -1,9 +1,8 @@-import execa from 'execa';import type {DownloadMap} from './assets/download-map';import {getAudioChannelsAndDuration} from './assets/get-audio-channels';import type {MediaAsset} from './assets/types';import {calculateFfmpegFilter} from './calculate-ffmpeg-filters';-import {getExecutablePath} from './compositor/get-executable-path';+import {callFf} from './call-ffmpeg';import {makeFfmpegFilterFile} from './ffmpeg-filter-file';import {pLimit} from './p-limit';import {resolveAssetSrc} from './resolve-asset-src';@@ -50,9 +49,7 @@ const preprocessAudioTrackUnlimited = async ({['-y', outName],].flat(2);- await execa(getExecutablePath('ffmpeg'), args, {- cwd: getExecutablePath('ffmpeg-cwd'),- });+ await callFf('ffmpeg', args);cleanup();return outName;diff --git a/packages/renderer/src/prespawn-ffmpeg.ts b/packages/renderer/src/prespawn-ffmpeg.tsindex 5371976b0d..d1f70989b4 100644--- a/packages/renderer/src/prespawn-ffmpeg.ts+++ b/packages/renderer/src/prespawn-ffmpeg.ts@@ -1,5 +1,5 @@-import execa from 'execa';import {Internals} from 'remotion';+import {callFf} from './call-ffmpeg';import type {Codec} from './codec';import {DEFAULT_CODEC} from './codec';import {getExecutablePath} from './compositor/get-executable-path';@@ -122,9 +122,7 @@ export const prespawnFfmpeg = (options: PreSticherOptions) => {? options.ffmpegOverride({type: 'pre-stitcher', args: ffmpegString}): ffmpegString;- const task = execa(getExecutablePath('ffmpeg'), finalFfmpegString, {- cwd: getExecutablePath('ffmpeg-cwd'),- });+ const task = callFf('ffmpeg', finalFfmpegString);options.signal(() => {task.kill();diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex de572ab050..ba219d4e56 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -1,8 +1,8 @@-import execa from 'execa';import fs, {promises} from 'fs';import path from 'path';import type {TAsset} from 'remotion';import {Internals} from 'remotion';+import {RenderInternals} from '.';import {calculateAssetPositions} from './assets/calculate-asset-positions';import {convertAssetsToFileUrls} from './assets/convert-assets-to-file-urls';import type {RenderMediaOnDownload} from './assets/download-and-map-assets-to-file';@@ -14,6 +14,7 @@ import {getDefaultAudioCodec,mapAudioCodecToFfmpegAudioCodecName,} from './audio-codec';+import {callFf} from './call-ffmpeg';import type {Codec} from './codec';import {DEFAULT_CODEC} from './codec';import {codecSupportsMedia} from './codec-supports-media';@@ -279,8 +280,8 @@ export const spawnFfmpeg = async ();}- const ffmpegTask = execa(- getExecutablePath('ffmpeg'),+ const ffmpegTask = callFf(+ 'ffmpeg',['-i',audio,@@ -291,8 +292,7 @@ export const spawnFfmpeg = async (options.audioBitrate ?? '320k',options.force ? '-y' : null,options.outputLocation ?? tempFile,- ].filter(Internals.truthy),- {cwd: getExecutablePath('ffmpeg-cwd')}+ ].filter(Internals.truthy));options.cancelSignal?.(() => {@@ -395,9 +395,8 @@ export const spawnFfmpeg = async (console.log(finalFfmpegString);}- const task = execa(getExecutablePath('ffmpeg'), finalFfmpegString, {- // TODO: overriden from `options.dir`- cwd: getExecutablePath('ffmpeg-cwd'),+ const task = RenderInternals.callFf('ffmpeg', finalFfmpegString, {+ // TODO: cwd overriden from `options.dir`});options.cancelSignal?.(() => {task.kill();diff --git a/packages/renderer/src/try-to-extract-frame-of-video-fast.ts b/packages/renderer/src/try-to-extract-frame-of-video-fast.tsindex a39c40077f..90dbb6a37d 100644--- a/packages/renderer/src/try-to-extract-frame-of-video-fast.ts+++ b/packages/renderer/src/try-to-extract-frame-of-video-fast.ts@@ -1,10 +1,9 @@-import execa from 'execa';import type {OffthreadVideoImageFormat} from 'remotion';+import {RenderInternals} from '.';import type {NeedsResize,SpecialVCodecForTransparency,} from './assets/download-map';-import {getExecutablePath} from './compositor/get-executable-path';import {determineResizeParams} from './determine-resize-params';import {determineVcodecFfmpegFlags} from './determine-vcodec-ffmpeg-flags';import {truthy} from './truthy';@@ -22,8 +21,8 @@ export const tryToExtractFrameOfVideoFast = async ({specialVCodecForTransparency: SpecialVCodecForTransparency;actualOffset: string;}) => {- const {stdout, stderr} = execa(- getExecutablePath('ffmpeg'),+ const {stdout, stderr} = RenderInternals.callFf(+ 'ffmpeg',['-ss',actualOffset,@@ -38,10 +37,7 @@ export const tryToExtractFrameOfVideoFast = async ({'image2pipe',...determineResizeParams(needsResize),'-',- ].filter(truthy),- {- cwd: getExecutablePath('ffmpeg-cwd'),- }+ ].filter(truthy));if (!stderr) {throw new Error('unexpectedly did not get stderr');