Skip to content

🎥 Make videos programmatically with React

try out different things

Jonny Burger8164c86246c8
diff --git a/packages/lambda/src/test/integration/webhooks.test.ts b/packages/lambda/src/test/integration/webhooks.test.ts
index b540b52932..b9d8db177d 100644
--- a/packages/lambda/src/test/integration/webhooks.test.ts
+++ b/packages/lambda/src/test/integration/webhooks.test.ts
@@ -1,6 +1,6 @@
import {RenderInternals, ensureBrowser} from '@remotion/renderer';
import {ServerlessRoutines} from '@remotion/serverless/client';
-import {beforeAll, describe, expect, test} from 'bun:test';
+import {beforeAll, expect, test} from 'bun:test';
import path from 'path';
import {VERSION} from 'remotion/version';
import {
@@ -19,229 +19,227 @@ beforeAll(async () => {
const TEST_URL = 'http://localhost:8000';
const exampleBuild = path.join(process.cwd(), '..', 'example', 'build');
-describe('Webhooks', () => {
- test('Should call webhook upon completion', async () => {
- process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '2048';
- process.env.AWS_LAMBDA_FUNCTION_NAME = 'remotion-dev-lambda';
-
- resetWebhookCalls();
-
- const {port, close} = await RenderInternals.serveStatic(exampleBuild, {
- binariesDirectory: null,
- concurrency: 1,
- downloadMap: RenderInternals.makeDownloadMap(),
- indent: false,
- logLevel: 'error',
- offthreadVideoCacheSizeInBytes: null,
- port: null,
- remotionRoot: path.dirname(exampleBuild),
- forceIPv4: false,
- });
+test('Should call webhook upon completion', async () => {
+ process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '2048';
+ process.env.AWS_LAMBDA_FUNCTION_NAME = 'remotion-dev-lambda';
+
+ resetWebhookCalls();
+
+ const {port, close} = await RenderInternals.serveStatic(exampleBuild, {
+ binariesDirectory: null,
+ concurrency: 1,
+ downloadMap: RenderInternals.makeDownloadMap(),
+ indent: false,
+ logLevel: 'error',
+ offthreadVideoCacheSizeInBytes: null,
+ port: null,
+ remotionRoot: path.dirname(exampleBuild),
+ forceIPv4: false,
+ });
- const res = await mockImplementation.callFunctionSync({
+ const res = await mockImplementation.callFunctionSync({
+ type: ServerlessRoutines.start,
+ payload: {
type: ServerlessRoutines.start,
- payload: {
- type: ServerlessRoutines.start,
- serveUrl: `http://localhost:${port}`,
- chromiumOptions: {},
- codec: 'h264',
- composition: 'react-svg',
- crf: 9,
- envVariables: {},
- frameRange: [0, 2],
- framesPerLambda: 8,
- imageFormat: 'png',
- inputProps: {
- type: 'payload',
- payload: '{}',
- },
- logLevel: 'warn',
- maxRetries: 3,
- outName: 'out.mp4',
- pixelFormat: 'yuv420p',
- privacy: 'public',
- proResProfile: undefined,
- x264Preset: null,
- jpegQuality: undefined,
- scale: 1,
- timeoutInMilliseconds: 40000,
- numberOfGifLoops: null,
- everyNthFrame: 1,
- concurrencyPerLambda: 1,
- downloadBehavior: {
- type: 'play-in-browser',
- },
- muted: false,
- version: VERSION,
- overwrite: true,
- webhook: {
- url: TEST_URL,
- secret: 'TEST_SECRET',
- customData: {
- customID: 123,
- },
+ serveUrl: `http://localhost:${port}`,
+ chromiumOptions: {},
+ codec: 'h264',
+ composition: 'react-svg',
+ crf: 9,
+ envVariables: {},
+ frameRange: [0, 2],
+ framesPerLambda: 8,
+ imageFormat: 'png',
+ inputProps: {
+ type: 'payload',
+ payload: '{}',
+ },
+ logLevel: 'warn',
+ maxRetries: 3,
+ outName: 'out.mp4',
+ pixelFormat: 'yuv420p',
+ privacy: 'public',
+ proResProfile: undefined,
+ x264Preset: null,
+ jpegQuality: undefined,
+ scale: 1,
+ timeoutInMilliseconds: 40000,
+ numberOfGifLoops: null,
+ everyNthFrame: 1,
+ concurrencyPerLambda: 1,
+ downloadBehavior: {
+ type: 'play-in-browser',
+ },
+ muted: false,
+ version: VERSION,
+ overwrite: true,
+ webhook: {
+ url: TEST_URL,
+ secret: 'TEST_SECRET',
+ customData: {
+ customID: 123,
},
- audioBitrate: null,
- videoBitrate: null,
- encodingBufferSize: null,
- encodingMaxRate: null,
- forceHeight: null,
- forceWidth: null,
- rendererFunctionName: null,
- bucketName: null,
- audioCodec: null,
- offthreadVideoCacheSizeInBytes: null,
- deleteAfter: null,
- colorSpace: null,
- preferLossless: false,
- forcePathStyle: false,
- metadata: {Author: 'Lunar'},
},
- functionName: 'remotion-dev-lambda',
- region: 'us-east-1',
- timeoutInTest: 120000,
- });
- const parsed = res;
+ audioBitrate: null,
+ videoBitrate: null,
+ encodingBufferSize: null,
+ encodingMaxRate: null,
+ forceHeight: null,
+ forceWidth: null,
+ rendererFunctionName: null,
+ bucketName: null,
+ audioCodec: null,
+ offthreadVideoCacheSizeInBytes: null,
+ deleteAfter: null,
+ colorSpace: null,
+ preferLossless: false,
+ forcePathStyle: false,
+ metadata: {Author: 'Lunar'},
+ },
+ functionName: 'remotion-dev-lambda',
+ region: 'us-east-1',
+ timeoutInTest: 120000,
+ });
+ const parsed = res;
- await mockImplementation.callFunctionSync({
+ await mockImplementation.callFunctionSync({
+ type: ServerlessRoutines.status,
+ payload: {
type: ServerlessRoutines.status,
- payload: {
- type: ServerlessRoutines.status,
- bucketName: parsed.bucketName,
- renderId: parsed.renderId,
- version: VERSION,
- logLevel: 'info',
- forcePathStyle: false,
- s3OutputProvider: null,
- },
- functionName: 'remotion-dev-lambda',
- region: 'us-east-1',
- timeoutInTest: 120000,
- });
-
- const webhookCalls = getWebhookCalls();
-
- expect(webhookCalls.length).toBe(1);
- expect(webhookCalls[0].options.url).toBe(TEST_URL);
- const {payload} = webhookCalls[0].options;
- if (payload.type !== 'success') {
- throw new Error(`Expected success, got ${payload.type}`);
- }
-
- const {
- expectedBucketOwner,
- timeToFinish,
- renderId,
- costs,
- ...testablePayload
- } = payload;
- expect(testablePayload).toEqual({
- type: 'success',
- bucketName: 'remotionlambda-eucentral1-abcdef',
- customData: {
- customID: 123,
- },
- outputUrl: 'https://s3.mock-region-1.amazonaws.com/bucket/mock.mp4',
- lambdaErrors: [],
- outputFile: 'https://s3.mock-region-1.amazonaws.com/bucket/mock.mp4',
- });
- await close();
+ bucketName: parsed.bucketName,
+ renderId: parsed.renderId,
+ version: VERSION,
+ logLevel: 'info',
+ forcePathStyle: false,
+ s3OutputProvider: null,
+ },
+ functionName: 'remotion-dev-lambda',
+ region: 'us-east-1',
+ timeoutInTest: 120000,
});
- test('Should call webhook upon timeout', async () => {
- // Maybe this can use simulateLambdaRender instead
- const {port, close} = await RenderInternals.serveStatic(exampleBuild, {
- binariesDirectory: null,
- concurrency: 1,
- downloadMap: RenderInternals.makeDownloadMap(),
- indent: false,
- logLevel: 'error',
- offthreadVideoCacheSizeInBytes: null,
- port: null,
- remotionRoot: path.dirname(exampleBuild),
- forceIPv4: false,
- });
+ const webhookCalls = getWebhookCalls();
+
+ expect(webhookCalls.length).toBe(1);
+ expect(webhookCalls[0].options.url).toBe(TEST_URL);
+ const {payload} = webhookCalls[0].options;
+ if (payload.type !== 'success') {
+ throw new Error(`Expected success, got ${payload.type}`);
+ }
+
+ const {
+ expectedBucketOwner,
+ timeToFinish,
+ renderId,
+ costs,
+ ...testablePayload
+ } = payload;
+ expect(testablePayload).toEqual({
+ type: 'success',
+ bucketName: 'remotionlambda-eucentral1-abcdef',
+ customData: {
+ customID: 123,
+ },
+ outputUrl: 'https://s3.mock-region-1.amazonaws.com/bucket/mock.mp4',
+ lambdaErrors: [],
+ outputFile: 'https://s3.mock-region-1.amazonaws.com/bucket/mock.mp4',
+ });
+ await close();
+});
- resetWebhookCalls();
+test('Should call webhook upon timeout', async () => {
+ // Maybe this can use simulateLambdaRender instead
+ const {port, close} = await RenderInternals.serveStatic(exampleBuild, {
+ binariesDirectory: null,
+ concurrency: 1,
+ downloadMap: RenderInternals.makeDownloadMap(),
+ indent: false,
+ logLevel: 'error',
+ offthreadVideoCacheSizeInBytes: null,
+ port: null,
+ remotionRoot: path.dirname(exampleBuild),
+ forceIPv4: false,
+ });
- await mockImplementation.callFunctionSync({
- functionName: 'remotion-dev-lambda',
- region: 'us-east-1',
+ resetWebhookCalls();
+
+ await mockImplementation.callFunctionSync({
+ functionName: 'remotion-dev-lambda',
+ region: 'us-east-1',
+ type: ServerlessRoutines.launch,
+ payload: {
type: ServerlessRoutines.launch,
- payload: {
- type: ServerlessRoutines.launch,
- offthreadVideoCacheSizeInBytes: null,
- serveUrl: `http://localhost:${port}`,
- chromiumOptions: {},
- codec: 'h264',
- composition: 'react-svg',
- crf: 9,
- envVariables: {},
- frameRange: [0, 10],
- framesPerFunction: 8,
- imageFormat: 'png',
- inputProps: {
- type: 'payload',
- payload: '{}',
- },
- logLevel: 'warn',
- maxRetries: 3,
- outName: 'out.mp4',
- pixelFormat: 'yuv420p',
- privacy: 'public',
- proResProfile: null,
- x264Preset: null,
- jpegQuality: undefined,
- scale: 1,
- timeoutInMilliseconds: 3000,
- numberOfGifLoops: null,
- everyNthFrame: 1,
- concurrencyPerFunction: 1,
- downloadBehavior: {
- type: 'play-in-browser',
- },
- muted: false,
- overwrite: true,
- webhook: {
- url: TEST_URL,
- secret: 'TEST_SECRET',
- customData: {customID: 123},
- },
- audioBitrate: null,
- videoBitrate: null,
- encodingBufferSize: null,
- encodingMaxRate: null,
- bucketName: 'abc',
- renderId: 'abc',
- forceHeight: null,
- forceWidth: null,
- rendererFunctionName: null,
- audioCodec: null,
- deleteAfter: null,
- colorSpace: null,
- preferLossless: false,
- forcePathStyle: false,
- metadata: null,
+ offthreadVideoCacheSizeInBytes: null,
+ serveUrl: `http://localhost:${port}`,
+ chromiumOptions: {},
+ codec: 'h264',
+ composition: 'react-svg',
+ crf: 9,
+ envVariables: {},
+ frameRange: [0, 10],
+ framesPerFunction: 8,
+ imageFormat: 'png',
+ inputProps: {
+ type: 'payload',
+ payload: '{}',
},
- timeoutInTest: 1000,
- });
-
- await new Promise((resolve) => {
- setTimeout(resolve, 2000);
- });
+ logLevel: 'warn',
+ maxRetries: 3,
+ outName: 'out.mp4',
+ pixelFormat: 'yuv420p',
+ privacy: 'public',
+ proResProfile: null,
+ x264Preset: null,
+ jpegQuality: undefined,
+ scale: 1,
+ timeoutInMilliseconds: 3000,
+ numberOfGifLoops: null,
+ everyNthFrame: 1,
+ concurrencyPerFunction: 1,
+ downloadBehavior: {
+ type: 'play-in-browser',
+ },
+ muted: false,
+ overwrite: true,
+ webhook: {
+ url: TEST_URL,
+ secret: 'TEST_SECRET',
+ customData: {customID: 123},
+ },
+ audioBitrate: null,
+ videoBitrate: null,
+ encodingBufferSize: null,
+ encodingMaxRate: null,
+ bucketName: 'abc',
+ renderId: 'abc',
+ forceHeight: null,
+ forceWidth: null,
+ rendererFunctionName: null,
+ audioCodec: null,
+ deleteAfter: null,
+ colorSpace: null,
+ preferLossless: false,
+ forcePathStyle: false,
+ metadata: null,
+ },
+ timeoutInTest: 1000,
+ });
- const webhookCalls = getWebhookCalls();
+ await new Promise((resolve) => {
+ setTimeout(resolve, 2000);
+ });
- expect(webhookCalls.length).toBe(1);
- expect(webhookCalls[0].options.payload).toEqual({
- type: 'timeout',
- renderId: 'abc',
- expectedBucketOwner: '124',
- bucketName: 'abc',
- customData: {
- customID: 123,
- },
- });
- await close();
+ const webhookCalls = getWebhookCalls();
+
+ expect(webhookCalls.length).toBe(1);
+ expect(webhookCalls[0].options.payload).toEqual({
+ type: 'timeout',
+ renderId: 'abc',
+ expectedBucketOwner: '124',
+ bucketName: 'abc',
+ customData: {
+ customID: 123,
+ },
});
+ await close();
});
diff --git a/packages/serverless/src/merge-chunks.ts b/packages/serverless/src/merge-chunks.ts
index ca53a1bbcf..dd17b02e22 100644
--- a/packages/serverless/src/merge-chunks.ts
+++ b/packages/serverless/src/merge-chunks.ts
@@ -148,6 +148,7 @@ export const mergeChunksAndFinishRender = async <
options.overallProgress.setPostRenderData(postRenderData);
- await Promise.all([cleanupChunksProm, fs.promises.rm(outfile)]);
+ fs.unlinkSync(outfile);
+ await cleanupChunksProm;
return postRenderData;
};