🎥 Make videos programmatically with React
import {DOCS_URL} from './docs-url';
import {getCloudwatchRendererUrl, getCloudwatchMethodUrl} from './get-aws-urls';
import type {AwsRegion} from './regions';
import type {RenderMetadata} from './render-metadata';
import {ServerlessRoutines} from './shared-constants';
const MAX_MISSING_CHUNKS = 5;
const makeChunkMissingMessage = ({
missingChunks,
renderMetadata,
region,
functionName,
}: {
missingChunks: number[];
renderMetadata: RenderMetadata;
region: AwsRegion;
functionName: string;
}) => {
if (missingChunks.length === 0) {
return 'All chunks have been successfully rendered, but the main function has timed out.';
}
return [
`The following chunks are missing (showing ${Math.min(
MAX_MISSING_CHUNKS,
missingChunks.length,
)} out of ${missingChunks.length}):`,
...missingChunks
.map((ch) => {
const isLastChunk = ch === renderMetadata.totalChunks - 1;
const start = ch * renderMetadata.framesPerLambda;
const end =
renderMetadata.type === 'still'
? 0
: isLastChunk
? renderMetadata.frameRange[1]
: (ch + 1) * renderMetadata.framesPerLambda - 1;
const msg = `Chunk ${ch} (Frames ${start} - ${end})`;
return [
msg,
`â–¸ Logs for chunk ${ch}: ${getCloudwatchRendererUrl({
functionName,
region,
rendererFunctionName: null,
renderId: renderMetadata.renderId,
chunk: ch,
})}`,
].join('\n');
})
.slice(0, 5),
].join('\n');
};
export const makeTimeoutMessage = ({
timeoutInMilliseconds,
missingChunks,
renderMetadata,
renderId,
functionName,
region,
}: {
timeoutInMilliseconds: number;
missingChunks: number[];
renderMetadata: RenderMetadata;
renderId: string;
region: AwsRegion;
functionName: string;
}) => {
const cloudWatchRendererUrl = getCloudwatchRendererUrl({
renderId,
functionName,
region,
rendererFunctionName: functionName,
chunk: null,
});
const cloudWatchLaunchUrl = getCloudwatchMethodUrl({
renderId,
functionName,
method: ServerlessRoutines.launch,
region,
rendererFunctionName: functionName,
});
const message = [
`The main function timed out after ${timeoutInMilliseconds}ms.`,
makeChunkMissingMessage({
missingChunks,
renderMetadata,
region,
functionName,
}),
'',
`Consider increasing the timeout of your function.`,
`â–¸ You can use the "--timeout" parameter when deploying a function via CLI, or the "timeoutInSeconds" parameter when using the deployFunction() API.`,
`${DOCS_URL}/docs/lambda/cli/functions/deploy`,
'',
'â–¸ Visit the logs for the main function:',
cloudWatchLaunchUrl,
'â–¸ Visit the logs for the renderer functions:',
cloudWatchRendererUrl,
'',
'â–¸ Get help on debugging this error:',
`${DOCS_URL}/docs/lambda/troubleshooting/debug`,
].join('\n');
return message;
};