Skip to content

🎥 Make videos programmatically with React

cli + test

Jonny Burger0350be052bc6
diff --git a/packages/bundler/src/renderEntry.tsx b/packages/bundler/src/renderEntry.tsx
index f11c6536d4..e09f3469a7 100644
--- a/packages/bundler/src/renderEntry.tsx
+++ b/packages/bundler/src/renderEntry.tsx
@@ -306,9 +306,7 @@ if (typeof window !== 'undefined') {
return getUnevaluatedComps().map((c) => c.id);
};
- window.remotion_calculateComposition = async (
- compId: string
- ): Promise<VideoConfig> => {
+ window.remotion_calculateComposition = async (compId: string) => {
const compositions = getUnevaluatedComps();
const selectedComp = compositions.find((c) => c.id === compId);
if (!selectedComp) {
@@ -337,7 +335,20 @@ if (typeof window !== 'undefined') {
);
continueRender(handle);
- return prom;
+ const {props, defaultProps, ...data} = prom;
+ return {
+ ...data,
+ serializedResolvedPropsWithCustomSchema: Internals.serializeJSONWithDate({
+ data: props,
+ indent: undefined,
+ staticBase: null,
+ }).serializedString,
+ serializedDefaultPropsWithCustomSchema: Internals.serializeJSONWithDate({
+ data: defaultProps,
+ indent: undefined,
+ staticBase: null,
+ }).serializedString,
+ };
};
window.siteVersion = '8';
diff --git a/packages/compositor-darwin-arm64/compositor b/packages/compositor-darwin-arm64/compositor
index 0be7982e84..1ed7989976 100755
Binary files a/packages/compositor-darwin-arm64/compositor and b/packages/compositor-darwin-arm64/compositor differ
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 9e240cd412..215fe36a13 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -14,7 +14,12 @@ declare global {
remotion_cancelledError: string | undefined;
remotion_getCompositionNames: () => string[];
getStaticCompositions: () => Promise<VideoConfig[]>;
- remotion_calculateComposition: (compId: string) => Promise<VideoConfig>;
+ remotion_calculateComposition: (compId: string) => Promise<
+ Omit<VideoConfig, 'defaultProps' | 'props'> & {
+ serializedDefaultPropsWithCustomSchema: string;
+ serializedResolvedPropsWithCustomSchema: string;
+ }
+ >;
remotion_setBundleMode: (bundleMode: BundleState) => void;
remotion_staticBase: string;
remotion_staticFiles: StaticFile[];
diff --git a/packages/core/src/input-props-serialization.ts b/packages/core/src/input-props-serialization.ts
index d1fe6ffa82..b4ba9e39c7 100644
--- a/packages/core/src/input-props-serialization.ts
+++ b/packages/core/src/input-props-serialization.ts
@@ -28,7 +28,7 @@ export const serializeJSONWithDate = ({
const serializedString = JSON.stringify(
data,
function (key, value) {
- const item = this[key];
+ const item = (this as Record<string, unknown>)[key];
if (item instanceof Date) {
customDateUsed = true;
return `${DATE_TOKEN}${item.toISOString()}`;
@@ -61,7 +61,9 @@ export const serializeJSONWithDate = ({
return {serializedString, customDateUsed, customFileUsed, mapUsed, setUsed};
};
-export const deserializeJSONWithCustomFields = (data: string) => {
+export const deserializeJSONWithCustomFields = (
+ data: string
+): Record<string, unknown> => {
return JSON.parse(data, (_, value) => {
if (typeof value === 'string' && value.startsWith(DATE_TOKEN)) {
return new Date(value.replace(DATE_TOKEN, ''));
diff --git a/packages/example/src/HugePayload.tsx b/packages/example/src/HugePayload.tsx
index 4ae0fc9b69..436b0d5e09 100644
--- a/packages/example/src/HugePayload.tsx
+++ b/packages/example/src/HugePayload.tsx
@@ -2,11 +2,27 @@ import {z} from 'zod';
export const hugePayloadSchema = z.object({
str: z.string(),
+ date: z.date(),
+ file: z.string(),
});
export const HugePayload: React.FC<z.infer<typeof hugePayloadSchema>> = ({
str,
+ date,
+ file,
}) => {
+ if (str.length !== 60000000) {
+ throw new Error('str is not 60,000,000 characters long');
+ }
+
+ if (date instanceof Date === false) {
+ throw new Error('date is not a Date');
+ }
+
+ if (!file.startsWith(window.remotion_staticBase)) {
+ throw new Error('file does not start with staticBase');
+ }
+
return (
<div
style={{
@@ -14,7 +30,7 @@ export const HugePayload: React.FC<z.infer<typeof hugePayloadSchema>> = ({
fontSize: 80,
}}
>
- Wow this payload is huge! {str.length}
+ Wow this payload is huge! {str.length} {file} {date.getTime()}
</div>
);
};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index eddb9e40ef..f758b7d4ab 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -193,16 +193,22 @@ export const Index: React.FC = () => {
width={1080}
height={1080}
fps={30}
- durationInFrames={100}
+ durationInFrames={2}
calculateMetadata={() => {
return {
props: {
str: 'potato'.repeat(10000000),
+ date: new Date('2020-01-01'),
+ file: staticFile('giphy.gif'),
},
};
}}
schema={hugePayloadSchema}
- defaultProps={{str: 'st'}}
+ defaultProps={{
+ str: 'st',
+ file: staticFile('giphy.gif'),
+ date: new Date('2020-01-01'),
+ }}
/>
<Composition
id="sync-dynamic-length"
diff --git a/packages/it-tests/src/rendering/rendering.test.ts b/packages/it-tests/src/rendering/rendering.test.ts
index 199dd5c1aa..ee1e3feda2 100644
--- a/packages/it-tests/src/rendering/rendering.test.ts
+++ b/packages/it-tests/src/rendering/rendering.test.ts
@@ -389,3 +389,23 @@ test("Should be able to render if remotion.config.ts is not provided", async ()
expect(task.exitCode).toBe(0);
fs.unlinkSync(outputPath);
});
+
+test("Should be able to render a huge payload that gets serialized", async () => {
+ const task = await execa(
+ "pnpm",
+ [
+ "exec",
+ "remotion",
+ "still",
+ "huge-payload",
+ outputPath.replace(".mp4", ".png"),
+ ],
+ {
+ cwd: path.join(process.cwd(), "..", "example"),
+ reject: false,
+ }
+ );
+
+ expect(task.exitCode).toBe(0);
+ fs.unlinkSync(outputPath.replace(".mp4", ".png"));
+});
diff --git a/packages/renderer/src/select-composition.ts b/packages/renderer/src/select-composition.ts
index 3c4fa3c84b..3569d50ab8 100644
--- a/packages/renderer/src/select-composition.ts
+++ b/packages/renderer/src/select-composition.ts
@@ -133,10 +133,33 @@ const innerSelectComposition = async ({
`calculateMetadata() took ${Date.now() - time}ms`
);
- return {metadata: result as VideoConfig, propsSize: size};
+ const res = result as Awaited<
+ ReturnType<typeof window.remotion_calculateComposition>
+ >;
+
+ const {width, durationInFrames, fps, height} = res;
+ return {
+ metadata: {
+ id,
+ width,
+ height,
+ fps,
+ durationInFrames,
+ props: Internals.deserializeJSONWithCustomFields(
+ res.serializedResolvedPropsWithCustomSchema
+ ),
+ defaultProps: Internals.deserializeJSONWithCustomFields(
+ res.serializedDefaultPropsWithCustomSchema
+ ),
+ },
+ propsSize: size,
+ };
};
-type InternalReturnType = {metadata: VideoConfig; propsSize: number};
+type InternalReturnType = {
+ metadata: VideoConfig;
+ propsSize: number;
+};
export const internalSelectComposition = async (
options: InternalSelectCompositionsConfig
@@ -237,7 +260,7 @@ export const internalSelectComposition = async (
*/
export const selectComposition = async (
options: SelectCompositionOptions
-): Promise<VideoConfig> => {
+): Promise<Omit<VideoConfig, 'defaultProps'>> => {
const {
id,
serveUrl,
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index bcb41502aa..dabc3607ee 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1105,6 +1105,12 @@ importers:
specifier: workspace:*
version: link:../core
+ packages/lambda-php-example/vendor/remotion/lambda:
+ devDependencies:
+ remotion:
+ specifier: workspace:*
+ version: link:../../../../core
+
packages/lottie:
dependencies:
lottie-web: