Skip to content

🎥 Make videos programmatically with React

hmm

Jonny Burgerd629c48efe21
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 2c087be4df..2a6f627eb2 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -1,5 +1,6 @@
import type {InternalRenderMediaOptions, LogLevel} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {NoReactInternals} from 'remotion/no-react';
import {chalk} from './chalk';
import {registerCleanupJob} from './cleanup-before-quit';
@@ -167,7 +168,6 @@ export const benchmarkCommand = async (
scale,
publicDir,
proResProfile,
- x264Preset,
frameRange: defaultFrameRange,
overwrite,
jpegQuality,
@@ -292,6 +292,10 @@ export const benchmarkCommand = async (
let count = 1;
+ const {value: x264Preset} = BrowserSafeApis.options.x264Option.getValue({
+ commandLine: parsedCli,
+ });
+
for (const composition of compositions) {
const {codec, reason: codecReason} = getFinalOutputCodec({
cliFlag: parsedCli.codec,
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index a9adaa856e..ad504d8f77 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -43,7 +43,6 @@ import {getScale} from './scale';
import {getStillFrame, setStillFrame} from './still-frame';
import {getCurrentPuppeteerTimeout} from './timeout';
import {getWebpackCaching} from './webpack-caching';
-import {getX264Preset} from './x264-preset';
import type {WebpackConfiguration} from '@remotion/bundler';
import type {
@@ -55,6 +54,7 @@ import type {
StillImageFormat,
VideoImageFormat,
} from '@remotion/renderer';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {StudioServerInternals} from '@remotion/studio-server';
import {getAudioCodec, setAudioCodec} from './audio-codec';
import {getBeepOnFinish, setBeepOnFinish} from './beep-on-finish';
@@ -131,7 +131,6 @@ import {
setWebpackPollingInMilliseconds,
} from './webpack-poll';
import {getWidth, overrideWidth} from './width';
-import {setX264Preset} from './x264-preset';
export type {Concurrency, WebpackConfiguration, WebpackOverrideFn};
@@ -604,7 +603,9 @@ export const Config: FlatConfig = {
setCrf,
setImageSequence,
setProResProfile,
- setX264Preset,
+ setX264Preset: (preset) => {
+ BrowserSafeApis.options.x264Option.setConfig(preset);
+ },
setAudioBitrate,
setVideoBitrate,
overrideHeight,
@@ -625,7 +626,6 @@ export const ConfigInternals = {
getBrowser,
getPixelFormat,
getProResProfile,
- getPresetProfile: getX264Preset,
getShouldOverwrite,
getBrowserExecutable,
getScale,
diff --git a/packages/cli/src/config/x264-preset.ts b/packages/cli/src/config/x264-preset.ts
deleted file mode 100644
index 1e37691d86..0000000000
--- a/packages/cli/src/config/x264-preset.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import type {X264Preset} from '@remotion/renderer';
-
-let preset: X264Preset | undefined;
-
-export const getX264Preset = (): X264Preset | undefined => {
- return preset;
-};
-
-export const setX264Preset = (profile: X264Preset | undefined) => {
- preset = profile;
-};
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index 68de8afcf2..dcd3aeab1e 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -70,12 +70,6 @@ const getProResProfile = () => {
return proResProfile;
};
-const getx264Preset = () => {
- const x264Preset = ConfigInternals.getPresetProfile();
-
- return x264Preset;
-};
-
export const getCliOptions = (options: {
isLambda: boolean;
type: 'still' | 'series' | 'get-compositions';
@@ -100,7 +94,6 @@ export const getCliOptions = (options: {
const encodingMaxRate = ConfigInternals.getEncodingMaxRate();
const pixelFormat = ConfigInternals.getPixelFormat();
const proResProfile = getProResProfile();
- const x264Preset = getx264Preset();
const browserExecutable = ConfigInternals.getBrowserExecutable();
const scale = ConfigInternals.getScale();
@@ -139,7 +132,6 @@ export const getCliOptions = (options: {
crf,
pixelFormat,
proResProfile,
- x264Preset,
everyNthFrame,
numberOfGifLoops,
stillFrame: ConfigInternals.getStillFrame(),
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 14622e3bfc..d9198cb812 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -1,5 +1,6 @@
// eslint-disable-next-line no-restricted-imports
import type {LogLevel} from '@remotion/renderer';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {NoReactInternals} from 'remotion/no-react';
import {registerCleanupJob} from './cleanup-before-quit';
import {ConfigInternals} from './config';
@@ -63,7 +64,6 @@ export const render = async (
muted,
enforceAudioTrack,
proResProfile,
- x264Preset,
pixelFormat,
videoBitrate,
encodingMaxRate,
@@ -79,6 +79,10 @@ export const render = async (
logLevel,
});
+ const {value: x264Preset} = BrowserSafeApis.options.x264Option.getValue({
+ commandLine: parsedCli,
+ });
+
const audioCodec = getResolvedAudioCodec();
await renderVideoFlow({
diff --git a/packages/renderer/src/options/option.ts b/packages/renderer/src/options/option.ts
index cd408d3ca1..4787ae8da4 100644
--- a/packages/renderer/src/options/option.ts
+++ b/packages/renderer/src/options/option.ts
@@ -8,9 +8,14 @@ export type RemotionOption<SsrName extends string, Type> = {
description: (mode: 'ssr' | 'cli') => React.ReactNode;
docLink: string;
type: Type;
+ getValue?: (values: {commandLine: Record<string, unknown>}) => {
+ value: Type;
+ source: string;
+ };
+ setConfig?: (value: Type) => void;
};
-export type AnyRemotionOption = RemotionOption<string, unknown>;
+export type AnyRemotionOption<T = unknown> = RemotionOption<string, T>;
export type ToOptions<T extends Record<string, AnyRemotionOption>> = {
[K in keyof T]: T[K]['type'];
diff --git a/packages/renderer/src/x264-preset.tsx b/packages/renderer/src/x264-preset.tsx
index 0d39adcb2b..8604468244 100644
--- a/packages/renderer/src/x264-preset.tsx
+++ b/packages/renderer/src/x264-preset.tsx
@@ -14,6 +14,8 @@ export const x264PresetOptions = [
'placebo',
] as const;
+let preset: X264Preset | undefined;
+
export type X264Preset = (typeof x264PresetOptions)[number];
export const validateSelectedCodecAndPresetCombination = ({
@@ -45,9 +47,11 @@ export const validateSelectedCodecAndPresetCombination = ({
}
};
+const cliFlag = 'x264-preset' as const;
+
export const x264Option = {
name: 'x264 Preset',
- cliFlag: 'x264-preset' as const,
+ cliFlag,
description: () => (
<>
Sets a x264 preset profile. Only applies to videos rendered with{' '}
@@ -62,5 +66,20 @@ export const x264Option = {
),
ssrName: 'x264Preset' as const,
docLink: 'https://www.remotion.dev/docs/renderer/render-media',
- type: 'fast' as X264Preset,
-} satisfies AnyRemotionOption;
+ type: 'fast' as X264Preset | undefined,
+ getValue: ({commandLine}) => {
+ const value = commandLine[cliFlag];
+ if (typeof value !== 'undefined') {
+ return {value: value as X264Preset, source: 'cli'};
+ }
+
+ if (typeof preset !== 'undefined') {
+ return {value: preset, source: 'config'};
+ }
+
+ return {value: undefined, source: 'default'};
+ },
+ setConfig: (profile: X264Preset | undefined) => {
+ preset = profile;
+ },
+} satisfies AnyRemotionOption<X264Preset | undefined>;
diff --git a/packages/studio/src/components/RenderModal/OptionExplainerBubble.tsx b/packages/studio/src/components/RenderModal/OptionExplainerBubble.tsx
index af412d1e33..c494a09c2e 100644
--- a/packages/studio/src/components/RenderModal/OptionExplainerBubble.tsx
+++ b/packages/studio/src/components/RenderModal/OptionExplainerBubble.tsx
@@ -7,6 +7,7 @@ export const OptionExplainerBubble: React.FC<{
id: AvailableOptions;
}> = ({id}) => {
const option = BrowserSafeApis.options[id];
+
return (
<InfoBubble title="Learn more about this option">
<OptionExplainer option={option} />