Skip to content

🎥 Make videos programmatically with React

no fields optional

Jonny Burger761b9c144270
diff --git a/packages/bundler/src/renderEntry.tsx b/packages/bundler/src/renderEntry.tsx
index 8b9698fd10..d0c9d5874a 100644
--- a/packages/bundler/src/renderEntry.tsx
+++ b/packages/bundler/src/renderEntry.tsx
@@ -88,6 +88,7 @@ const GetVideo: React.FC<{state: BundleState}> = ({state}) => {
fps: state.compositionFps,
height: state.compositionHeight,
width: state.compositionWidth,
+ defaultCodec: state.compositionDefaultCodec,
});
}
}, [compositions, compositions.compositions, state, video]);
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index a916494a16..26dce4638b 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -267,15 +267,15 @@ export const benchmarkCommand = async (
let count = 1;
- const {codec, reason: codecReason} = getFinalOutputCodec({
- cliFlag: parsedCli.codec,
- downloadName: null,
- outName: null,
- configFile: ConfigInternals.getOutputCodecOrUndefined() ?? null,
- uiCodec: null,
- });
-
for (const composition of compositions) {
+ const {codec, reason: codecReason} = getFinalOutputCodec({
+ cliFlag: parsedCli.codec,
+ downloadName: null,
+ outName: null,
+ configFile: ConfigInternals.getOutputCodecOrUndefined() ?? null,
+ uiCodec: null,
+ compositionCodec: composition.defaultCodec ?? null,
+ });
const concurrency = getValidConcurrency(unparsedConcurrency);
benchmark[composition.id] = {};
diff --git a/packages/cli/src/get-final-output-codec.ts b/packages/cli/src/get-final-output-codec.ts
index ef8c31d43a..7f411463be 100644
--- a/packages/cli/src/get-final-output-codec.ts
+++ b/packages/cli/src/get-final-output-codec.ts
@@ -21,21 +21,20 @@ const deriveCodecsFromFilename = (
};
export const getFinalOutputCodec = ({
- cliFlag,
- configFile,
- downloadName,
- outName,
- uiCodec,
- defaultCodec,
- }: {
- cliFlag: CodecOrUndefined;
- outName: string | null;
- downloadName: string | null;
- configFile: Codec | null;
- uiCodec: Codec | null;
- defaultCodec?: Codec | null;
- }
-): {codec: Codec; reason: string} => {
+ cliFlag,
+ configFile,
+ downloadName,
+ outName,
+ uiCodec,
+ compositionCodec,
+}: {
+ cliFlag: CodecOrUndefined;
+ outName: string | null;
+ downloadName: string | null;
+ configFile: Codec | null;
+ uiCodec: Codec | null;
+ compositionCodec: Codec | null;
+}): {codec: Codec; reason: string} => {
if (uiCodec) {
return {codec: uiCodec, reason: 'via UI'};
}
@@ -98,8 +97,8 @@ export const getFinalOutputCodec = ({
};
}
- if (defaultCodec) {
- return {codec: defaultCodec, reason: 'default codec'};
+ if (compositionCodec) {
+ return {codec: compositionCodec, reason: 'default codec'};
}
if (configFile) {
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index 988812587a..8c1c92804c 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -282,8 +282,6 @@ export const renderVideoFlow = async ({
offthreadVideoCacheSizeInBytes,
});
- const defaultCodec = config.defaultCodec;
-
const {codec, reason: codecReason} = getFinalOutputCodec({
cliFlag: parsedCli.codec,
configFile: ConfigInternals.getOutputCodecOrUndefined() ?? null,
@@ -293,7 +291,7 @@ export const renderVideoFlow = async ({
outputLocationFromUI,
),
uiCodec,
- defaultCodec,
+ compositionCodec: config.defaultCodec,
});
RenderInternals.validateEvenDimensionsWithCodec({
diff --git a/packages/cli/src/test/final-output-codec.test.ts b/packages/cli/src/test/final-output-codec.test.ts
index ae24ef8f5b..bfefb720bf 100644
--- a/packages/cli/src/test/final-output-codec.test.ts
+++ b/packages/cli/src/test/final-output-codec.test.ts
@@ -22,6 +22,7 @@ describe('Codec tests valid codec input', () => {
configFile: null,
downloadName: null,
uiCodec: null,
+ compositionCodec: null,
}),
).toEqual({
codec: entry,
@@ -48,6 +49,7 @@ describe('Codec tests undefined codec input with known extension', () => {
downloadName: null,
outName: 'hi.' + entry[1],
uiCodec: null,
+ compositionCodec: null,
}),
).toEqual({
codec: entry[0],
@@ -65,6 +67,7 @@ test('Codec tests undefined codec input with unknown extension', () => {
configFile: null,
downloadName: null,
uiCodec: null,
+ compositionCodec: null,
}),
).toEqual({codec: 'h264', reason: 'default'});
expect(
@@ -74,6 +77,7 @@ test('Codec tests undefined codec input with unknown extension', () => {
configFile: null,
downloadName: null,
uiCodec: null,
+ compositionCodec: null,
}),
).toEqual({codec: 'h264', reason: 'default'});
});
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index 3619f01c32..9d7433850a 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -30,6 +30,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
outName: outName ?? null,
configFile: ConfigInternals.getOutputCodecOrUndefined() ?? null,
uiCodec: null,
+ compositionCodec: null,
});
const imageFormat = parsedCloudrunCli['image-format'];
diff --git a/packages/core/src/CompositionManagerContext.tsx b/packages/core/src/CompositionManagerContext.tsx
index f5064dfb51..cc8f3f369e 100644
--- a/packages/core/src/CompositionManagerContext.tsx
+++ b/packages/core/src/CompositionManagerContext.tsx
@@ -7,7 +7,7 @@ import type {VideoConfig} from './video-config.js';
export type BaseMetadata = Pick<
VideoConfig,
- 'durationInFrames' | 'fps' | 'props' | 'height' | 'width'
+ 'durationInFrames' | 'fps' | 'props' | 'height' | 'width' | 'defaultCodec'
>;
export type CanvasContent =
diff --git a/packages/core/src/ResolveCompositionConfig.tsx b/packages/core/src/ResolveCompositionConfig.tsx
index 42a735b4ff..fb416d5a90 100644
--- a/packages/core/src/ResolveCompositionConfig.tsx
+++ b/packages/core/src/ResolveCompositionConfig.tsx
@@ -268,6 +268,7 @@ export const useResolvedVideoConfig = (
id: composition.id,
props: currentCompositionMetadata.props,
defaultProps: composition.defaultProps ?? {},
+ defaultCodec: currentCompositionMetadata.defaultCodec,
},
};
}
@@ -290,6 +291,7 @@ export const useResolvedVideoConfig = (
? {}
: getInputProps() ?? {}),
},
+ defaultCodec: null,
},
};
}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 23c14f546f..d4dbd6655e 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -1,5 +1,6 @@
import './asset-types.js';
import {Clipper} from './Clipper.js';
+import type {Codec} from './codec.js';
import type {TRenderAsset} from './CompositionManager.js';
import type {StaticFile} from './get-static-files.js';
import {useIsPlayer} from './is-player.js';
@@ -72,6 +73,7 @@ export type BundleState =
compositionDurationInFrames: number;
compositionWidth: number;
compositionFps: number;
+ compositionDefaultCodec: Codec;
};
checkMultipleRemotionVersions();
diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.ts
index cec909f744..018edc9fe3 100644
--- a/packages/core/src/resolve-video-config.ts
+++ b/packages/core/src/resolve-video-config.ts
@@ -1,11 +1,11 @@
import type {AnyZodObject} from 'zod';
import type {CalcMetadataReturnType} from './Composition.js';
import type {TCompMetadataWithCalcFunction} from './CompositionManager.js';
+import {validateDefaultCodec} from './validation/validate-default-codec.js';
import {validateDimension} from './validation/validate-dimensions.js';
import {validateDurationInFrames} from './validation/validate-duration-in-frames.js';
import {validateFps} from './validation/validate-fps.js';
import type {VideoConfig} from './video-config.js';
-import { validateDefaultCodec } from './validation/validate-default-codec.js';
const validateCalculated = ({
composition,
@@ -95,10 +95,11 @@ export const resolveVideoConfig = ({
'then' in calculatedProm
) {
return calculatedProm.then((c) => {
- const {height, width, durationInFrames, fps, defaultCodec} = validateCalculated({
- calculated: c,
- composition,
- });
+ const {height, width, durationInFrames, fps, defaultCodec} =
+ validateCalculated({
+ calculated: c,
+ composition,
+ });
return {
width,
height,
@@ -107,7 +108,7 @@ export const resolveVideoConfig = ({
id: composition.id,
defaultProps: composition.defaultProps ?? {},
props: c.props ?? fallbackProps,
- defaultCodec,
+ defaultCodec: defaultCodec ?? null,
};
});
}
@@ -123,6 +124,7 @@ export const resolveVideoConfig = ({
id: composition.id,
defaultProps: composition.defaultProps ?? {},
props: fallbackProps,
+ defaultCodec: null,
};
}
@@ -131,5 +133,6 @@ export const resolveVideoConfig = ({
id: composition.id,
defaultProps: composition.defaultProps ?? {},
props: calculatedProm.props ?? fallbackProps,
+ defaultCodec: calculatedProm.defaultCodec ?? null,
};
-};
\ No newline at end of file
+};
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 a0275fd186..44382ccbf9 100644
--- a/packages/core/src/test/use-media-in-timeline.test.tsx
+++ b/packages/core/src/test/use-media-in-timeline.test.tsx
@@ -25,6 +25,7 @@ beforeAll(() => {
id: 'hithere',
defaultProps: {},
props: {},
+ defaultCodec: null,
}));
});
afterAll(() => {
diff --git a/packages/core/src/video-config.ts b/packages/core/src/video-config.ts
index 0e790b1c5a..598c687941 100644
--- a/packages/core/src/video-config.ts
+++ b/packages/core/src/video-config.ts
@@ -1,4 +1,4 @@
-import {Codec} from './codec';
+import type {Codec} from './codec';
export type VideoConfig = {
width: number;
@@ -8,5 +8,5 @@ export type VideoConfig = {
id: string;
defaultProps: Record<string, unknown>;
props: Record<string, unknown>;
- defaultCodec?: Codec | undefined;
+ defaultCodec: Codec | null;
};
diff --git a/packages/it-tests/src/ssr/cancel-after-success.test.ts b/packages/it-tests/src/ssr/cancel-after-success.test.ts
index dece26ec7c..49572a7213 100644
--- a/packages/it-tests/src/ssr/cancel-after-success.test.ts
+++ b/packages/it-tests/src/ssr/cancel-after-success.test.ts
@@ -18,6 +18,7 @@ test("Cancelling after success should not throw error", async () => {
width: 1280,
defaultProps: {},
props: {},
+ defaultCodec: null,
},
concurrency: 1,
outputLocation,
diff --git a/packages/it-tests/src/ssr/cancel-renderframes.test.ts b/packages/it-tests/src/ssr/cancel-renderframes.test.ts
index ba86b768b4..e5870b7d51 100644
--- a/packages/it-tests/src/ssr/cancel-renderframes.test.ts
+++ b/packages/it-tests/src/ssr/cancel-renderframes.test.ts
@@ -15,6 +15,7 @@ test("Should be able to cancel render", async () => {
width: 1280,
defaultProps: {},
props: {},
+ defaultCodec: null,
},
cancelSignal,
imageFormat: "jpeg",
diff --git a/packages/it-tests/src/ssr/cancel-rendermedia.test.ts b/packages/it-tests/src/ssr/cancel-rendermedia.test.ts
index e4414b40c4..303a7c591d 100644
--- a/packages/it-tests/src/ssr/cancel-rendermedia.test.ts
+++ b/packages/it-tests/src/ssr/cancel-rendermedia.test.ts
@@ -16,6 +16,7 @@ test("Should be able to cancel render", async () => {
width: 1280,
defaultProps: {},
props: {},
+ defaultCodec: null,
},
outputLocation: "out/render.mp4",
cancelSignal,
diff --git a/packages/it-tests/src/ssr/cancel-renderstill.test.ts b/packages/it-tests/src/ssr/cancel-renderstill.test.ts
index 796b40d41a..75427e5b20 100644
--- a/packages/it-tests/src/ssr/cancel-renderstill.test.ts
+++ b/packages/it-tests/src/ssr/cancel-renderstill.test.ts
@@ -15,6 +15,7 @@ test("Should be able to cancel render", async () => {
width: 1280,
defaultProps: {},
props: {},
+ defaultCodec: null,
},
cancelSignal,
output: "out/hithere.png",
diff --git a/packages/it-tests/src/ssr/fatal-error-correct-error.test.ts b/packages/it-tests/src/ssr/fatal-error-correct-error.test.ts
index 8596c9fc2f..e43b5177cc 100644
--- a/packages/it-tests/src/ssr/fatal-error-correct-error.test.ts
+++ b/packages/it-tests/src/ssr/fatal-error-correct-error.test.ts
@@ -15,6 +15,7 @@ test("Fatal error on frame 10 should yield correct error", async () => {
width: 1280,
defaultProps: {},
props: {},
+ defaultCodec: null,
},
outputLocation: "out/render.mp4",
});
diff --git a/packages/it-tests/src/ssr/render-media.test.ts b/packages/it-tests/src/ssr/render-media.test.ts
index e48b979074..c8b83b4bb0 100644
--- a/packages/it-tests/src/ssr/render-media.test.ts
+++ b/packages/it-tests/src/ssr/render-media.test.ts
@@ -84,6 +84,7 @@ test("should fail on invalid CRF", async () => {
width: 1080,
defaultProps: {},
props: {},
+ defaultCodec: null,
},
frameRange: [0, 2],
puppeteerInstance: browserInstance,
@@ -134,6 +135,7 @@ test("Should fail invalid serve URL", async () => {
id: "hitehre",
width: 1080,
props: {},
+ defaultCodec: null,
},
});
} catch (err) {
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 3610464781..9b35d99c3d 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -143,6 +143,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
outName: outName ?? null,
configFile: ConfigInternals.getOutputCodecOrUndefined() ?? null,
uiCodec: null,
+ compositionCodec: null,
});
const imageFormat = CliInternals.getVideoImageFormat({
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 69ebdd84fb..da74670002 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -124,6 +124,7 @@ const renderHandler = async (
fps: params.fps,
height: params.height,
width: params.width,
+ defaultCodec: null,
},
imageFormat: params.imageFormat,
serializedInputPropsWithCustomSchema,
diff --git a/packages/lambda/src/test/unit/expected-out-name.test.ts b/packages/lambda/src/test/unit/expected-out-name.test.ts
index 68b032267a..ac23f384a3 100644
--- a/packages/lambda/src/test/unit/expected-out-name.test.ts
+++ b/packages/lambda/src/test/unit/expected-out-name.test.ts
@@ -32,6 +32,7 @@ const testRenderMetadata: RenderMetadata = {
id: 'react-svg',
width: 1080,
props: {},
+ defaultCodec: null,
},
privacy: 'public',
everyNthFrame: 1,
diff --git a/packages/lambda/src/test/unit/price-calculation.test.ts b/packages/lambda/src/test/unit/price-calculation.test.ts
index 2594649ebc..0289b01267 100644
--- a/packages/lambda/src/test/unit/price-calculation.test.ts
+++ b/packages/lambda/src/test/unit/price-calculation.test.ts
@@ -44,6 +44,7 @@ test('Should not throw while calculating prices when time shifts occur', () => {
width: 1080,
defaultProps: {},
props: {},
+ defaultCodec: null,
},
outName: 'out.mp4',
privacy: 'public',
diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.ts
index 28dc28302a..747439cde9 100644
--- a/packages/renderer/src/render-frames.ts
+++ b/packages/renderer/src/render-frames.ts
@@ -14,6 +14,7 @@ import type {Page} from './browser/BrowserPage';
import type {ConsoleMessage} from './browser/ConsoleMessage';
import {isTargetClosedErr} from './browser/is-target-closed-err';
import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
+import type {Codec} from './codec';
import type {Compositor} from './compositor/compositor';
import {compressAsset} from './compress-assets';
import {cycleBrowserTabs} from './cycle-browser-tabs';
@@ -279,6 +280,7 @@ const innerRenderFrames = async ({
fps: number,
height: number,
width: number,
+ defaultCodec: Codec,
) => {
window.remotion_setBundleMode({
type: 'composition',
@@ -288,6 +290,7 @@ const innerRenderFrames = async ({
compositionFps: fps,
compositionHeight: height,
compositionWidth: width,
+ compositionDefaultCodec: defaultCodec,
});
},
args: [
@@ -297,6 +300,7 @@ const innerRenderFrames = async ({
composition.fps,
composition.height,
composition.width,
+ composition.defaultCodec,
],
frame: null,
page,
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index 18f3b6b110..39d2c79089 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -10,6 +10,7 @@ import type {BrowserLog} from './browser-log';
import type {HeadlessBrowser} from './browser/Browser';
import type {ConsoleMessage} from './browser/ConsoleMessage';
import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
+import type {Codec} from './codec';
import type {Compositor} from './compositor/compositor';
import {convertToPositiveFrameIndex} from './convert-to-positive-frame-index';
import {ensureOutputDirectory} from './ensure-output-directory';
@@ -286,6 +287,7 @@ const innerRenderStill = async ({
fps: number,
height: number,
width: number,
+ defaultCodec: Codec,
) => {
window.remotion_setBundleMode({
type: 'composition',
@@ -295,6 +297,7 @@ const innerRenderStill = async ({
compositionFps: fps,
compositionHeight: height,
compositionWidth: width,
+ compositionDefaultCodec: defaultCodec,
});
},
args: [
@@ -304,6 +307,7 @@ const innerRenderStill = async ({
composition.fps,
composition.height,
composition.width,
+ composition.defaultCodec,
],
frame: null,
page,
diff --git a/packages/renderer/src/test/render-still.test.ts b/packages/renderer/src/test/render-still.test.ts
index e10488b660..128d673440 100644
--- a/packages/renderer/src/test/render-still.test.ts
+++ b/packages/renderer/src/test/render-still.test.ts
@@ -12,6 +12,7 @@ test('Need to pass valid metadata', async () => {
id: 'hithere',
defaultProps: {},
props: {},
+ defaultCodec: null,
},
frame: 0,
output: '/file/output.png',
@@ -32,6 +33,7 @@ test('Returns buffer in promise result', async () => {
id: 'react-svg',
defaultProps: {},
props: {},
+ defaultCodec: null,
},
frame: 0,
serveUrl:
@@ -52,6 +54,7 @@ test('Need to pass valid metadata', async () => {
id: 'hithere',
defaultProps: {},
props: {},
+ defaultCodec: null,
},
frame: 200,
output: '/file/output.png',
@@ -75,6 +78,7 @@ test('Catches invalid image format', () => {
id: 'hithere',
defaultProps: {},
props: {},
+ defaultCodec: 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 f75afa6903..172af93b73 100644
--- a/packages/renderer/src/test/validate-config.test.ts
+++ b/packages/renderer/src/test/validate-config.test.ts
@@ -14,6 +14,7 @@ describe('Should validate invalid data passed to renderFrames', () => {
id: 'hithere',
defaultProps: {},
props: {},
+ defaultCodec: null,
},
}),
).rejects.toMatch(
@@ -32,6 +33,7 @@ describe('Should validate invalid data passed to renderFrames', () => {
id: 'hithere',
defaultProps: {},
props: {},
+ defaultCodec: null,
},
}),
).rejects.toMatch(
@@ -50,6 +52,7 @@ describe('Should validate invalid data passed to renderFrames', () => {
id: 'hithere',
defaultProps: {},
props: {},
+ defaultCodec: null,
},
}),
).rejects.toMatch(
@@ -68,6 +71,7 @@ describe('Should validate invalid data passed to renderFrames', () => {
id: 'hithere',
defaultProps: {},
props: {},
+ defaultCodec: null,
},
}),
).rejects.toMatch(