Skip to content

🎥 Make videos programmatically with React

cool

Jonny Burger2561079c7442
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 25e2e82634..a226634311 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -44,6 +44,7 @@ const {
encodingBufferSizeOption,
delayRenderTimeoutInMillisecondsOption,
headlessOption,
+ overwriteOption,
} = BrowserSafeApis.options;
const getValidConcurrency = (cliConcurrency: number | string | null) => {
@@ -187,7 +188,6 @@ export const benchmarkCommand = async (
publicDir,
proResProfile,
frameRange: defaultFrameRange,
- overwrite,
pixelFormat,
everyNthFrame,
ffmpegOverride,
@@ -198,7 +198,6 @@ export const benchmarkCommand = async (
userAgent,
ignoreCertificateErrors,
} = getCliOptions({
- isLambda: false,
isStill: false,
logLevel,
});
@@ -350,6 +349,12 @@ export const benchmarkCommand = async (
delayRenderTimeoutInMillisecondsOption.getValue({
commandLine: parsedCli,
}).value;
+ const overwrite = overwriteOption.getValue(
+ {
+ commandLine: parsedCli,
+ },
+ true,
+ ).value;
for (const composition of compositions) {
const {value: videoCodec, source: codecReason} = videoCodecOption.getValue(
diff --git a/packages/cli/src/bundle.ts b/packages/cli/src/bundle.ts
index e35718a984..15fdddda79 100644
--- a/packages/cli/src/bundle.ts
+++ b/packages/cli/src/bundle.ts
@@ -51,7 +51,6 @@ export const bundleCommand = async (
}
const {publicDir} = getCliOptions({
- isLambda: false,
isStill: false,
logLevel,
});
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.ts
index bc1dbcb85f..276a8d11fb 100644
--- a/packages/cli/src/compositions.ts
+++ b/packages/cli/src/compositions.ts
@@ -59,7 +59,6 @@ export const listCompositionsCommand = async (
userAgent,
disableWebSecurity,
} = getCliOptions({
- isLambda: false,
isStill: false,
logLevel,
});
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index e1a419627f..1d752a91d4 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -19,7 +19,6 @@ import {
defaultOverrideFunction,
getWebpackOverrideFn,
} from './override-webpack';
-import {getShouldOverwrite} from './overwrite';
import {getPixelFormat} from './pixel-format';
import {
getRendererPortFromConfigFile,
@@ -75,7 +74,6 @@ import {getShouldOpenBrowser, setShouldOpenBrowser} from './open-browser';
import {setOutputLocation} from './output-location';
import type {WebpackOverrideFn} from './override-webpack';
import {overrideWebpackConfig} from './override-webpack';
-import {setOverwriteOutput} from './overwrite';
import {setPixelFormat} from './pixel-format';
import {setPort, setRendererPort, setStudioPort} from './preview-server';
import {setProResProfile} from './prores-profile';
@@ -99,6 +97,7 @@ const {
crfOption,
jpegQualityOption,
enforceAudioOption,
+ overwriteOption,
mutedOption,
videoCodecOption,
colorSpaceOption,
@@ -583,7 +582,7 @@ export const Config: FlatConfig = {
setMuted: mutedOption.setConfig,
setEnforceAudioTrack: enforceAudioOption.setConfig,
setOutputLocation,
- setOverwriteOutput,
+ setOverwriteOutput: overwriteOption.setConfig,
setPixelFormat,
setCodec: videoCodecOption.setConfig,
setCrf: crfOption.setConfig,
@@ -612,7 +611,6 @@ export const ConfigInternals = {
getBrowser,
getPixelFormat,
getProResProfile,
- getShouldOverwrite,
getBrowserExecutable,
getStudioPort,
getRendererPortFromConfigFile,
diff --git a/packages/cli/src/config/overwrite.ts b/packages/cli/src/config/overwrite.ts
deleted file mode 100644
index d6c7e7406e..0000000000
--- a/packages/cli/src/config/overwrite.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-let shouldOverwrite: boolean | null = null;
-
-export const setOverwriteOutput = (newOverwrite: boolean) => {
- if (typeof newOverwrite !== 'boolean') {
- throw new Error(
- `overwriteExisting must be a boolean but got ${typeof newOverwrite} (${JSON.stringify(
- newOverwrite,
- )})`,
- );
- }
-
- shouldOverwrite = newOverwrite;
-};
-
-export const getShouldOverwrite = ({
- defaultValue,
-}: {
- defaultValue: boolean;
-}): boolean => shouldOverwrite ?? defaultValue;
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index 8e32f79d79..3e837610e3 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -54,7 +54,6 @@ const getProResProfile = () => {
};
export const getCliOptions = (options: {
- isLambda: boolean;
isStill: boolean;
logLevel: LogLevel;
}) => {
@@ -64,9 +63,6 @@ export const getCliOptions = (options: {
? true
: ConfigInternals.getShouldOutputImageSequence(frameRange);
- const overwrite = ConfigInternals.getShouldOverwrite({
- defaultValue: !options.isLambda,
- });
const pixelFormat = ConfigInternals.getPixelFormat();
const proResProfile = getProResProfile();
const browserExecutable = ConfigInternals.getBrowserExecutable();
@@ -102,7 +98,6 @@ export const getCliOptions = (options: {
userAgent,
disableWebSecurity,
ignoreCertificateErrors,
- overwrite,
publicDir: ConfigInternals.getPublicDir(),
ffmpegOverride: ConfigInternals.getFfmpegOverrideFunction(),
height,
diff --git a/packages/cli/src/gpu.ts b/packages/cli/src/gpu.ts
index da9f983ed5..82729edeb6 100644
--- a/packages/cli/src/gpu.ts
+++ b/packages/cli/src/gpu.ts
@@ -22,7 +22,6 @@ export const gpuCommand = async (logLevel: LogLevel) => {
ignoreCertificateErrors,
userAgent,
} = getCliOptions({
- isLambda: false,
isStill: false,
logLevel,
});
diff --git a/packages/cli/src/render-queue/process-still.ts b/packages/cli/src/render-queue/process-still.ts
index 909109effe..949009ba85 100644
--- a/packages/cli/src/render-queue/process-still.ts
+++ b/packages/cli/src/render-queue/process-still.ts
@@ -22,7 +22,6 @@ export const processStill = async ({
}
const {publicDir, browserExecutable} = getCliOptions({
- isLambda: false,
isStill: true,
logLevel: job.logLevel,
});
diff --git a/packages/cli/src/render-queue/process-video.ts b/packages/cli/src/render-queue/process-video.ts
index 715b5ec66a..63050933ce 100644
--- a/packages/cli/src/render-queue/process-video.ts
+++ b/packages/cli/src/render-queue/process-video.ts
@@ -25,7 +25,6 @@ export const processVideoJob = async ({
}
const {publicDir, browserExecutable, ffmpegOverride} = getCliOptions({
- isLambda: false,
isStill: true,
logLevel,
});
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 8dae56c2f2..67ca0bc2b5 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -31,6 +31,7 @@ const {
reproOption,
delayRenderTimeoutInMillisecondsOption,
headlessOption,
+ overwriteOption,
} = BrowserSafeApis.options;
export const render = async (
@@ -74,7 +75,6 @@ export const render = async (
concurrency,
frameRange,
shouldOutputImageSequence,
- overwrite,
inputProps,
envVariables,
browserExecutable,
@@ -89,7 +89,6 @@ export const render = async (
proResProfile,
pixelFormat,
} = getCliOptions({
- isLambda: false,
isStill: false,
logLevel,
});
@@ -140,6 +139,12 @@ export const render = async (
const headless = headlessOption.getValue({
commandLine: parsedCli,
}).value;
+ const overwrite = overwriteOption.getValue(
+ {
+ commandLine: parsedCli,
+ },
+ true,
+ ).value;
const chromiumOptions: ChromiumOptions = {
disableWebSecurity,
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index 028f280c33..893ee7bd49 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -18,6 +18,7 @@ const {
glOption,
delayRenderTimeoutInMillisecondsOption,
headlessOption,
+ overwriteOption,
} = BrowserSafeApis.options;
export const still = async (
@@ -62,7 +63,6 @@ export const still = async (
envVariables,
height,
inputProps,
- overwrite,
publicDir,
stillFrame,
width,
@@ -70,7 +70,6 @@ export const still = async (
ignoreCertificateErrors,
userAgent,
} = getCliOptions({
- isLambda: false,
isStill: true,
logLevel,
});
@@ -93,6 +92,12 @@ export const still = async (
const headless = headlessOption.getValue({
commandLine: parsedCli,
}).value;
+ const overwrite = overwriteOption.getValue(
+ {
+ commandLine: parsedCli,
+ },
+ true,
+ ).value;
const chromiumOptions: ChromiumOptions = {
disableWebSecurity,
diff --git a/packages/cli/src/test/overwrite.test.ts b/packages/cli/src/test/overwrite.test.ts
index be9f192554..c3335f70e5 100644
--- a/packages/cli/src/test/overwrite.test.ts
+++ b/packages/cli/src/test/overwrite.test.ts
@@ -1,15 +1,20 @@
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {afterEach, beforeAll, expect, test} from 'vitest';
-import {getShouldOverwrite, setOverwriteOutput} from '../config/overwrite';
import {expectToThrow} from './expect-to-throw';
const invalidOverwrite = 555;
let defaultOverwriteValue: boolean;
beforeAll(() => {
- defaultOverwriteValue = getShouldOverwrite({defaultValue: true});
+ defaultOverwriteValue = BrowserSafeApis.options.overwriteOption.getValue(
+ {
+ commandLine: {},
+ },
+ true,
+ ).value;
});
afterEach(() => {
- setOverwriteOutput(defaultOverwriteValue);
+ BrowserSafeApis.options.overwriteOption.setConfig(defaultOverwriteValue);
});
test('setOverwriteOutput should throw if overwrite is not a boolean value', () => {
@@ -20,12 +25,18 @@ test('setOverwriteOutput should throw if overwrite is not a boolean value', () =
);
});
test('setOverwriteOutput should NOT throw if image format is a boolean value', () => {
- expect(() => setOverwriteOutput(true)).not.toThrow();
+ expect(() =>
+ BrowserSafeApis.options.overwriteOption.setConfig(true),
+ ).not.toThrow();
});
test('getShouldOverwrite should return true by default', () => {
- expect(getShouldOverwrite({defaultValue: true})).toEqual(true);
+ expect(
+ BrowserSafeApis.options.overwriteOption.getValue({commandLine: {}}, true),
+ ).toEqual(true);
});
test('setOverwriteOutput should return a boolean value', () => {
- setOverwriteOutput(false);
- expect(getShouldOverwrite({defaultValue: true})).toEqual(false);
+ BrowserSafeApis.options.overwriteOption.setConfig(false);
+ expect(
+ BrowserSafeApis.options.overwriteOption.getValue({commandLine: {}}, true),
+ ).toEqual(false);
});
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index 1970b4e6d2..6e72c32abb 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -83,7 +83,6 @@ export const renderCommand = async (
userAgent,
} = CliInternals.getCliOptions({
isStill: false,
- isLambda: true,
logLevel,
});
diff --git a/packages/cloudrun/src/cli/commands/still.ts b/packages/cloudrun/src/cli/commands/still.ts
index af2150527a..e249b1089e 100644
--- a/packages/cloudrun/src/cli/commands/still.ts
+++ b/packages/cloudrun/src/cli/commands/still.ts
@@ -50,7 +50,6 @@ export const stillCommand = async (
ignoreCertificateErrors,
} = CliInternals.getCliOptions({
isStill: false,
- isLambda: true,
logLevel,
});
diff --git a/packages/lambda/src/cli/commands/compositions/index.ts b/packages/lambda/src/cli/commands/compositions/index.ts
index 58fa39b1c4..45b84004dc 100644
--- a/packages/lambda/src/cli/commands/compositions/index.ts
+++ b/packages/lambda/src/cli/commands/compositions/index.ts
@@ -47,7 +47,6 @@ export const compositionsCommand = async (
disableWebSecurity,
} = CliInternals.getCliOptions({
isStill: false,
- isLambda: true,
logLevel,
});
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 91234fd963..8e0c647c96 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -58,6 +58,7 @@ const {
encodingMaxRateOption,
encodingBufferSizeOption,
delayRenderTimeoutInMillisecondsOption,
+ overwriteOption,
} = BrowserSafeApis.options;
export const renderCommand = async (
@@ -89,7 +90,6 @@ export const renderCommand = async (
pixelFormat,
proResProfile,
everyNthFrame,
- overwrite,
height,
width,
browserExecutable,
@@ -98,7 +98,6 @@ export const renderCommand = async (
disableWebSecurity,
} = CliInternals.getCliOptions({
isStill: false,
- isLambda: true,
logLevel,
});
@@ -156,7 +155,12 @@ export const renderCommand = async (
commandLine: CliInternals.parsedCli,
},
).value;
-
+ const overwrite = overwriteOption.getValue(
+ {
+ commandLine: CliInternals.parsedCli,
+ },
+ false,
+ ).value;
const chromiumOptions: ChromiumOptions = {
disableWebSecurity,
enableMultiProcessOnLinux,
diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.ts
index cddcae8287..ce4f2b844b 100644
--- a/packages/lambda/src/cli/commands/still.ts
+++ b/packages/lambda/src/cli/commands/still.ts
@@ -75,7 +75,6 @@ export const stillCommand = async (
ignoreCertificateErrors,
} = getCliOptions({
isStill: true,
- isLambda: true,
logLevel,
});
diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsx
index d1aec861ec..d68da9e1fe 100644
--- a/packages/renderer/src/options/index.tsx
+++ b/packages/renderer/src/options/index.tsx
@@ -17,6 +17,7 @@ import {mutedOption} from './mute';
import {numberOfGifLoopsOption} from './number-of-gif-loops';
import {offthreadVideoCacheSizeInBytesOption} from './offthreadvideo-cache-size';
import type {AnyRemotionOption} from './option';
+import {overwriteOption} from './overwrite';
import {reproOption} from './repro';
import {scaleOption} from './scale';
import {delayRenderTimeoutInMillisecondsOption} from './timeout';
@@ -51,6 +52,7 @@ export const allOptions = {
logLevelOption,
delayRenderTimeoutInMillisecondsOption,
headlessOption,
+ overwriteOption,
};
export type AvailableOptions = keyof typeof allOptions;
diff --git a/packages/renderer/src/options/overwrite.tsx b/packages/renderer/src/options/overwrite.tsx
new file mode 100644
index 0000000000..4fa35113f4
--- /dev/null
+++ b/packages/renderer/src/options/overwrite.tsx
@@ -0,0 +1,41 @@
+import type {AnyRemotionOption} from './option';
+
+let shouldOverwrite: boolean | null = null;
+const cliFlag = 'overwrite' as const;
+
+export const overwriteOption = {
+ name: 'Overwrite output',
+ cliFlag,
+ description: () => (
+ <>
+ If set to <code>false</code>, will prevent rendering to a path that
+ already exists. Default is <code>true</code>.
+ </>
+ ),
+ ssrName: 'overwrite',
+ docLink: 'https://www.remotion.dev/docs/config#setoverwriteoutput',
+ type: false as boolean,
+ getValue: ({commandLine}, defaultValue: boolean) => {
+ if (commandLine[cliFlag] !== undefined) {
+ return {
+ source: 'cli',
+ value: commandLine[cliFlag] as boolean,
+ };
+ }
+
+ if (shouldOverwrite !== null) {
+ return {
+ source: 'config',
+ value: shouldOverwrite,
+ };
+ }
+
+ return {
+ source: 'default',
+ value: defaultValue,
+ };
+ },
+ setConfig: (value) => {
+ shouldOverwrite = value;
+ },
+} satisfies AnyRemotionOption<boolean>;