Skip to content

🎥 Make videos programmatically with React

core: Add defaultVideoImageFormat and defaultPixelFormat to composition types

copilot-swe-agent[bot]83d60dc3ed9c
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsx
index 6e88013339..b33fba55d0 100644
--- a/packages/core/src/Composition.tsx
+++ b/packages/core/src/Composition.tsx
@@ -21,6 +21,7 @@ import {Loading} from './loading-indicator.js';
import {useNonce} from './nonce.js';
import {portalNode} from './portal-node.js';
import type {InferProps, PropsIfHasProps} from './props-if-has-props.js';
+import type {PixelFormat, VideoImageFormat} from './render-types.js';
import {useLazyComponent} from './use-lazy-component.js';
import {useVideo} from './use-video.js';
import {validateCompositionId} from './validation/validate-composition-id.js';
@@ -44,6 +45,8 @@ export type CalcMetadataReturnType<T extends Record<string, unknown>> = {
props?: T;
defaultCodec?: Codec;
defaultOutName?: string;
+ defaultVideoImageFormat?: VideoImageFormat;
+ defaultPixelFormat?: PixelFormat;
};
export type CalculateMetadataFunction<T extends Record<string, unknown>> =
diff --git a/packages/core/src/CompositionManagerContext.tsx b/packages/core/src/CompositionManagerContext.tsx
index 6f325270d9..ae962b0abd 100644
--- a/packages/core/src/CompositionManagerContext.tsx
+++ b/packages/core/src/CompositionManagerContext.tsx
@@ -14,6 +14,8 @@ export type BaseMetadata = Pick<
| 'width'
| 'defaultCodec'
| 'defaultOutName'
+ | 'defaultVideoImageFormat'
+ | 'defaultPixelFormat'
>;
export type CanvasContent =
diff --git a/packages/core/src/ResolveCompositionConfig.tsx b/packages/core/src/ResolveCompositionConfig.tsx
index 10ffced13c..d23783df07 100644
--- a/packages/core/src/ResolveCompositionConfig.tsx
+++ b/packages/core/src/ResolveCompositionConfig.tsx
@@ -485,6 +485,8 @@ export const useResolvedVideoConfig = (
},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
},
};
}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index bbc27aa38a..c350078f0b 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -14,6 +14,7 @@ import {useIsPlayer} from './is-player.js';
import type {LogLevel} from './log.js';
import {checkMultipleRemotionVersions} from './multiple-versions-warning.js';
import {Null} from './Null.js';
+import type {PixelFormat, VideoImageFormat} from './render-types.js';
import {Sequence} from './Sequence.js';
import type {VideoConfig} from './video-config.js';
@@ -90,6 +91,8 @@ export type BundleCompositionState = {
compositionFps: number;
compositionDefaultCodec: Codec;
compositionDefaultOutName: string | null;
+ compositionDefaultVideoImageFormat: VideoImageFormat | null;
+ compositionDefaultPixelFormat: PixelFormat | null;
};
export type BundleIndexState = {
@@ -143,6 +146,7 @@ export {
} from './no-react';
export {prefetch, PrefetchOnProgress} from './prefetch.js';
export {registerRoot} from './register-root.js';
+export type {PixelFormat, VideoImageFormat} from './render-types.js';
export {
AbsoluteFillLayout,
LayoutAndStyle,
diff --git a/packages/core/src/render-types.ts b/packages/core/src/render-types.ts
new file mode 100644
index 0000000000..fed1c9011f
--- /dev/null
+++ b/packages/core/src/render-types.ts
@@ -0,0 +1,18 @@
+// Types copied from @remotion/renderer for use in core composition metadata
+// This avoids circular dependencies while keeping renderer as the source of truth
+
+export const validVideoImageFormats = ['png', 'jpeg', 'none'] as const;
+export type VideoImageFormat = (typeof validVideoImageFormats)[number];
+
+export const validPixelFormats = [
+ 'yuv420p',
+ 'yuva420p',
+ 'yuv422p',
+ 'yuv444p',
+ 'yuv420p10le',
+ 'yuv422p10le',
+ 'yuv444p10le',
+ 'yuva444p10le',
+] as const;
+
+export type PixelFormat = (typeof validPixelFormats)[number];
diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.ts
index 7e452e21a5..a44ee4afdf 100644
--- a/packages/core/src/resolve-video-config.ts
+++ b/packages/core/src/resolve-video-config.ts
@@ -65,8 +65,19 @@ const validateCalculated = ({
validateDefaultCodec(defaultCodec, calculateMetadataErrorLocation);
const defaultOutName = calculated?.defaultOutName;
+ const defaultVideoImageFormat = calculated?.defaultVideoImageFormat;
+ const defaultPixelFormat = calculated?.defaultPixelFormat;
- return {width, height, fps, durationInFrames, defaultCodec, defaultOutName};
+ return {
+ width,
+ height,
+ fps,
+ durationInFrames,
+ defaultCodec,
+ defaultOutName,
+ defaultVideoImageFormat,
+ defaultPixelFormat,
+ };
};
type ResolveVideoConfigParams = {
@@ -116,6 +127,8 @@ export const resolveVideoConfig = ({
fps,
defaultCodec,
defaultOutName,
+ defaultVideoImageFormat,
+ defaultPixelFormat,
} = validateCalculated({
calculated: c,
compositionDurationInFrames,
@@ -134,6 +147,8 @@ export const resolveVideoConfig = ({
props: serializeThenDeserializeInStudio(c.props ?? originalProps),
defaultCodec: defaultCodec ?? null,
defaultOutName: defaultOutName ?? null,
+ defaultVideoImageFormat: defaultVideoImageFormat ?? null,
+ defaultPixelFormat: defaultPixelFormat ?? null,
};
});
}
@@ -155,6 +170,8 @@ export const resolveVideoConfig = ({
props: serializeThenDeserializeInStudio(originalProps),
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
};
}
@@ -167,6 +184,8 @@ export const resolveVideoConfig = ({
),
defaultCodec: calculatedProm.defaultCodec ?? null,
defaultOutName: calculatedProm.defaultOutName ?? null,
+ defaultVideoImageFormat: calculatedProm.defaultVideoImageFormat ?? null,
+ defaultPixelFormat: calculatedProm.defaultPixelFormat ?? null,
};
};
diff --git a/packages/core/src/test/use-media-in-timeline.test.tsx b/packages/core/src/test/use-media-in-timeline.test.tsx
index b2865bff56..8a5cb3a2ea 100644
--- a/packages/core/src/test/use-media-in-timeline.test.tsx
+++ b/packages/core/src/test/use-media-in-timeline.test.tsx
@@ -32,6 +32,8 @@ beforeAll(() => {
props: {},
defaultCodec: null,
defaultOutName: null,
+ defaultVideoImageFormat: null,
+ defaultPixelFormat: null,
}));
});
afterAll(() => {
diff --git a/packages/core/src/use-unsafe-video-config.ts b/packages/core/src/use-unsafe-video-config.ts
index 82cc79e60c..edc86d8135 100644
--- a/packages/core/src/use-unsafe-video-config.ts
+++ b/packages/core/src/use-unsafe-video-config.ts
@@ -25,6 +25,8 @@ export const useUnsafeVideoConfig = (): VideoConfig | null => {
props,
defaultCodec,
defaultOutName,
+ defaultVideoImageFormat,
+ defaultPixelFormat,
} = video;
return {
@@ -37,6 +39,8 @@ export const useUnsafeVideoConfig = (): VideoConfig | null => {
props,
defaultCodec,
defaultOutName,
+ defaultVideoImageFormat,
+ defaultPixelFormat,
};
}, [ctxDuration, ctxHeight, ctxWidth, video]);
};
diff --git a/packages/core/src/video-config.ts b/packages/core/src/video-config.ts
index cd881e84a1..3eb2848157 100644
--- a/packages/core/src/video-config.ts
+++ b/packages/core/src/video-config.ts
@@ -1,4 +1,5 @@
import type {Codec} from './codec';
+import type {PixelFormat, VideoImageFormat} from './render-types';
export type VideoConfig = {
width: number;
@@ -10,4 +11,6 @@ export type VideoConfig = {
props: Record<string, unknown>;
defaultCodec: Codec | null;
defaultOutName: string | null;
+ defaultVideoImageFormat: VideoImageFormat | null;
+ defaultPixelFormat: PixelFormat | null;
};