🎥 Make videos programmatically with React
import path from 'path';
import {
LambdaClientInternals,
ServerlessRoutines,
type RenderMediaOnLambdaInput,
} from '@remotion/lambda-client';
import {RenderInternals} from '@remotion/renderer';
import {waitUntilDone} from './wait-until-done';
const functionName = 'remotion-dev-render';
export const simulateLambdaRender = async (
input: Omit<RenderMediaOnLambdaInput, 'serveUrl' | 'functionName'>,
) => {
process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '2048';
const exampleBuild = path.join(process.cwd(), '..', 'example', 'build');
const {port, close} = await RenderInternals.serveStatic(exampleBuild, {
binariesDirectory: null,
offthreadVideoThreads: 1,
downloadMap: RenderInternals.makeDownloadMap(48000),
indent: false,
logLevel: input.logLevel ?? 'info',
offthreadVideoCacheSizeInBytes: null,
port: null,
remotionRoot: path.dirname(exampleBuild),
forceIPv4: false,
});
const payload = await LambdaClientInternals.makeLambdaRenderMediaPayload(
LambdaClientInternals.renderMediaOnLambdaOptionalToRequired({
...input,
serveUrl: `http://localhost:${port}`,
functionName,
}),
);
const res =
await LambdaClientInternals.callFunctionSyncImplementation<ServerlessRoutines.start>(
{
type: ServerlessRoutines.start,
payload,
functionName: 'remotion-dev-lambda',
region: 'eu-central-1',
timeoutInTest: 120000,
requestHandler: null,
},
);
const progress = await waitUntilDone(res.bucketName, res.renderId);
const file = await LambdaClientInternals.lambdaReadFileImplementation({
bucketName: progress.outBucket as string,
key: progress.outKey as string,
expectedBucketOwner: 'abc',
region: 'eu-central-1',
forcePathStyle: false,
requestHandler: null,
});
return {file, close, progress, renderId: res.renderId};
};