Skip to content

🎥 Make videos programmatically with React

correct offset

Patric Salvisberg03c53a22cb72
diff --git a/packages/lambda/src/functions/helpers/create-post-render-data.ts b/packages/lambda/src/functions/helpers/create-post-render-data.ts
index d03c2dcfc3..5325f272fa 100644
--- a/packages/lambda/src/functions/helpers/create-post-render-data.ts
+++ b/packages/lambda/src/functions/helpers/create-post-render-data.ts
@@ -117,6 +117,7 @@ export const createPostRenderData = ({
mostExpensiveFrameRanges: getMostExpensiveChunks(
parsedTimings,
renderMetadata.framesPerLambda,
+ renderMetadata.frameRange[0],
renderMetadata.frameRange[1]
),
};
diff --git a/packages/lambda/src/shared/get-most-expensive-chunks.ts b/packages/lambda/src/shared/get-most-expensive-chunks.ts
index 9916043031..0f718db4ee 100644
--- a/packages/lambda/src/shared/get-most-expensive-chunks.ts
+++ b/packages/lambda/src/shared/get-most-expensive-chunks.ts
@@ -11,6 +11,7 @@ export type ExpensiveChunk = {
export const getMostExpensiveChunks = (
parsedTimings: ParsedTiming[],
framesPerLambda: number,
+ firstFrame: number,
lastFrame: number
): ExpensiveChunk[] => {
const mostExpensiveChunks = parsedTimings
@@ -30,8 +31,10 @@ export const getMostExpensiveChunks = (
timeInMilliseconds: c.rendered - c.start,
chunk: c.chunk,
frameRange: [
- framesPerLambda * c.chunk,
- isLastChunk ? lastFrame : framesPerLambda * (c.chunk + 1) - 1,
+ framesPerLambda * c.chunk + firstFrame,
+ isLastChunk
+ ? lastFrame
+ : framesPerLambda * (c.chunk + 1) - 1 + firstFrame,
],
};
});
diff --git a/packages/lambda/src/test/unit/most-expensive-chunks.test.ts b/packages/lambda/src/test/unit/most-expensive-chunks.test.ts
index 1ca3f2d3a5..cc99417a0a 100644
--- a/packages/lambda/src/test/unit/most-expensive-chunks.test.ts
+++ b/packages/lambda/src/test/unit/most-expensive-chunks.test.ts
@@ -49,6 +49,7 @@ test('Should calculate most expensive chunks', () => {
},
],
10,
+ 0,
99
);
@@ -60,3 +61,129 @@ test('Should calculate most expensive chunks', () => {
{timeInMilliseconds: 1000, chunk: 3, frameRange: [30, 39]},
]);
});
+
+test('Render starting from frame 10 should have correct offset', () => {
+ const framesPerLambda = 10;
+ const firstFrame = 10;
+ const lastFrame = 99;
+ const most = getMostExpensiveChunks(
+ [
+ {
+ chunk: 0,
+ rendered: 1000,
+ start: 0,
+ renderId: 'abc',
+ },
+ {
+ chunk: 1,
+ rendered: 4000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 2,
+ rendered: 5000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 3,
+ rendered: 3000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 4,
+ rendered: 100000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 5,
+ rendered: 2001,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 6,
+ rendered: 2500,
+ start: 2000,
+ renderId: 'abc',
+ },
+ ],
+ framesPerLambda,
+ firstFrame,
+ lastFrame
+ );
+
+ expect(most).toEqual([
+ {timeInMilliseconds: 98000, chunk: 4, frameRange: [50, 59]},
+ {timeInMilliseconds: 3000, chunk: 2, frameRange: [30, 39]},
+ {timeInMilliseconds: 2000, chunk: 1, frameRange: [20, 29]},
+ {timeInMilliseconds: 1000, chunk: 0, frameRange: [10, 19]},
+ {timeInMilliseconds: 1000, chunk: 3, frameRange: [40, 49]},
+ ]);
+});
+
+test('Render starting from frame 10 and last chunk in most expensive should be corret', () => {
+ const framesPerLambda = 10;
+ const firstFrame = 10;
+ const lastFrame = 79;
+ const most = getMostExpensiveChunks(
+ [
+ {
+ chunk: 0,
+ rendered: 1000,
+ start: 0,
+ renderId: 'abc',
+ },
+ {
+ chunk: 1,
+ rendered: 4000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 2,
+ rendered: 5000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 3,
+ rendered: 3000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 4,
+ rendered: 100000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 5,
+ rendered: 2001,
+ start: 2000,
+ renderId: 'abc',
+ },
+ {
+ chunk: 6,
+ rendered: 125000,
+ start: 2000,
+ renderId: 'abc',
+ },
+ ],
+ framesPerLambda,
+ firstFrame,
+ lastFrame
+ );
+
+ expect(most).toEqual([
+ {timeInMilliseconds: 123000, chunk: 6, frameRange: [70, 79]},
+ {timeInMilliseconds: 98000, chunk: 4, frameRange: [50, 59]},
+ {timeInMilliseconds: 3000, chunk: 2, frameRange: [30, 39]},
+ {timeInMilliseconds: 2000, chunk: 1, frameRange: [20, 29]},
+ {timeInMilliseconds: 1000, chunk: 0, frameRange: [10, 19]},
+ ]);
+});