Skip to content

🎥 Make videos programmatically with React

new arch!

Jonny Burger2e385bd063df
diff --git a/packages/renderer/src/call-ffmpeg.ts b/packages/renderer/src/call-ffmpeg.ts
index f29af81028..425cf11806 100644
--- a/packages/renderer/src/call-ffmpeg.ts
+++ b/packages/renderer/src/call-ffmpeg.ts
@@ -1,39 +1,15 @@
import execa from 'execa';
import {chmodSync} from 'node:fs';
+import path from 'path';
import {getExecutablePath} from './compositor/get-executable-path';
import type {LogLevel} from './log-level';
import {truthy} from './truthy';
-export const dynamicLibraryPathOptions = (
- indent: boolean,
- logLevel: LogLevel,
-) => {
- const lib = getExecutablePath('lib', indent, logLevel);
-
- return {
- env: {
- RUST_BACKTRACE: 'full',
- ...(process.platform === 'darwin'
- ? {
- DYLD_LIBRARY_PATH: lib,
- }
- : process.platform === 'win32'
- ? {
- PATH: `${lib};${process.env.PATH}`,
- }
- : {
- LD_LIBRARY_PATH: lib,
- }),
- },
- };
-};
-
export const callFf = (
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) {
@@ -41,7 +17,6 @@ export const callFf = (
}
return execa(executablePath, args.filter(truthy), {
- ...dynamicLibraryPathOptions(indent, logLevel),
- ...options,
+ cwd: path.dirname(executablePath),
});
};
diff --git a/packages/renderer/src/compositor/compose.ts b/packages/renderer/src/compositor/compose.ts
index 797b62233a..045d613e84 100644
--- a/packages/renderer/src/compositor/compose.ts
+++ b/packages/renderer/src/compositor/compose.ts
@@ -2,8 +2,8 @@ import {spawn} from 'node:child_process';
import {createHash} from 'node:crypto';
import {chmodSync} from 'node:fs';
import {copyFile} from 'node:fs/promises';
+import path from 'node:path';
import type {DownloadMap} from '../assets/download-map';
-import {dynamicLibraryPathOptions} from '../call-ffmpeg';
import type {LogLevel} from '../log-level';
import type {Compositor} from './compositor';
import {getExecutablePath} from './get-executable-path';
@@ -106,11 +106,9 @@ export const callCompositor = (
chmodSync(execPath, 0o755);
}
- const child = spawn(
- execPath,
- [payload],
- dynamicLibraryPathOptions(indent, logLevel),
- );
+ const child = spawn(execPath, [payload], {
+ cwd: path.dirname(execPath),
+ });
const stderrChunks: Buffer[] = [];
child.stderr.on('data', (d) => stderrChunks.push(d));
diff --git a/packages/renderer/src/compositor/compositor.ts b/packages/renderer/src/compositor/compositor.ts
index 4a15620e00..6568b68e98 100644
--- a/packages/renderer/src/compositor/compositor.ts
+++ b/packages/renderer/src/compositor/compositor.ts
@@ -1,6 +1,6 @@
import {spawn} from 'node:child_process';
import {chmodSync} from 'node:fs';
-import {dynamicLibraryPathOptions} from '../call-ffmpeg';
+import path from 'node:path';
import {getActualConcurrency} from '../get-concurrency';
import type {LogLevel} from '../log-level';
import {isEqualOrBelowLogLevel} from '../log-level';
@@ -80,11 +80,9 @@ export const startCompositor = <T extends keyof CompositorCommand>(
payload,
);
- const child = spawn(
- bin,
- [JSON.stringify(fullCommand)],
- dynamicLibraryPathOptions(indent, logLevel),
- );
+ const child = spawn(bin, [JSON.stringify(fullCommand)], {
+ cwd: path.dirname(bin),
+ });
const stderrChunks: Buffer[] = [];
let outputBuffer = Buffer.from('');
diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.ts
index 7d49767e45..967ca48ee7 100644
--- a/packages/renderer/src/index.ts
+++ b/packages/renderer/src/index.ts
@@ -8,7 +8,7 @@ import {
import {DEFAULT_BROWSER} from './browser';
import {HeadlessBrowser} from './browser/Browser';
import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
-import {callFf, dynamicLibraryPathOptions} from './call-ffmpeg';
+import {callFf} from './call-ffmpeg';
import {canUseParallelEncoding} from './can-use-parallel-encoding';
import {chalk} from './chalk';
import {isColorSupported} from './chalk/is-color-supported';
@@ -196,7 +196,6 @@ export const RenderInternals = {
defaultCodecsForFileExtension,
getExecutablePath,
callFf,
- dynamicLibraryPathOptions,
validStillImageFormats,
validVideoImageFormats,
DEFAULT_STILL_IMAGE_FORMAT,
diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.ts
index 6f671d53e9..a390e15c28 100644
--- a/packages/renderer/src/render-frames.ts
+++ b/packages/renderer/src/render-frames.ts
@@ -351,6 +351,8 @@ const innerRenderFrames = async ({
stopped = true;
});
+ const frameDir = outputDir ?? downloadMap.compositingDir;
+
const renderFrameWithOptionToReject = async ({
frame,
index,
@@ -419,8 +421,6 @@ const innerRenderFrames = async ({
const id = startPerfMeasure('save');
- const frameDir = outputDir ?? downloadMap.compositingDir;
-
const {buffer, collectedAssets} = await takeFrameAndCompose({
frame,
freePage,
@@ -576,7 +576,10 @@ const innerRenderFrames = async ({
const returnValue: RenderFramesOutput = {
assetsInfo: {
assets,
- imageSequenceName: `element-%0${filePadLength}d.${imageFormat}`,
+ imageSequenceName: path.join(
+ frameDir,
+ `element-%0${filePadLength}d.${imageFormat}`,
+ ),
firstFrameIndex,
downloadMap,
},
diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.ts
index 7f4a4a293f..5f3b4a1e90 100644
--- a/packages/renderer/src/stitch-frames-to-video.ts
+++ b/packages/renderer/src/stitch-frames-to-video.ts
@@ -488,9 +488,7 @@ const innerStitchFramesToVideo = async (
finalFfmpegString.join(' '),
);
- const task = callFf('ffmpeg', finalFfmpegString, indent, logLevel, {
- cwd: dir,
- });
+ const task = callFf('ffmpeg', finalFfmpegString, indent, logLevel);
cancelSignal?.(() => {
task.kill();
});