Skip to content

🎥 Make videos programmatically with React

renderer: Update VideoConfig usage for new fields and fix documentation

copilot-swe-agent[bot]96b8c935d3b4
diff --git a/packages/docs/docs/4-0-migration.mdx b/packages/docs/docs/4-0-migration.mdx
index fba926546d..0fd4180738 100644
--- a/packages/docs/docs/4-0-migration.mdx
+++ b/packages/docs/docs/4-0-migration.mdx
@@ -327,6 +327,8 @@ const composition = {
defaultProps: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
} as const;
// ---cut---
diff --git a/packages/docs/docs/artifacts.mdx b/packages/docs/docs/artifacts.mdx
index 37c84da487..53647497f5 100644
--- a/packages/docs/docs/artifacts.mdx
+++ b/packages/docs/docs/artifacts.mdx
@@ -88,6 +88,8 @@ const composition: VideoConfig = {
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
id: 'hi',
durationInFrames: 100,
};
diff --git a/packages/docs/docs/calculate-metadata.mdx b/packages/docs/docs/calculate-metadata.mdx
index 343586094b..c526db8da2 100644
--- a/packages/docs/docs/calculate-metadata.mdx
+++ b/packages/docs/docs/calculate-metadata.mdx
@@ -22,7 +22,10 @@ Use it if you:
<Step>3</Step> want to add a per-composition default codec
</div>
<div>
-<Step>4</Step> want to run code once, before the actual render starts.
+<Step>4</Step> want to add per-composition default video image format or pixel format
+</div>
+<div>
+<Step>5</Step> want to run code once, before the actual render starts.
</div>
The `calculateMetadata()` function is called a single time, independently from the concurrency of the render.
@@ -58,6 +61,10 @@ const calculateMetadata: CalculateMetadataFunction<MyComponentProps> = ({props,
props,
// or add per-composition default codec
defaultCodec: 'h264',
+ // or add per-composition default video image format
+ defaultVideoImageFormat: 'png',
+ // or add per-composition default pixel format
+ defaultPixelFormat: 'yuv420p',
};
};
@@ -96,6 +103,8 @@ The function must return an pure JSON-serializable object, which can contain the
- `fps` _optional_: The frames per second of the composition
- `defaultCodec` _optional_: The default codec to use for the composition.
- `defaultOutName` _optional_: The default output name when rendering (without file extension) <AvailableFrom v="4.0.268" />
+- `defaultVideoImageFormat` _optional_: The default video image format (`'png'`, `'jpeg'`, or `'none'`) <AvailableFrom v="4.0.316" />
+- `defaultPixelFormat` _optional_: The default pixel format (`'yuv420p'`, `'yuva420p'`, `'yuv422p'`, `'yuv444p'`, `'yuv420p10le'`, `'yuv422p10le'`, `'yuv444p10le'`, or `'yuva444p10le'`) <AvailableFrom v="4.0.316" />
If you return a field, it will take precendence over the props directly passed to the composition. The defaultCodec returned will have a higher priority than the config file, but less priority than explicitly passing the option to renderMedia() i.e. the composition will be rendered with this codec if nothing with higher priority was specified.
diff --git a/packages/docs/docs/renderer/make-cancel-signal.mdx b/packages/docs/docs/renderer/make-cancel-signal.mdx
index dfbc3b80fd..032aea08d6 100644
--- a/packages/docs/docs/renderer/make-cancel-signal.mdx
+++ b/packages/docs/docs/renderer/make-cancel-signal.mdx
@@ -24,6 +24,8 @@ const composition: VideoConfig = {
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
};
// ---cut---
import {makeCancelSignal, renderMedia} from '@remotion/renderer';
diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.ts
index 08e95827e3..53d1d89984 100644
--- a/packages/renderer/src/get-compositions.ts
+++ b/packages/renderer/src/get-compositions.ts
@@ -123,6 +123,8 @@ const innerGetCompositions = async ({
id,
defaultCodec,
defaultOutName,
+ defaultVideoImageFormat,
+ defaultPixelFormat,
} = r;
return {
@@ -139,6 +141,8 @@ const innerGetCompositions = async ({
),
defaultCodec,
defaultOutName,
+ defaultVideoImageFormat,
+ defaultPixelFormat,
};
});
};
diff --git a/packages/renderer/src/make-page.ts b/packages/renderer/src/make-page.ts
index e010bc8407..ab3a75916a 100644
--- a/packages/renderer/src/make-page.ts
+++ b/packages/renderer/src/make-page.ts
@@ -5,6 +5,7 @@ import type {SourceMapGetter} from './browser/source-map-getter';
import type {Codec} from './codec';
import type {VideoImageFormat} from './image-format';
import type {LogLevel} from './log-level';
+import type {PixelFormat} from './pixel-format';
import {puppeteerEvaluateWithCatch} from './puppeteer-evaluate';
import type {BrowserReplacer} from './replace-browser';
import {setPropsAndEnv} from './set-props-and-env';
@@ -85,6 +86,8 @@ export const makePage = async ({
width: number,
defaultCodec: Codec,
defaultOutName: string | null,
+ defaultVideoImageFormat: VideoImageFormat | null,
+ defaultPixelFormat: PixelFormat | null,
) => {
window.remotion_setBundleMode({
type: 'composition',
@@ -96,6 +99,8 @@ export const makePage = async ({
compositionWidth: width,
compositionDefaultCodec: defaultCodec,
compositionDefaultOutName: defaultOutName,
+ compositionDefaultVideoImageFormat: defaultVideoImageFormat,
+ compositionDefaultPixelFormat: defaultPixelFormat,
});
},
args: [
@@ -107,6 +112,8 @@ export const makePage = async ({
composition.width,
composition.defaultCodec,
composition.defaultOutName,
+ composition.defaultVideoImageFormat,
+ composition.defaultPixelFormat,
],
frame: null,
page,
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index df94b0723f..9a66df2882 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -16,7 +16,7 @@ import {ensureOutputDirectory} from './ensure-output-directory';
import {handleJavascriptException} from './error-handling/handle-javascript-exception';
import {onlyArtifact} from './filter-asset-types';
import {findRemotionRoot} from './find-closest-package-json';
-import type {StillImageFormat} from './image-format';
+import type {StillImageFormat, VideoImageFormat} from './image-format';
import {
DEFAULT_STILL_IMAGE_FORMAT,
validateStillImageFormat,
@@ -30,6 +30,7 @@ import {internalOpenBrowser} from './open-browser';
import type {ToOptions} from './options/option';
import type {optionsMap} from './options/options-map';
import {DEFAULT_OVERWRITE} from './overwrite';
+import type {PixelFormat} from './pixel-format';
import type {RemotionServer} from './prepare-server';
import {makeOrReuseServer} from './prepare-server';
import {puppeteerEvaluateWithCatch} from './puppeteer-evaluate';
@@ -275,6 +276,8 @@ const innerRenderStill = async ({
width: number,
defaultCodec: Codec,
defaultOutName: string | null,
+ defaultVideoImageFormat: VideoImageFormat | null,
+ defaultPixelFormat: PixelFormat | null,
) => {
window.remotion_setBundleMode({
type: 'composition',
@@ -286,6 +289,8 @@ const innerRenderStill = async ({
compositionWidth: width,
compositionDefaultCodec: defaultCodec,
compositionDefaultOutName: defaultOutName,
+ compositionDefaultVideoImageFormat: defaultVideoImageFormat,
+ compositionDefaultPixelFormat: defaultPixelFormat,
});
},
args: [
@@ -297,6 +302,8 @@ const innerRenderStill = async ({
composition.width,
composition.defaultCodec,
composition.defaultOutName,
+ composition.defaultVideoImageFormat,
+ composition.defaultPixelFormat,
],
frame: null,
page,
diff --git a/packages/renderer/src/select-composition.ts b/packages/renderer/src/select-composition.ts
index f2fb8bad74..833362918b 100644
--- a/packages/renderer/src/select-composition.ts
+++ b/packages/renderer/src/select-composition.ts
@@ -143,8 +143,16 @@ const innerSelectComposition = async ({
ReturnType<typeof window.remotion_calculateComposition>
>;
- const {width, durationInFrames, fps, height, defaultCodec, defaultOutName} =
- res;
+ const {
+ width,
+ durationInFrames,
+ fps,
+ height,
+ defaultCodec,
+ defaultOutName,
+ defaultVideoImageFormat,
+ defaultPixelFormat,
+ } = res;
return {
metadata: {
id,
@@ -160,6 +168,8 @@ const innerSelectComposition = async ({
),
defaultCodec,
defaultOutName,
+ defaultVideoImageFormat,
+ defaultPixelFormat,
},
propsSize: size,
};
diff --git a/packages/renderer/src/test/render-still.test.ts b/packages/renderer/src/test/render-still.test.ts
index 8f28672e73..626b95c62e 100644
--- a/packages/renderer/src/test/render-still.test.ts
+++ b/packages/renderer/src/test/render-still.test.ts
@@ -21,6 +21,8 @@ test(
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
frame: 0,
output: '/file/output.png',
@@ -49,6 +51,8 @@ test(
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
frame: 0,
serveUrl:
@@ -77,6 +81,8 @@ test(
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
frame: 200,
output: '/file/output.png',
@@ -106,6 +112,8 @@ test(
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
// @ts-expect-error
imageFormat: 'jjj',
diff --git a/packages/renderer/src/test/validate-config.test.ts b/packages/renderer/src/test/validate-config.test.ts
index fd75a8e9a1..d4d969d3a9 100644
--- a/packages/renderer/src/test/validate-config.test.ts
+++ b/packages/renderer/src/test/validate-config.test.ts
@@ -16,6 +16,8 @@ describe('Should validate invalid data passed to renderFrames', () => {
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
}),
).toThrow(
@@ -36,6 +38,8 @@ describe('Should validate invalid data passed to renderFrames', () => {
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
}),
).toThrow(
@@ -56,6 +60,8 @@ describe('Should validate invalid data passed to renderFrames', () => {
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
}),
).toThrow(
@@ -76,6 +82,8 @@ describe('Should validate invalid data passed to renderFrames', () => {
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
}),
).toThrow(