Skip to content

🎥 Make videos programmatically with React

`@remotion/renderer`: Add `stillImageFormatOption` for resolving `--image-format` in still renders

Jonny Burger38d0038531bc
diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.ts
index 694de99c8a..520566dc46 100644
--- a/packages/cli/src/render-flows/still.ts
+++ b/packages/cli/src/render-flows/still.ts
@@ -11,6 +11,7 @@ import type {
StillImageFormat,
} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import type {
AggregateRenderProgress,
JobProgressCallback,
@@ -277,7 +278,10 @@ export const renderStillFlow = async ({
});
const {format: imageFormat, source} = determineFinalStillImageFormat({
- cliFlag: parsedCli['image-format'] ?? null,
+ cliFlag:
+ BrowserSafeApis.options.stillImageFormatOption.getValue({
+ commandLine: parsedCli,
+ }).value ?? null,
configImageFormat:
ConfigInternals.getUserPreferredStillImageFormat() ?? null,
downloadName: null,
diff --git a/packages/cloudrun/src/cli/commands/still.ts b/packages/cloudrun/src/cli/commands/still.ts
index 09ee21ca6a..58783a10b0 100644
--- a/packages/cloudrun/src/cli/commands/still.ts
+++ b/packages/cloudrun/src/cli/commands/still.ts
@@ -158,11 +158,16 @@ export const stillCommand = async (
composition = compositionId;
}
+ const {stillImageFormatOption} = BrowserSafeApis.options;
+
const {format: imageFormat, source: imageFormatReason} =
CliInternals.determineFinalStillImageFormat({
downloadName,
outName: outName ?? null,
- cliFlag: CliInternals.parsedCli['image-format'] ?? null,
+ cliFlag:
+ stillImageFormatOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value ?? null,
isLambda: true,
fromUi: null,
configImageFormat:
diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.ts
index 7003a601c1..ee2b699c53 100644
--- a/packages/lambda/src/cli/commands/still.ts
+++ b/packages/lambda/src/cli/commands/still.ts
@@ -206,11 +206,14 @@ export const stillCommand = async ({
const privacy = parsedLambdaCli.privacy ?? DEFAULT_OUTPUT_PRIVACY;
validatePrivacy(privacy, true);
+ const {stillImageFormatOption} = BrowserSafeApis.options;
+
const {format: imageFormat, source: imageFormatReason} =
determineFinalStillImageFormat({
downloadName,
outName: outName ?? null,
- cliFlag: parsedCli['image-format'] ?? null,
+ cliFlag:
+ stillImageFormatOption.getValue({commandLine: parsedCli}).value ?? null,
isLambda: true,
fromUi: null,
configImageFormat:
diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsx
index a27057f54b..98ac1db7cb 100644
--- a/packages/renderer/src/options/index.tsx
+++ b/packages/renderer/src/options/index.tsx
@@ -48,6 +48,7 @@ import {publicPathOption} from './public-path';
import {reproOption} from './repro';
import {scaleOption} from './scale';
import {separateAudioOption} from './separate-audio';
+import {stillImageFormatOption} from './still-image-format';
import {throwIfSiteExistsOption} from './throw-if-site-exists';
import {delayRenderTimeoutInMillisecondsOption} from './timeout';
import {videoBitrateOption} from './video-bitrate';
@@ -113,6 +114,7 @@ export const allOptions = {
forceNewStudioOption,
numberOfSharedAudioTagsOption,
ipv4Option,
+ stillImageFormatOption,
};
export type AvailableOptions = keyof typeof allOptions;
diff --git a/packages/renderer/src/options/still-image-format.tsx b/packages/renderer/src/options/still-image-format.tsx
new file mode 100644
index 0000000000..c911c04bd3
--- /dev/null
+++ b/packages/renderer/src/options/still-image-format.tsx
@@ -0,0 +1,63 @@
+import type {StillImageFormat} from '../image-format';
+import {validStillImageFormats} from '../image-format';
+import type {AnyRemotionOption} from './option';
+
+let currentStillImageFormat: StillImageFormat | null = null;
+
+const cliFlag = 'image-format' as const;
+
+export const stillImageFormatOption = {
+ name: 'Still Image Format',
+ cliFlag,
+ description: () => (
+ <>
+ The image format to use when rendering a still. Must be one of{' '}
+ {validStillImageFormats.map((f) => `"${f}"`).join(', ')}. Default:{' '}
+ <code>&quot;png&quot;</code>.
+ </>
+ ),
+ ssrName: 'stillImageFormat' as const,
+ docLink: 'https://www.remotion.dev/docs/renderer/render-still#imageformat',
+ type: null as StillImageFormat | null,
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag] !== undefined) {
+ const value = commandLine[cliFlag] as StillImageFormat;
+ if (
+ !(validStillImageFormats as readonly string[]).includes(value as string)
+ ) {
+ throw new Error(
+ `Invalid still image format: ${value}. Must be one of: ${validStillImageFormats.join(', ')}`,
+ );
+ }
+
+ return {
+ source: 'cli',
+ value,
+ };
+ }
+
+ if (currentStillImageFormat !== null) {
+ return {
+ source: 'config',
+ value: currentStillImageFormat,
+ };
+ }
+
+ return {
+ source: 'default',
+ value: null,
+ };
+ },
+ setConfig: (value) => {
+ if (
+ value !== null &&
+ !(validStillImageFormats as readonly string[]).includes(value as string)
+ ) {
+ throw new Error(
+ `Invalid still image format: ${value}. Must be one of: ${validStillImageFormats.join(', ')}`,
+ );
+ }
+
+ currentStillImageFormat = value;
+ },
+} satisfies AnyRemotionOption<StillImageFormat | null>;