π₯ Make videos programmatically with React
pixel-format as an option
Jonny Burgercee2856387c2
diff --git a/.claude/skills/add-cli-option/SKILL.md b/.claude/skills/add-cli-option/SKILL.mdindex 6d9f2ca5bf..cf649cc87f 100644--- a/.claude/skills/add-cli-option/SKILL.md+++ b/.claude/skills/add-cli-option/SKILL.md@@ -75,17 +75,19 @@ For Studio options, this is typically in `packages/cli/src/studio.ts`. For rende- Add the setter signature to the `FlatConfig` type (either in the `RemotionConfigObject` global interface or the `FlatConfig` intersection)- Add the implementation to the `Config` object: `setMyFlagEnabled: myFlagOption.setConfig`-## 6. Update docs+## 6. Update docs β IMPORTANT, do not skip this step-In the relevant CLI command page:+**This step is mandatory.** Every new option must have its docs updated to use `<Options id="..." />` so the description is pulled from the option definition automatically (single source of truth). If converting an existing hardcoded flag, replace any hand-written description with the `<Options>` component.-- Add a `### \`--my-flag\`` section-- Use `<Options id="my-flag" />` to pull the description from the option definition automatically-- The `id` matches the option's `cliFlag` value+**CLI command pages** (check all that apply β `cli/render.mdx`, `lambda/cli/render.mdx`, `cloudrun/cli/render.mdx`, `cli/benchmark.mdx`):++- Add or update the `### \`--my-flag\`` section+- Use `<Options id="my-flag" />` as the description body (no import needed β it's globally available)+- The `id` must match the option's `cliFlag` / `id` value**`packages/docs/docs/config.mdx`**:-- Add a `## \`setMyFlagEnabled()\`` section with:+- Add or update the `## \`setMyFlagEnabled()\`` section with:- `<Options id="my-flag" />` for the description- A twoslash config example- A note that the CLI flag takes precedencediff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex f52eb29649..407f42e9ae 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -13,7 +13,6 @@ import {defaultOverrideFunction,getWebpackOverrideFn,} from './override-webpack';-import {getPixelFormat} from './pixel-format';import {getRendererPortFromConfigFile,getRendererPortFromConfigFileAndCliFlag,@@ -65,7 +64,6 @@ import {getShouldOpenBrowser, setShouldOpenBrowser} from './open-browser';import {setOutputLocation} from './output-location';import type {WebpackOverrideFn} from './override-webpack';import {overrideWebpackConfig} from './override-webpack';-import {setPixelFormat} from './pixel-format';import {setPort, setRendererPort, setStudioPort} from './preview-server';import {setProResProfile} from './prores-profile';import {getChromiumUserAgent, setChromiumUserAgent} from './user-agent';@@ -124,6 +122,7 @@ const {forceNewStudioOption,numberOfSharedAudioTagsOption,ipv4Option,+ pixelFormatOption,stillImageFormatOption,videoImageFormatOption,} = BrowserSafeApis.options;@@ -701,7 +700,7 @@ export const Config: FlatConfig = {setOutputLocation,setOverwriteOutput: overwriteOption.setConfig,setChromeMode: chromeModeOption.setConfig,- setPixelFormat,+ setPixelFormat: pixelFormatOption.setConfig,setCodec: videoCodecOption.setConfig,setCrf: crfOption.setConfig,setImageSequence,@@ -740,7 +739,6 @@ export const Config: FlatConfig = {export const ConfigInternals = {getRange,getBrowser,- getPixelFormat,getProResProfile,getBrowserExecutable,getStudioPort,diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex a77b3e2e25..c339332b53 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -1,11 +1,15 @@import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';+import {BrowserSafeApis} from '@remotion/renderer/client';import fs from 'node:fs';import path from 'node:path';import {ConfigInternals} from './config';import {getEnvironmentVariables} from './get-env';import {getInputProps} from './get-input-props';import {Log} from './log';+import {parsedCli} from './parsed-cli';++const {pixelFormatOption} = BrowserSafeApis.options;const getAndValidateFrameRange = (logLevel: LogLevel, indent: boolean) => {const frameRange = ConfigInternals.getRange();@@ -64,7 +68,9 @@ export const getCliOptions = (options: {? true: ConfigInternals.getShouldOutputImageSequence(frameRange);- const pixelFormat = ConfigInternals.getPixelFormat();+ const pixelFormat = pixelFormatOption.getValue({+ commandLine: parsedCli,+ }).value;const proResProfile = getProResProfile();const browserExecutable = ConfigInternals.getBrowserExecutable();diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.tsindex 97324c142b..1283dae671 100644--- a/packages/cli/src/get-render-defaults.ts+++ b/packages/cli/src/get-render-defaults.ts@@ -31,6 +31,7 @@ const {chromeModeOption,mediaCacheSizeInBytesOption,darkModeOption,+ pixelFormatOption,publicLicenseKeyOption,stillImageFormatOption,videoImageFormatOption,@@ -45,7 +46,9 @@ export const getRenderDefaults = (): RenderDefaults => {const concurrency = RenderInternals.resolveConcurrency(ConfigInternals.getConcurrency(),);- const pixelFormat = ConfigInternals.getPixelFormat();+ const pixelFormat = pixelFormatOption.getValue({+ commandLine: parsedCli,+ }).value;const proResProfile = ConfigInternals.getProResProfile() ?? null;const x264Preset = x264Option.getValue({diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex 67a498fead..27a7a263d1 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -3,7 +3,6 @@ import type {BrowserExecutable,Codec,OpenGlRenderer,- PixelFormat,StillImageFormat,VideoImageFormat,} from '@remotion/renderer';@@ -38,11 +37,12 @@ const {forceNewStudioOption,numberOfSharedAudioTagsOption,ipv4Option,+ pixelFormatOption,} = BrowserSafeApis.options;export type CommandLineOptions = {['browser-executable']: BrowserExecutable;- ['pixel-format']: PixelFormat;+ [pixelFormatOption.cliFlag]: TypeOfOption<typeof pixelFormatOption>;['image-format']: VideoImageFormat | StillImageFormat;['prores-profile']: _InternalTypes['ProResProfile'];[x264Option.cliFlag]: TypeOfOption<typeof x264Option>;@@ -127,10 +127,6 @@ export type CommandLineOptions = {};export const parseCommandLine = () => {- if (parsedCli['pixel-format']) {- Config.setPixelFormat(parsedCli['pixel-format']);- }-if (parsedCli['browser-executable']) {Config.setBrowserExecutable(parsedCli['browser-executable']);}diff --git a/packages/cli/src/test/pixel-format.test.ts b/packages/cli/src/test/pixel-format.test.tsindex 6d538a3c5e..6d8bbcaf36 100644--- a/packages/cli/src/test/pixel-format.test.ts+++ b/packages/cli/src/test/pixel-format.test.ts@@ -1,8 +1,10 @@import type {PixelFormat} from '@remotion/renderer';+import {BrowserSafeApis} from '@remotion/renderer/client';import {describe, expect, test} from 'bun:test';-import {getPixelFormat, setPixelFormat} from '../config/pixel-format';import {expectToThrow} from './expect-to-throw';+const {pixelFormatOption} = BrowserSafeApis.options;+describe('pixel-format tests setPixelFormat', () => {// input formatconst validPixelFormats: PixelFormat[] = [@@ -16,8 +18,10 @@ describe('pixel-format tests setPixelFormat', () => {];validPixelFormats.forEach((entry) =>test(`test for ${entry}`, () => {- setPixelFormat(entry);- expect(getPixelFormat()).toEqual(entry);+ pixelFormatOption.setConfig(entry);+ expect(pixelFormatOption.getValue({commandLine: {}}).value).toEqual(+ entry,+ );}),);@@ -27,7 +31,7 @@ describe('pixel-format tests setPixelFormat', () => {test(`test for invalid input ${entry}`, () =>expectToThrow(// @ts-expect-error- () => setPixelFormat(entry),+ () => pixelFormatOption.setConfig(entry),new RegExp(`Value ${entry} is not valid as a pixel format.`),)),);diff --git a/packages/docs/docs/cli/render.mdx b/packages/docs/docs/cli/render.mdxindex 1d18d7ac9f..3ee9bd4e00 100644--- a/packages/docs/docs/cli/render.mdx+++ b/packages/docs/docs/cli/render.mdx@@ -45,7 +45,7 @@ Inline JSON string isn't supported on Windows shells because it removes the `"`### `--pixel-format`-[Set a custom pixel format. See here for available values.](/docs/config#setpixelformat)+<Options id="pixel-format" />### `--image-format`<AvailableFrom v="1.4.0" />diff --git a/packages/docs/docs/cloudrun/cli/render.mdx b/packages/docs/docs/cloudrun/cli/render.mdxindex 74b9ee7584..ad6a27ecc1 100644--- a/packages/docs/docs/cloudrun/cli/render.mdx+++ b/packages/docs/docs/cloudrun/cli/render.mdx@@ -175,7 +175,7 @@ You will be responsible for ensuring that the render ID is unique, otherwise it### `--pixel-format`-[Set a custom pixel format. See here for available values.](/docs/config#setpixelformat)+<Options id="pixel-format" />### `--every-nth-frame`diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdxindex 442545e582..cb132b15b2 100644--- a/packages/docs/docs/config.mdx+++ b/packages/docs/docs/config.mdx@@ -519,8 +519,7 @@ In version 1.x, the default behavior was inverse - Remotion would not override b## `setPixelFormat()`-Controls the pixel format in FFmpeg. [Read more about it here.](https://trac.ffmpeg.org/wiki/Chroma%20Subsampling) Acceptable values: `yuv420p`, `yuv422p`, `yuv444p`, `yuv420p10le`, `yuv422p10le`, `yuv444p10le`. Since v1.4, `yuva420p` is also supported for transparent WebM videos. Since v2.1.7, `yuva444p10le` is also supported for transparent ProRes videos-Default value: `yuv420p`+<Options id="pixel-format" />```ts twoslash title="remotion.config.ts"import {Config} from '@remotion/cli/config';diff --git a/packages/docs/docs/lambda/cli/render.mdx b/packages/docs/docs/lambda/cli/render.mdxindex 068e23e985..9b41b953d9 100644--- a/packages/docs/docs/lambda/cli/render.mdx+++ b/packages/docs/docs/lambda/cli/render.mdx@@ -174,7 +174,7 @@ Renamed to `jpegQuality` in `v4.0.0`.### `--pixel-format`-[Set a custom pixel format. See here for available values.](/docs/config#setpixelformat)+<Options id="pixel-format" />### `--image-format`diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsxindex dc87d42a40..d98858ffaf 100644--- a/packages/renderer/src/options/index.tsx+++ b/packages/renderer/src/options/index.tsx@@ -41,6 +41,7 @@ import {offthreadVideoThreadsOption} from './offthreadvideo-threads';import {onBrowserDownloadOption} from './on-browser-download';import type {AnyRemotionOption} from './option';import {overwriteOption} from './overwrite';+import {pixelFormatOption} from './pixel-format';import {preferLosslessAudioOption} from './prefer-lossless';import {publicDirOption} from './public-dir';import {publicLicenseKeyOption} from './public-license-key';@@ -83,6 +84,7 @@ export const allOptions = {beepOnFinishOption,numberOfGifLoopsOption,reproOption,+ pixelFormatOption,preferLosslessOption: preferLosslessAudioOption,x264Option,logLevelOption,diff --git a/packages/renderer/src/options/pixel-format.tsx b/packages/renderer/src/options/pixel-format.tsxnew file mode 100644index 0000000000..a82e82f3a9--- /dev/null+++ b/packages/renderer/src/options/pixel-format.tsx@@ -0,0 +1,52 @@+import type {PixelFormat} from '../pixel-format';+import {DEFAULT_PIXEL_FORMAT, validPixelFormats} from '../pixel-format';+import type {AnyRemotionOption} from './option';++let currentPixelFormat: PixelFormat = DEFAULT_PIXEL_FORMAT;++const cliFlag = 'pixel-format' as const;++export const pixelFormatOption = {+ name: 'Pixel format',+ cliFlag,+ description: () => (+ <>+ Sets the pixel format in FFmpeg. See{' '}+ <a href="https://trac.ffmpeg.org/wiki/Chroma%20Subsampling">+ the FFmpeg docs for an explanation+ </a>+ . Acceptable values: {validPixelFormats.map((f) => `"${f}"`).join(', ')}.+ </>+ ),+ ssrName: 'pixelFormat' as const,+ docLink: 'https://www.remotion.dev/docs/config#setpixelformat',+ type: DEFAULT_PIXEL_FORMAT as PixelFormat,+ getValue: ({commandLine}) => {+ if (commandLine[cliFlag] !== undefined) {+ return {+ source: 'cli',+ value: commandLine[cliFlag] as PixelFormat,+ };+ }++ if (currentPixelFormat !== DEFAULT_PIXEL_FORMAT) {+ return {+ source: 'config',+ value: currentPixelFormat,+ };+ }++ return {+ source: 'default',+ value: DEFAULT_PIXEL_FORMAT,+ };+ },+ setConfig: (value) => {+ if (!validPixelFormats.includes(value)) {+ throw new TypeError(`Value ${value} is not valid as a pixel format.`);+ }++ currentPixelFormat = value;+ },+ id: cliFlag,+} satisfies AnyRemotionOption<PixelFormat>;