🎥 Make videos programmatically with React
`@remotion/cli`: Unhardcode --image-format in error messages, use cliFlag
Jonny Burgercc82dfcdc706
diff --git a/packages/cli/src/determine-image-format.ts b/packages/cli/src/determine-image-format.tsindex b2d69ad087..c7b306dad0 100644--- a/packages/cli/src/determine-image-format.ts+++ b/packages/cli/src/determine-image-format.ts@@ -1,4 +1,7 @@import type {StillImageFormat} from '@remotion/renderer';+import {BrowserSafeApis} from '@remotion/renderer/client';++const cliFlag = BrowserSafeApis.options.stillImageFormatOption.cliFlag;const deriveExtensionFromFilename = (filename: string | null,@@ -64,7 +67,7 @@ export const determineFinalStillImageFormat = ({downloadNameExtension !== configuredImageFormat) {throw new TypeError(- `Image format mismatch: ${downloadName} was given as the download name, but --image-format=${configuredImageFormat} was passed. The image formats must match.`,+ `Image format mismatch: ${downloadName} was given as the download name, but the image format "${configuredImageFormat}" was configured via --${cliFlag} or Config.setStillImageFormat(). The image formats must match.`,);}@@ -74,7 +77,7 @@ export const determineFinalStillImageFormat = ({if (outNameExtension) {if (configuredImageFormat && outNameExtension !== configuredImageFormat) {throw new TypeError(- `Image format mismatch: ${outName} was given as the ${outNameDescription}, but --image-format=${configuredImageFormat} was passed. The image formats must match.`,+ `Image format mismatch: ${outName} was given as the ${outNameDescription}, but the image format "${configuredImageFormat}" was configured via --${cliFlag} or Config.setStillImageFormat(). The image formats must match.`,);}@@ -82,7 +85,7 @@ export const determineFinalStillImageFormat = ({}if (configuredImageFormat !== null) {- return {format: configuredImageFormat, source: '--image-format flag'};+ return {format: configuredImageFormat, source: `--${cliFlag} or config`};}return {format: 'png', source: 'Default'};diff --git a/packages/example/src/test/still-image-format.test.ts b/packages/example/src/test/still-image-format.test.tsdeleted file mode 100644index b27f01eb51..0000000000--- a/packages/example/src/test/still-image-format.test.ts+++ /dev/null@@ -1,133 +0,0 @@-import {- RenderInternals,- renderStill,- selectComposition,-} from '@remotion/renderer';-import {BrowserSafeApis} from '@remotion/renderer/client';-import {$} from 'bun';-import {beforeAll, expect, test} from 'bun:test';-import {existsSync, readFileSync, unlinkSync} from 'node:fs';-import {tmpdir} from 'node:os';-import path from 'node:path';--if (process.platform === 'win32') {- process.exit(0);-}--const exampleDir = path.join(__dirname, '..', '..');-const buildDir = path.join(exampleDir, 'build');--beforeAll(async () => {- await $`bunx remotion browser ensure`.cwd(exampleDir);-});--const isPng = (filePath: string) => {- const buf = readFileSync(filePath);- return (- buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47- );-};--const isJpeg = (filePath: string) => {- const buf = readFileSync(filePath);- return buf[0] === 0xff && buf[1] === 0xd8;-};--test(- '--image-format=jpeg produces a JPEG still',- async () => {- const outFile = path.join(tmpdir(), 'remotion-test', 'still-fmt-jpeg.jpeg');-- await $`bunx remotion still ${buildDir} --image-format=jpeg react-svg ${outFile}`.cwd(- exampleDir,- );-- expect(existsSync(outFile)).toBe(true);- expect(isJpeg(outFile)).toBe(true);- unlinkSync(outFile);- },- {timeout: 90000},-);--test(- '--image-format=png produces a PNG still',- async () => {- const outFile = path.join(tmpdir(), 'remotion-test', 'still-fmt-png.png');-- await $`bunx remotion still ${buildDir} --image-format=png react-svg ${outFile}`.cwd(- exampleDir,- );-- expect(existsSync(outFile)).toBe(true);- expect(isPng(outFile)).toBe(true);- unlinkSync(outFile);- },- {timeout: 90000},-);--test(- 'Config.setStillImageFormat works via the option',- async () => {- const {stillImageFormatOption} = BrowserSafeApis.options;-- stillImageFormatOption.setConfig('jpeg');-- const composition = await selectComposition({- serveUrl: buildDir,- id: 'react-svg',- inputProps: {},- });-- const folder = path.join(tmpdir(), 'remotion-test', 'still-fmt-config');- const testOut = path.join(folder, 'still.jpeg');-- await renderStill({- composition,- output: testOut,- serveUrl: buildDir,- imageFormat:- stillImageFormatOption.getValue({commandLine: {}}).value ?? undefined,- });-- expect(existsSync(testOut)).toBe(true);- expect(isJpeg(testOut)).toBe(true);- unlinkSync(testOut);- RenderInternals.deleteDirectory(folder);-- stillImageFormatOption.setConfig(null);- },- {timeout: 90000},-);--test(- 'CLI --image-format takes precedence over Config.setStillImageFormat',- async () => {- const {stillImageFormatOption} = BrowserSafeApis.options;-- stillImageFormatOption.setConfig('jpeg');-- const resolved = stillImageFormatOption.getValue({- commandLine: {'image-format': 'png'},- });-- expect(resolved.value).toBe('png');- expect(resolved.source).toBe('cli');-- const configOnly = stillImageFormatOption.getValue({- commandLine: {},- });-- expect(configOnly.value).toBe('jpeg');- expect(configOnly.source).toBe('config');-- stillImageFormatOption.setConfig(null);-- const defaultVal = stillImageFormatOption.getValue({- commandLine: {},- });-- expect(defaultVal.value).toBeNull();- expect(defaultVal.source).toBe('default');- },- {timeout: 90000},-);diff --git a/packages/renderer/src/options/still-image-format.tsx b/packages/renderer/src/options/still-image-format.tsxindex a63b748e21..bc6fa741b0 100644--- a/packages/renderer/src/options/still-image-format.tsx+++ b/packages/renderer/src/options/still-image-format.tsx@@ -16,7 +16,7 @@ export const stillImageFormatOption = {<code>"png"</code>.</>),- ssrName: 'stillImageFormat' as const,+ ssrName: 'imageFormat' as const,docLink: 'https://www.remotion.dev/docs/renderer/render-still#imageformat',type: null as StillImageFormat | null,getValue: ({commandLine}) => {