🎥 Make videos programmatically with React
`@remotion/renderer`: Eliminate setStillImageFormat/getUserPreferredStillImageFormat in favor of stillImageFormatOption
Jonny Burger9b0c8e10dc5a
diff --git a/packages/cli/src/config/image-format.ts b/packages/cli/src/config/image-format.tsindex 8a1ecb01ee..c670958eb2 100644--- a/packages/cli/src/config/image-format.ts+++ b/packages/cli/src/config/image-format.ts@@ -1,31 +1,9 @@-import type {StillImageFormat, VideoImageFormat} from '@remotion/renderer';+import type {VideoImageFormat} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';import {truthy} from '../truthy';-let currentStillImageFormat: StillImageFormat | undefined;let currentVideoImageFormat: VideoImageFormat | undefined;-export const setStillImageFormat = (format: StillImageFormat) => {- if (typeof format === 'undefined') {- currentStillImageFormat = undefined;- return;- }-- if (!RenderInternals.validStillImageFormats.includes(format)) {- throw new TypeError(- [- `Value ${format} is not valid as an image format.`,- // @ts-expect-error- format === 'jpg' ? 'Did you mean "jpeg"?' : null,- ]- .filter(truthy)- .join(' '),- );- }-- currentStillImageFormat = format;-};-export const setVideoImageFormat = (format: VideoImageFormat) => {if (typeof format === 'undefined') {currentVideoImageFormat = undefined;@@ -47,10 +25,6 @@ export const setVideoImageFormat = (format: VideoImageFormat) => {currentVideoImageFormat = format;};-export const getUserPreferredStillImageFormat = () => {- return currentStillImageFormat;-};-export const getUserPreferredVideoImageFormat = () => {return currentVideoImageFormat;};diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 8cd755dbc7..73272a94be 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -8,9 +8,7 @@ import {getConcurrency} from './concurrency';import {getDotEnvLocation} from './env-file';import {getRange, setFrameRangeFromCli} from './frame-range';import {- getUserPreferredStillImageFormat,getUserPreferredVideoImageFormat,- setStillImageFormat,setVideoImageFormat,} from './image-format';import {getShouldOutputImageSequence} from './image-sequence';@@ -130,6 +128,7 @@ const {forceNewStudioOption,numberOfSharedAudioTagsOption,ipv4Option,+ stillImageFormatOption,} = BrowserSafeApis.options;declare global {@@ -691,7 +690,7 @@ export const Config: FlatConfig = {);},setJpegQuality: jpegQualityOption.setConfig,- setStillImageFormat,+ setStillImageFormat: stillImageFormatOption.setConfig,setVideoImageFormat,setMetadata,setEncodingMaxRate: encodingMaxRateOption.setConfig,@@ -757,7 +756,6 @@ export const ConfigInternals = {getStillFrame,getShouldOutputImageSequence,getDotEnvLocation,- getUserPreferredStillImageFormat,getUserPreferredVideoImageFormat,getWebpackOverrideFn,getWebpackCaching,diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.tsindex b10d34769a..e9a201d9a5 100644--- a/packages/cli/src/get-render-defaults.ts+++ b/packages/cli/src/get-render-defaults.ts@@ -32,6 +32,7 @@ const {mediaCacheSizeInBytesOption,darkModeOption,publicLicenseKeyOption,+ stillImageFormatOption,} = BrowserSafeApis.options;export const getRenderDefaults = (): RenderDefaults => {@@ -122,7 +123,9 @@ export const getRenderDefaults = (): RenderDefaults => {}).value;const everyNthFrame = ConfigInternals.getEveryNthFrame();- const stillImageFormat = ConfigInternals.getUserPreferredStillImageFormat();+ const stillImageFormat = stillImageFormatOption.getValue({+ commandLine: parsedCli,+ }).value;const videoImageFormat = ConfigInternals.getUserPreferredVideoImageFormat();const disableWebSecurity = ConfigInternals.getChromiumDisableWebSecurity();const ignoreCertificateErrors = ConfigInternals.getIgnoreCertificateErrors();diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.tsindex 520566dc46..cd97ae3934 100644--- a/packages/cli/src/render-flows/still.ts+++ b/packages/cli/src/render-flows/still.ts@@ -23,7 +23,6 @@ import {NoReactInternals} from 'remotion/no-react';import {defaultBrowserDownloadProgress} from '../browser-download-bar';import {chalk} from '../chalk';import {registerCleanupJob} from '../cleanup-before-quit';-import {ConfigInternals} from '../config';import {determineFinalStillImageFormat} from '../determine-image-format';import {getAndValidateAbsoluteOutputFile} from '../get-cli-options';import {getCompositionWithDimensionOverride} from '../get-composition-with-dimension-override';@@ -277,13 +276,22 @@ export const renderStillFlow = async ({mediaCacheSizeInBytes,});+ const {+ value: resolvedStillImageFormat,+ source: resolvedStillImageFormatSource,+ } = BrowserSafeApis.options.stillImageFormatOption.getValue({+ commandLine: parsedCli,+ });+const {format: imageFormat, source} = determineFinalStillImageFormat({cliFlag:- BrowserSafeApis.options.stillImageFormatOption.getValue({- commandLine: parsedCli,- }).value ?? null,+ resolvedStillImageFormatSource === 'cli'+ ? resolvedStillImageFormat+ : null,configImageFormat:- ConfigInternals.getUserPreferredStillImageFormat() ?? null,+ resolvedStillImageFormatSource === 'config'+ ? resolvedStillImageFormat+ : null,downloadName: null,outName: getUserPassedOutputLocation(argsAfterComposition,diff --git a/packages/cloudrun/src/cli/commands/still.ts b/packages/cloudrun/src/cli/commands/still.tsindex 58783a10b0..e9b8087fe7 100644--- a/packages/cloudrun/src/cli/commands/still.ts+++ b/packages/cloudrun/src/cli/commands/still.ts@@ -159,19 +159,27 @@ export const stillCommand = async (}const {stillImageFormatOption} = BrowserSafeApis.options;+ const {+ value: resolvedStillImageFormat,+ source: resolvedStillImageFormatSource,+ } = stillImageFormatOption.getValue({+ commandLine: CliInternals.parsedCli,+ });const {format: imageFormat, source: imageFormatReason} =CliInternals.determineFinalStillImageFormat({downloadName,outName: outName ?? null,cliFlag:- stillImageFormatOption.getValue({- commandLine: CliInternals.parsedCli,- }).value ?? null,+ resolvedStillImageFormatSource === 'cli'+ ? resolvedStillImageFormat+ : null,isLambda: true,fromUi: null,configImageFormat:- ConfigInternals.getUserPreferredStillImageFormat() ?? null,+ resolvedStillImageFormatSource === 'config'+ ? resolvedStillImageFormat+ : null,});Log.verbose({indent: false, logLevel},diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.tsindex ee2b699c53..fd7ce5b34a 100644--- a/packages/lambda/src/cli/commands/still.ts+++ b/packages/lambda/src/cli/commands/still.ts@@ -207,17 +207,25 @@ export const stillCommand = async ({validatePrivacy(privacy, true);const {stillImageFormatOption} = BrowserSafeApis.options;+ const {+ value: resolvedStillImageFormat,+ source: resolvedStillImageFormatSource,+ } = stillImageFormatOption.getValue({commandLine: parsedCli});const {format: imageFormat, source: imageFormatReason} =determineFinalStillImageFormat({downloadName,outName: outName ?? null,cliFlag:- stillImageFormatOption.getValue({commandLine: parsedCli}).value ?? null,+ resolvedStillImageFormatSource === 'cli'+ ? resolvedStillImageFormat+ : null,isLambda: true,fromUi: null,configImageFormat:- ConfigInternals.getUserPreferredStillImageFormat() ?? null,+ resolvedStillImageFormatSource === 'config'+ ? resolvedStillImageFormat+ : null,});Log.info(diff --git a/packages/renderer/src/options/still-image-format.tsx b/packages/renderer/src/options/still-image-format.tsxindex c911c04bd3..a63b748e21 100644--- a/packages/renderer/src/options/still-image-format.tsx+++ b/packages/renderer/src/options/still-image-format.tsx@@ -49,12 +49,22 @@ export const stillImageFormatOption = {};},setConfig: (value) => {+ if (value === null) {+ currentStillImageFormat = null;+ return;+ }+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(', ')}`,+ throw new TypeError(+ [+ `Value ${value} is not valid as a still image format.`,+ // @ts-expect-error+ value === 'jpg' ? 'Did you mean "jpeg"?' : null,+ ]+ .filter(Boolean)+ .join(' '),);}