Skip to content

🎥 Make videos programmatically with React

simplify chunk keys

Jonny Burgerf9cff41caf11
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index 8df5b2420e..ba28b5b8ef 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -2,7 +2,7 @@
import type {LogOptions} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
import {existsSync, mkdirSync, rmSync, writeFileSync} from 'fs';
-import path, {join} from 'path';
+import {join} from 'path';
import {VERSION} from 'remotion/version';
import {callLambdaWithStreaming} from '../shared/call-lambda';
import {
@@ -376,14 +376,10 @@ const innerLaunchHandler = async ({
} else if (message.type === 'video-chunk-rendered') {
const filename = join(
outdir,
- // TODO: Can be simplified
- path.basename(
- chunkKeyForIndex({
- index: payload.chunk,
- renderId: params.renderId,
- type: 'video',
- }),
- ),
+ chunkKeyForIndex({
+ index: payload.chunk,
+ type: 'video',
+ }),
);
writeFileSync(filename, message.payload);
console.log(
@@ -394,14 +390,10 @@ const innerLaunchHandler = async ({
} else if (message.type === 'audio-chunk-rendered') {
const filename = join(
outdir,
- // TODO: Can be simplified
- path.basename(
- chunkKeyForIndex({
- index: payload.chunk,
- renderId: params.renderId,
- type: 'audio',
- }),
- ),
+ chunkKeyForIndex({
+ index: payload.chunk,
+ type: 'audio',
+ }),
);
writeFileSync(filename, message.payload);
files.push(filename);
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index 1f88728acd..184d95f7f8 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -111,14 +111,12 @@ export const lambdaTimingsKey = ({
export const chunkKey = (renderId: string) =>
`${rendersPrefix(renderId)}/chunks/chunk`;
export const chunkKeyForIndex = ({
- renderId,
index,
type,
}: {
- renderId: string;
index: number;
type: 'video' | 'audio';
-}) => `${chunkKey(renderId)}:${String(index).padStart(8, '0')}:${type}`;
+}) => `chunk:${String(index).padStart(8, '0')}:${type}`;
export const getErrorKeyPrefix = (renderId: string) =>
`${rendersPrefix(renderId)}/errors/`;
diff --git a/packages/lambda/src/shared/parse-chunk-key.ts b/packages/lambda/src/shared/parse-chunk-key.ts
index da44d11711..fe248ffeb6 100644
--- a/packages/lambda/src/shared/parse-chunk-key.ts
+++ b/packages/lambda/src/shared/parse-chunk-key.ts
@@ -1,7 +1,5 @@
export const parseLambdaChunkKey = (key: string) => {
- const match = key.match(
- /^renders\/(.*)\/chunks\/chunk:([0-9]+):(video|audio)$/,
- );
+ const match = key.match(/chunk:([0-9]+):(video|audio)$/);
if (!match) {
throw new Error(
`Cannot parse filename ${key} into timing information. Malformed data.`,
@@ -9,8 +7,7 @@ export const parseLambdaChunkKey = (key: string) => {
}
return {
- renderId: match[1],
- chunk: Number(match[2]),
- type: match[3],
+ chunk: Number(match[1]),
+ type: match[2],
};
};
diff --git a/packages/lambda/src/test/unit/lambda-chunk-key.test.ts b/packages/lambda/src/test/unit/lambda-chunk-key.test.ts
index 8865e9ab90..91e6c7eb70 100644
--- a/packages/lambda/src/test/unit/lambda-chunk-key.test.ts
+++ b/packages/lambda/src/test/unit/lambda-chunk-key.test.ts
@@ -7,13 +7,11 @@ test('Should be able to parse Lambda key', () => {
parseLambdaChunkKey(
chunkKeyForIndex({
index: 1111,
- renderId: 'abcdef',
type: 'video',
}),
),
).toEqual({
chunk: 1111,
- renderId: 'abcdef',
type: 'video',
});
});