Skip to content

🎥 Make videos programmatically with React

scale

Jonny Burger04a20ead8b09
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 53135ffd1d..eca5aef02d 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -22,7 +22,12 @@ import {truthy} from './truthy';
const DEFAULT_RUNS = 3;
-const {audioBitrateOption, x264Option} = BrowserSafeApis.options;
+const {
+ audioBitrateOption,
+ x264Option,
+ offthreadVideoCacheSizeInBytesOption,
+ scaleOption,
+} = BrowserSafeApis.options;
const getValidConcurrency = (cliConcurrency: number | string | null) => {
const {concurrencies} = parsedCli;
@@ -167,7 +172,6 @@ export const benchmarkCommand = async (
browserExecutable,
chromiumOptions,
puppeteerTimeout,
- scale,
publicDir,
proResProfile,
frameRange: defaultFrameRange,
@@ -175,7 +179,6 @@ export const benchmarkCommand = async (
jpegQuality,
crf: configFileCrf,
pixelFormat,
- scale: configFileScale,
numberOfGifLoops,
everyNthFrame,
muted,
@@ -203,6 +206,8 @@ export const benchmarkCommand = async (
reason,
);
+ const scale = scaleOption.getValue({commandLine: parsedCli}).value;
+
const browserInstance = RenderInternals.internalOpenBrowser({
browser: 'chrome',
browserExecutable,
@@ -261,7 +266,7 @@ export const benchmarkCommand = async (
server: undefined,
logLevel,
offthreadVideoCacheSizeInBytes:
- BrowserSafeApis.options.offthreadVideoCacheSizeInBytesOption.getValue({
+ offthreadVideoCacheSizeInBytesOption.getValue({
commandLine: parsedCli,
}).value,
});
@@ -351,7 +356,7 @@ export const benchmarkCommand = async (
jpegQuality,
chromiumOptions,
timeoutInMilliseconds: ConfigInternals.getCurrentPuppeteerTimeout(),
- scale: configFileScale,
+ scale,
port: getRendererPortFromConfigFileAndCliFlag(),
numberOfGifLoops,
everyNthFrame,
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index 3d6c0aae20..b48a194afb 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -39,7 +39,6 @@ import {
} from './preview-server';
import {getProResProfile} from './prores-profile';
import {getDeleteAfter, setDeleteAfter} from './render-folder-expiry';
-import {getScale} from './scale';
import {getStillFrame, setStillFrame} from './still-frame';
import {getCurrentPuppeteerTimeout} from './timeout';
import {getWebpackCaching} from './webpack-caching';
@@ -116,7 +115,6 @@ import {setPort, setRendererPort, setStudioPort} from './preview-server';
import {setProResProfile} from './prores-profile';
import {getPublicDir, setPublicDir} from './public-dir';
import {getRepro, setRepro} from './repro';
-import {setScale} from './scale';
import {setPuppeteerTimeout} from './timeout';
import {getChromiumUserAgent, setChromiumUserAgent} from './user-agent';
import {setWebpackCaching} from './webpack-caching';
@@ -128,8 +126,12 @@ import {getWidth, overrideWidth} from './width';
export type {Concurrency, WebpackConfiguration, WebpackOverrideFn};
-const {offthreadVideoCacheSizeInBytesOption, x264Option, audioBitrateOption} =
- BrowserSafeApis.options;
+const {
+ offthreadVideoCacheSizeInBytesOption,
+ x264Option,
+ audioBitrateOption,
+ scaleOption,
+} = BrowserSafeApis.options;
declare global {
interface RemotionBundlingOptions {
@@ -588,7 +590,9 @@ export const Config: FlatConfig = {
setEncodingMaxRate,
setEncodingBufferSize,
setFrameRange,
- setScale,
+ setScale: (option) => {
+ scaleOption.setConfig(option);
+ },
setEveryNthFrame,
setNumberOfGifLoops,
setMuted,
@@ -629,7 +633,6 @@ export const ConfigInternals = {
getProResProfile,
getShouldOverwrite,
getBrowserExecutable,
- getScale,
getStudioPort,
getRendererPortFromConfigFile,
getRendererPortFromConfigFileAndCliFlag,
diff --git a/packages/cli/src/config/scale.ts b/packages/cli/src/config/scale.ts
deleted file mode 100644
index b7abe1e132..0000000000
--- a/packages/cli/src/config/scale.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-type Scale = number;
-
-let currentScale: Scale = 1;
-
-export const setScale = (newScale: Scale) => {
- if (typeof newScale !== 'number') {
- throw new Error('--scale flag must be a number.');
- }
-
- currentScale = newScale;
-};
-
-export const getScale = () => {
- return currentScale;
-};
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index 1a462ccf25..9ac39d38e5 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -95,7 +95,6 @@ export const getCliOptions = (options: {
const pixelFormat = ConfigInternals.getPixelFormat();
const proResProfile = getProResProfile();
const browserExecutable = ConfigInternals.getBrowserExecutable();
- const scale = ConfigInternals.getScale();
const chromiumOptions: ChromiumOptions = {
disableWebSecurity: ConfigInternals.getChromiumDisableWebSecurity(),
@@ -137,7 +136,6 @@ export const getCliOptions = (options: {
stillFrame: ConfigInternals.getStillFrame(),
browserExecutable,
logLevel: ConfigInternals.Logging.getLogLevel(),
- scale,
chromiumOptions,
overwrite,
muted: ConfigInternals.getMuted(),
diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.ts
index e2ac4ef299..15ba7f64a5 100644
--- a/packages/cli/src/get-render-defaults.ts
+++ b/packages/cli/src/get-render-defaults.ts
@@ -4,12 +4,15 @@ import type {RenderDefaults} from '@remotion/studio';
import {ConfigInternals} from './config';
import {parsedCli} from './parse-command-line';
-const {x264Option, audioBitrateOption, offthreadVideoCacheSizeInBytesOption} =
- BrowserSafeApis.options;
+const {
+ x264Option,
+ audioBitrateOption,
+ offthreadVideoCacheSizeInBytesOption,
+ scaleOption,
+} = BrowserSafeApis.options;
export const getRenderDefaults = (): RenderDefaults => {
const defaultJpegQuality = ConfigInternals.getJpegQuality();
- const defaultScale = ConfigInternals.getScale();
const logLevel = ConfigInternals.Logging.getLogLevel();
const defaultCodec = ConfigInternals.getOutputCodecOrUndefined();
const concurrency = RenderInternals.getActualConcurrency(
@@ -30,6 +33,10 @@ export const getRenderDefaults = (): RenderDefaults => {
offthreadVideoCacheSizeInBytesOption.getValue({
commandLine: parsedCli,
}).value;
+ const defaultScale = scaleOption.getValue({
+ commandLine: parsedCli,
+ }).value;
+
const videoBitrate = ConfigInternals.getVideoBitrate();
const encodingBufferSize = ConfigInternals.getEncodingBufferSize();
const encodingMaxRate = ConfigInternals.getEncodingMaxRate();
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index baebc8c13f..6742114835 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -13,8 +13,12 @@ import {Log} from './log';
import {parsedCli, quietFlagProvided} from './parse-command-line';
import {renderVideoFlow} from './render-flows/render';
-const {x264Option, audioBitrateOption, offthreadVideoCacheSizeInBytesOption} =
- BrowserSafeApis.options;
+const {
+ x264Option,
+ audioBitrateOption,
+ offthreadVideoCacheSizeInBytesOption,
+ scaleOption,
+} = BrowserSafeApis.options;
export const render = async (
remotionRoot: string,
@@ -54,7 +58,6 @@ export const render = async (
envVariables,
jpegQuality,
browserExecutable,
- scale,
chromiumOptions,
everyNthFrame,
puppeteerTimeout,
@@ -88,6 +91,7 @@ export const render = async (
offthreadVideoCacheSizeInBytesOption.getValue({
commandLine: parsedCli,
});
+ const {value: scale} = scaleOption.getValue({commandLine: parsedCli});
const audioCodec = getResolvedAudioCodec();
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index 83ac5b9c05..0d7bd7a712 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -10,7 +10,8 @@ import {Log} from './log';
import {parsedCli} from './parse-command-line';
import {renderStillFlow} from './render-flows/still';
-const {offthreadVideoCacheSizeInBytesOption} = BrowserSafeApis.options;
+const {offthreadVideoCacheSizeInBytesOption, scaleOption} =
+ BrowserSafeApis.options;
export const still = async (
remotionRoot: string,
@@ -51,7 +52,6 @@ export const still = async (
publicDir,
puppeteerTimeout,
jpegQuality,
- scale,
stillFrame,
width,
} = getCliOptions({
@@ -82,7 +82,9 @@ export const still = async (
publicDir,
puppeteerTimeout,
jpegQuality,
- scale,
+ scale: scaleOption.getValue({
+ commandLine: parsedCli,
+ }).value,
stillFrame,
width,
compositionIdFromUi: null,
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index 1ec82e1103..b8fbf2a1c5 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -15,8 +15,12 @@ import {renderArgsCheck} from './helpers/renderArgsCheck';
export const RENDER_COMMAND = 'render';
-const {audioBitrateOption, x264Option, offthreadVideoCacheSizeInBytesOption} =
- BrowserSafeApis.options;
+const {
+ audioBitrateOption,
+ x264Option,
+ offthreadVideoCacheSizeInBytesOption,
+ scaleOption,
+} = BrowserSafeApis.options;
export const renderCommand = async (
args: string[],
@@ -56,7 +60,6 @@ export const renderCommand = async (
pixelFormat,
proResProfile,
jpegQuality,
- scale,
everyNthFrame,
numberOfGifLoops,
muted,
@@ -193,6 +196,9 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
const audioBitrate = audioBitrateOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
+ const scale = scaleOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
const res = await internalRenderMediaOnCloudrun({
cloudRunUrl,
serviceName: undefined,
diff --git a/packages/cloudrun/src/cli/commands/still.ts b/packages/cloudrun/src/cli/commands/still.ts
index 0f183f8b89..4bf7d227f6 100644
--- a/packages/cloudrun/src/cli/commands/still.ts
+++ b/packages/cloudrun/src/cli/commands/still.ts
@@ -13,6 +13,9 @@ import {renderArgsCheck} from './render/helpers/renderArgsCheck';
export const STILL_COMMAND = 'still';
+const {offthreadVideoCacheSizeInBytesOption, scaleOption} =
+ BrowserSafeApis.options;
+
export const stillCommand = async (
args: string[],
remotionRoot: string,
@@ -35,7 +38,6 @@ export const stillCommand = async (
puppeteerTimeout,
jpegQuality,
stillFrame,
- scale,
height,
width,
browserExecutable,
@@ -59,7 +61,7 @@ export const stillCommand = async (
}
const offthreadVideoCacheSizeInBytes =
- BrowserSafeApis.options.offthreadVideoCacheSizeInBytesOption.getValue({
+ offthreadVideoCacheSizeInBytesOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
@@ -153,6 +155,10 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
);
};
+ const scale = scaleOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
+
const res = await renderStillOnCloudrun({
cloudRunUrl,
serveUrl,
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index eff18129e4..391055dbbf 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -40,8 +40,12 @@ function getTotalFrames(status: RenderProgress): number | null {
: null;
}
-const {x264Option, audioBitrateOption, offthreadVideoCacheSizeInBytesOption} =
- BrowserSafeApis.options;
+const {
+ x264Option,
+ audioBitrateOption,
+ offthreadVideoCacheSizeInBytesOption,
+ scaleOption,
+} = BrowserSafeApis.options;
export const renderCommand = async (
args: string[],
@@ -73,7 +77,6 @@ export const renderCommand = async (
proResProfile,
puppeteerTimeout,
jpegQuality,
- scale,
everyNthFrame,
numberOfGifLoops,
muted,
@@ -103,6 +106,9 @@ export const renderCommand = async (
offthreadVideoCacheSizeInBytesOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
+ const scale = scaleOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
let composition: string = args[1];
if (!composition) {
diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.ts
index 7a7ae8193f..5afb7ede4c 100644
--- a/packages/lambda/src/cli/commands/still.ts
+++ b/packages/lambda/src/cli/commands/still.ts
@@ -20,6 +20,9 @@ import {findFunctionName} from '../helpers/find-function-name';
import {quit} from '../helpers/quit';
import {Log} from '../log';
+const {offthreadVideoCacheSizeInBytesOption, scaleOption, deleteAfterOption} =
+ BrowserSafeApis.options;
+
export const STILL_COMMAND = 'still';
export const stillCommand = async (
@@ -48,7 +51,6 @@ export const stillCommand = async (
puppeteerTimeout,
jpegQuality,
stillFrame,
- scale,
height,
width,
browserExecutable,
@@ -73,7 +75,7 @@ export const stillCommand = async (
}
const offthreadVideoCacheSizeInBytes =
- BrowserSafeApis.options.offthreadVideoCacheSizeInBytesOption.getValue({
+ offthreadVideoCacheSizeInBytesOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
@@ -142,8 +144,10 @@ export const stillCommand = async (
),
);
- const deleteAfter =
- parsedLambdaCli[BrowserSafeApis.options.deleteAfterOption.cliFlag];
+ const deleteAfter = parsedLambdaCli[deleteAfterOption.cliFlag];
+ const scale = scaleOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
const res = await renderStillOnLambda({
functionName,
diff --git a/packages/renderer/src/options/scale.tsx b/packages/renderer/src/options/scale.tsx
index 0f767aa117..6fd8842e19 100644
--- a/packages/renderer/src/options/scale.tsx
+++ b/packages/renderer/src/options/scale.tsx
@@ -1,8 +1,20 @@
import type {AnyRemotionOption} from './option';
+type Scale = number;
+
+let currentScale: Scale | null = 1;
+
+const cliFlag = 'scale' as const;
+
+const validateScale = (value: unknown) => {
+ if (typeof value !== 'number') {
+ throw new Error('scale must be a number.');
+ }
+};
+
export const scaleOption = {
name: 'Scale',
- cliFlag: 'scale' as const,
+ cliFlag,
description: () => (
<>
Scales the output by a factor. For example, a 1280x720px frame will become
@@ -13,4 +25,28 @@ export const scaleOption = {
ssrName: 'scale',
docLink: 'https://www.remotion.dev/docs/scaling',
type: 0 as number,
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag] !== undefined) {
+ validateScale(commandLine[cliFlag]);
+ return {
+ source: 'cli',
+ value: commandLine[cliFlag] as number,
+ };
+ }
+
+ if (currentScale !== null) {
+ return {
+ source: 'config',
+ value: currentScale,
+ };
+ }
+
+ return {
+ source: 'default',
+ value: 1,
+ };
+ },
+ setConfig: (scale) => {
+ currentScale = scale;
+ },
} satisfies AnyRemotionOption<number>;