@remotion/lambda 3.3.7 → 3.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/admin/generate-etag-list.d.ts +1 -0
  2. package/dist/admin/generate-etag-list.js +14 -0
  3. package/dist/api/deploy-site.js +0 -5
  4. package/dist/api/get-aws-client.d.ts +2 -0
  5. package/dist/api/get-aws-client.js +2 -0
  6. package/dist/api/get-or-create-bucket.js +0 -5
  7. package/dist/api/iam-validation/simulate-rule.js +0 -22
  8. package/dist/api/iam-validation/simulate.js +24 -5
  9. package/dist/api/iam-validation/user-permissions.js +0 -8
  10. package/dist/cli/commands/render/progress.d.ts +6 -3
  11. package/dist/cli/commands/render/progress.js +49 -39
  12. package/dist/cli/commands/render/render.js +16 -1
  13. package/dist/cli/commands/sites/create.js +0 -2
  14. package/dist/cli/helpers/progress-bar.d.ts +1 -2
  15. package/dist/cli/helpers/progress-bar.js +2 -2
  16. package/dist/functions/chunk-optimization/plan-frame-ranges.d.ts +4 -1
  17. package/dist/functions/helpers/concat-videos.d.ts +10 -6
  18. package/dist/functions/helpers/concat-videos.js +5 -21
  19. package/dist/functions/helpers/create-post-render-data.js +0 -12
  20. package/dist/functions/helpers/get-encoding-metadata.d.ts +4 -8
  21. package/dist/functions/helpers/get-encoding-metadata.js +4 -18
  22. package/dist/functions/helpers/get-final-encoding-status.d.ts +2 -4
  23. package/dist/functions/helpers/get-final-encoding-status.js +1 -4
  24. package/dist/functions/helpers/get-lambdas-invoked-stats.d.ts +1 -5
  25. package/dist/functions/helpers/get-lambdas-invoked-stats.js +1 -9
  26. package/dist/functions/helpers/get-overall-progress.d.ts +2 -1
  27. package/dist/functions/helpers/get-overall-progress.js +7 -5
  28. package/dist/functions/helpers/get-progress.js +40 -26
  29. package/dist/functions/helpers/get-rendered-frames-progress.d.ts +8 -0
  30. package/dist/functions/helpers/get-rendered-frames-progress.js +37 -0
  31. package/dist/functions/launch.js +48 -37
  32. package/dist/functions/renderer.js +15 -22
  33. package/dist/functions/still.js +2 -0
  34. package/dist/shared/aws-clients.d.ts +3 -0
  35. package/dist/shared/aws-clients.js +55 -13
  36. package/dist/shared/check-credentials.js +3 -0
  37. package/dist/shared/chunk-progress.d.ts +9 -0
  38. package/dist/shared/chunk-progress.js +2034 -0
  39. package/dist/shared/constants.d.ts +5 -5
  40. package/dist/shared/get-account-id.js +4 -6
  41. package/dist/shared/invoke-webhook.d.ts +0 -2
  42. package/dist/shared/parse-chunk-key.d.ts +4 -0
  43. package/dist/shared/parse-chunk-key.js +14 -0
  44. package/package.json +8 -6
  45. package/remotionlambda.zip +0 -0
@@ -1,26 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEncodingMetadata = void 0;
4
- const defaults_1 = require("../../defaults");
5
- const stream_to_string_1 = require("../../shared/stream-to-string");
6
- const io_1 = require("./io");
7
- const getEncodingMetadata = async ({ exists, bucketName, renderId, region, expectedBucketOwner, }) => {
4
+ const chunk_progress_1 = require("../../shared/chunk-progress");
5
+ const getEncodingMetadata = ({ exists, }) => {
8
6
  if (!exists) {
9
7
  return null;
10
8
  }
11
- try {
12
- const Body = await (0, io_1.lambdaReadFile)({
13
- bucketName,
14
- key: (0, defaults_1.encodingProgressKey)(renderId),
15
- region,
16
- expectedBucketOwner,
17
- });
18
- const encodingProgress = JSON.parse(await (0, stream_to_string_1.streamToString)(Body));
19
- return encodingProgress;
20
- }
21
- catch (err) {
22
- // The file may not yet have been fully written or already have been cleaned up again
23
- return null;
24
- }
9
+ const framesEncoded = (0, chunk_progress_1.getProgressOfChunk)(exists.ETag);
10
+ return { framesEncoded };
25
11
  };
26
12
  exports.getEncodingMetadata = getEncodingMetadata;
@@ -1,8 +1,6 @@
1
1
  import type { EncodingProgress, RenderMetadata } from '../../shared/constants';
2
- import type { LambdaInvokeStats } from './get-lambdas-invoked-stats';
3
- export declare const getFinalEncodingStatus: ({ encodingStatus: encodingProgress, renderMetadata, outputFileExists, lambdaInvokeStatus, }: {
4
- encodingStatus: EncodingProgress | null;
2
+ export declare const getFinalEncodingStatus: ({ encodingProgress, renderMetadata, outputFileExists, }: {
3
+ encodingProgress: EncodingProgress | null;
5
4
  renderMetadata: RenderMetadata | null;
6
5
  outputFileExists: boolean;
7
- lambdaInvokeStatus: LambdaInvokeStats;
8
6
  }) => EncodingProgress | null;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFinalEncodingStatus = void 0;
4
- const getFinalEncodingStatus = ({ encodingStatus: encodingProgress, renderMetadata, outputFileExists, lambdaInvokeStatus, }) => {
4
+ const getFinalEncodingStatus = ({ encodingProgress, renderMetadata, outputFileExists, }) => {
5
5
  if (!renderMetadata) {
6
6
  return null;
7
7
  }
@@ -11,9 +11,6 @@ const getFinalEncodingStatus = ({ encodingStatus: encodingProgress, renderMetada
11
11
  if (outputFileExists) {
12
12
  return {
13
13
  framesEncoded: renderMetadata.videoConfig.durationInFrames,
14
- totalFrames: renderMetadata.videoConfig.durationInFrames,
15
- doneIn: null,
16
- timeToInvoke: lambdaInvokeStatus.timeToInvokeLambdas,
17
14
  };
18
15
  }
19
16
  return null;
@@ -1,12 +1,8 @@
1
1
  import type { _Object } from '@aws-sdk/client-s3';
2
2
  export declare type LambdaInvokeStats = {
3
- timeToInvokeLambdas: number | null;
4
3
  lambdasInvoked: number;
5
4
  };
6
- export declare const getLambdasInvokedStats: ({ contents, renderId, estimatedRenderLambdaInvokations, startDate, checkIfAllLambdasWereInvoked, }: {
5
+ export declare const getLambdasInvokedStats: ({ contents, renderId, }: {
7
6
  contents: _Object[];
8
7
  renderId: string;
9
- estimatedRenderLambdaInvokations: number | null;
10
- startDate: number | null;
11
- checkIfAllLambdasWereInvoked: boolean;
12
8
  }) => LambdaInvokeStats;
@@ -3,19 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLambdasInvokedStats = void 0;
4
4
  const constants_1 = require("../../shared/constants");
5
5
  const parse_lambda_initialized_key_1 = require("../../shared/parse-lambda-initialized-key");
6
- const min_max_1 = require("./min-max");
7
- const getLambdasInvokedStats = ({ contents, renderId, estimatedRenderLambdaInvokations, startDate, checkIfAllLambdasWereInvoked, }) => {
8
- var _a;
6
+ const getLambdasInvokedStats = ({ contents, renderId, }) => {
9
7
  const lambdasInvoked = contents
10
8
  .filter((c) => { var _a; return (_a = c.Key) === null || _a === void 0 ? void 0 : _a.startsWith((0, constants_1.lambdaChunkInitializedPrefix)(renderId)); })
11
9
  .filter((c) => (0, parse_lambda_initialized_key_1.parseLambdaInitializedKey)(c.Key).attempt === 1);
12
- const allLambdasInvoked = !checkIfAllLambdasWereInvoked ||
13
- lambdasInvoked.length === estimatedRenderLambdaInvokations;
14
- const timeToInvokeLambdas = !allLambdasInvoked || startDate === null
15
- ? null
16
- : ((_a = (0, min_max_1.max)(lambdasInvoked.map((l) => { var _a; return (_a = l.LastModified) === null || _a === void 0 ? void 0 : _a.getTime(); }))) !== null && _a !== void 0 ? _a : 0) - startDate;
17
10
  return {
18
- timeToInvokeLambdas,
19
11
  lambdasInvoked: lambdasInvoked.length,
20
12
  };
21
13
  };
@@ -1,6 +1,7 @@
1
- export declare const getOverallProgress: ({ cleanup, encoding, rendering, invoking, }: {
1
+ export declare const getOverallProgress: ({ cleanup, encoding, rendering, invoking, frames, }: {
2
2
  cleanup: number;
3
3
  encoding: number;
4
4
  rendering: number;
5
5
  invoking: number;
6
+ frames: number;
6
7
  }) => number;
@@ -3,14 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getOverallProgress = void 0;
4
4
  const weights = {
5
5
  cleanup: 0.1,
6
- encoding: 0.3,
7
- rendering: 0.3,
8
- invoking: 0.3,
6
+ encoding: 0.225,
7
+ rendering: 0.225,
8
+ frames: 0.225,
9
+ invoking: 0.225,
9
10
  };
10
- const getOverallProgress = ({ cleanup, encoding, rendering, invoking, }) => {
11
+ const getOverallProgress = ({ cleanup, encoding, rendering, invoking, frames, }) => {
11
12
  return (cleanup * weights.cleanup +
12
13
  encoding * weights.encoding +
13
14
  rendering * weights.rendering +
14
- invoking * weights.invoking);
15
+ invoking * weights.invoking +
16
+ frames * weights.frames);
15
17
  };
16
18
  exports.getOverallProgress = getOverallProgress;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getProgress = void 0;
4
+ const renderer_1 = require("@remotion/renderer");
4
5
  const remotion_1 = require("remotion");
6
+ const chunk_progress_1 = require("../../shared/chunk-progress");
5
7
  const constants_1 = require("../../shared/constants");
6
8
  const docs_url_1 = require("../../shared/docs-url");
7
9
  const calculate_chunk_times_1 = require("./calculate-chunk-times");
@@ -19,12 +21,13 @@ const get_lambdas_invoked_stats_1 = require("./get-lambdas-invoked-stats");
19
21
  const get_overall_progress_1 = require("./get-overall-progress");
20
22
  const get_post_render_data_1 = require("./get-post-render-data");
21
23
  const get_render_metadata_1 = require("./get-render-metadata");
24
+ const get_rendered_frames_progress_1 = require("./get-rendered-frames-progress");
22
25
  const get_retry_stats_1 = require("./get-retry-stats");
23
26
  const get_time_to_finish_1 = require("./get-time-to-finish");
24
27
  const inspect_errors_1 = require("./inspect-errors");
25
28
  const io_1 = require("./io");
26
29
  const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region, memorySizeInMb, timeoutInMilliseconds, customCredentials, }) => {
27
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
30
+ var _a, _b, _c, _d, _e, _f, _g, _h;
28
31
  const postRenderData = await (0, get_post_render_data_1.getPostRenderData)({
29
32
  bucketName,
30
33
  region,
@@ -33,7 +36,9 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
33
36
  });
34
37
  if (postRenderData) {
35
38
  const outData = (0, expected_out_name_1.getExpectedOutName)(postRenderData.renderMetadata, bucketName, customCredentials);
39
+ const totalFrameCount = renderer_1.RenderInternals.getFramesToRender(postRenderData.renderMetadata.frameRange, postRenderData.renderMetadata.everyNthFrame).length;
36
40
  return {
41
+ framesRendered: totalFrameCount,
37
42
  bucket: bucketName,
38
43
  renderSize: postRenderData.renderSize,
39
44
  chunks: postRenderData.renderMetadata.totalChunks,
@@ -51,10 +56,7 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
51
56
  currentTime: Date.now(),
52
57
  done: true,
53
58
  encodingStatus: {
54
- framesEncoded: postRenderData.renderMetadata.videoConfig.durationInFrames,
55
- totalFrames: postRenderData.renderMetadata.videoConfig.durationInFrames,
56
- doneIn: postRenderData.timeToEncode,
57
- timeToInvoke: postRenderData.timeToInvokeLambdas,
59
+ framesEncoded: totalFrameCount,
58
60
  },
59
61
  errors: postRenderData.errors,
60
62
  fatalErrorEncountered: false,
@@ -64,12 +66,13 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
64
66
  renderMetadata: postRenderData.renderMetadata,
65
67
  timeToFinish: postRenderData.timeToFinish,
66
68
  timeToFinishChunks: postRenderData.timeToRenderChunks,
67
- timeToInvokeLambdas: postRenderData.timeToInvokeLambdas,
68
69
  overallProgress: 1,
69
70
  retriesInfo: postRenderData.retriesInfo,
70
71
  outKey: outData.key,
71
72
  outBucket: outData.renderBucketName,
72
73
  mostExpensiveFrameRanges: (_a = postRenderData.mostExpensiveFrameRanges) !== null && _a !== void 0 ? _a : null,
74
+ timeToEncode: postRenderData.timeToEncode,
75
+ outputSizeInBytes: postRenderData.outputSize,
73
76
  };
74
77
  }
75
78
  const contents = await (0, io_1.lambdaLs)({
@@ -78,16 +81,11 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
78
81
  region: (0, get_current_region_1.getCurrentRegionInFunction)(),
79
82
  expectedBucketOwner,
80
83
  });
81
- (0, check_if_render_exists_1.checkIfRenderExists)(contents, renderId, bucketName, (0, get_current_region_1.getCurrentRegionInFunction)());
82
84
  const renderMetadataExists = Boolean(contents.find((c) => c.Key === (0, constants_1.renderMetadataKey)(renderId)));
83
- const [encodingStatus, renderMetadata, errorExplanations] = await Promise.all([
84
- (0, get_encoding_metadata_1.getEncodingMetadata)({
85
- exists: Boolean(contents.find((c) => c.Key === (0, constants_1.encodingProgressKey)(renderId))),
86
- bucketName,
87
- renderId,
88
- region: (0, get_current_region_1.getCurrentRegionInFunction)(),
89
- expectedBucketOwner,
90
- }),
85
+ const encodingStatus = (0, get_encoding_metadata_1.getEncodingMetadata)({
86
+ exists: contents.find((c) => c.Key === (0, constants_1.encodingProgressKey)(renderId)),
87
+ });
88
+ const [renderMetadata, errorExplanations] = await Promise.all([
91
89
  renderMetadataExists
92
90
  ? (0, get_render_metadata_1.getRenderMetadata)({
93
91
  bucketName,
@@ -107,6 +105,7 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
107
105
  if ((renderMetadata === null || renderMetadata === void 0 ? void 0 : renderMetadata.type) === 'still') {
108
106
  throw new Error("You don't need to call getRenderProgress() on a still render. Once you have obtained the `renderId`, the render is already done! 😉");
109
107
  }
108
+ (0, check_if_render_exists_1.checkIfRenderExists)(contents, renderId, bucketName, (0, get_current_region_1.getCurrentRegionInFunction)());
110
109
  const outputFile = renderMetadata
111
110
  ? await (0, find_output_file_in_bucket_1.findOutputFileInBucket)({
112
111
  bucketName,
@@ -137,6 +136,20 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
137
136
  renderMetadata,
138
137
  });
139
138
  const chunks = contents.filter((c) => { var _a; return (_a = c.Key) === null || _a === void 0 ? void 0 : _a.startsWith((0, constants_1.chunkKey)(renderId)); });
139
+ const framesRendered = renderMetadata
140
+ ? (0, get_rendered_frames_progress_1.getRenderedFramesProgress)({
141
+ contents,
142
+ everyNthFrame: renderMetadata.everyNthFrame,
143
+ frameRange: renderMetadata.frameRange,
144
+ framesPerLambda: renderMetadata.framesPerLambda,
145
+ renderId,
146
+ })
147
+ : 0;
148
+ console.log('etags', contents
149
+ .filter((c) => { var _a; return (_a = c.Key) === null || _a === void 0 ? void 0 : _a.startsWith((0, constants_1.lambdaChunkInitializedPrefix)(renderId)); })
150
+ .map((c) => {
151
+ return (0, chunk_progress_1.getProgressOfChunk)(c.ETag);
152
+ }));
140
153
  const allChunks = chunks.length === ((_f = renderMetadata === null || renderMetadata === void 0 ? void 0 : renderMetadata.totalChunks) !== null && _f !== void 0 ? _f : Infinity);
141
154
  const renderSize = contents
142
155
  .map((c) => { var _a; return (_a = c.Size) !== null && _a !== void 0 ? _a : 0; })
@@ -144,22 +157,18 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
144
157
  const lambdasInvokedStats = (0, get_lambdas_invoked_stats_1.getLambdasInvokedStats)({
145
158
  contents,
146
159
  renderId,
147
- estimatedRenderLambdaInvokations: (_g = renderMetadata === null || renderMetadata === void 0 ? void 0 : renderMetadata.estimatedRenderLambdaInvokations) !== null && _g !== void 0 ? _g : null,
148
- startDate: (_h = renderMetadata === null || renderMetadata === void 0 ? void 0 : renderMetadata.startedDate) !== null && _h !== void 0 ? _h : null,
149
- checkIfAllLambdasWereInvoked: true,
150
160
  });
151
161
  const retriesInfo = (0, get_retry_stats_1.getRetryStats)({
152
162
  contents,
153
163
  renderId,
154
164
  });
155
165
  const finalEncodingStatus = (0, get_final_encoding_status_1.getFinalEncodingStatus)({
156
- encodingStatus,
166
+ encodingProgress: encodingStatus,
157
167
  outputFileExists: Boolean(outputFile),
158
168
  renderMetadata,
159
- lambdaInvokeStatus: lambdasInvokedStats,
160
169
  });
161
170
  const chunkCount = outputFile
162
- ? (_j = renderMetadata === null || renderMetadata === void 0 ? void 0 : renderMetadata.totalChunks) !== null && _j !== void 0 ? _j : 0
171
+ ? (_g = renderMetadata === null || renderMetadata === void 0 ? void 0 : renderMetadata.totalChunks) !== null && _g !== void 0 ? _g : 0
163
172
  : chunks.length;
164
173
  // We add a 20 second buffer for it, since AWS timeshifts can be quite a lot. Once it's 20sec over the limit, we consider it timed out
165
174
  const isBeyondTimeout = renderMetadata &&
@@ -182,7 +191,11 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
182
191
  : null,
183
192
  ...errorExplanations,
184
193
  ].filter(remotion_1.Internals.truthy);
194
+ const frameCount = renderMetadata
195
+ ? renderer_1.RenderInternals.getFramesToRender(renderMetadata.frameRange, renderMetadata.everyNthFrame).length
196
+ : null;
185
197
  return {
198
+ framesRendered,
186
199
  chunks: chunkCount,
187
200
  done: false,
188
201
  encodingStatus,
@@ -190,7 +203,7 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
190
203
  renderId,
191
204
  renderMetadata,
192
205
  bucket: bucketName,
193
- outputFile: (_k = outputFile === null || outputFile === void 0 ? void 0 : outputFile.url) !== null && _k !== void 0 ? _k : null,
206
+ outputFile: (_h = outputFile === null || outputFile === void 0 ? void 0 : outputFile.url) !== null && _h !== void 0 ? _h : null,
194
207
  timeToFinish,
195
208
  errors: allErrors,
196
209
  fatalErrorEncountered: allErrors.some((f) => f.isFatal && !f.willRetry),
@@ -205,18 +218,17 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
205
218
  type: 'absolute-time',
206
219
  })
207
220
  : null,
208
- timeToInvokeLambdas: (_l = encodingStatus === null || encodingStatus === void 0 ? void 0 : encodingStatus.timeToInvoke) !== null && _l !== void 0 ? _l : lambdasInvokedStats.timeToInvokeLambdas,
209
221
  overallProgress: (0, get_overall_progress_1.getOverallProgress)({
210
222
  cleanup: cleanup ? cleanup.filesDeleted / cleanup.minFilesToDelete : 0,
211
- encoding: finalEncodingStatus && renderMetadata
212
- ? finalEncodingStatus.framesEncoded /
213
- renderMetadata.videoConfig.durationInFrames
223
+ encoding: finalEncodingStatus && renderMetadata && frameCount
224
+ ? finalEncodingStatus.framesEncoded / frameCount
214
225
  : 0,
215
226
  invoking: renderMetadata
216
227
  ? lambdasInvokedStats.lambdasInvoked /
217
228
  renderMetadata.estimatedRenderLambdaInvokations
218
229
  : 0,
219
230
  rendering: renderMetadata ? chunkCount / renderMetadata.totalChunks : 0,
231
+ frames: frameCount === null ? 0 : framesRendered / frameCount,
220
232
  }),
221
233
  retriesInfo,
222
234
  outKey: outputFile && renderMetadata
@@ -227,6 +239,8 @@ const getProgress = async ({ bucketName, renderId, expectedBucketOwner, region,
227
239
  .renderBucketName
228
240
  : null,
229
241
  mostExpensiveFrameRanges: null,
242
+ timeToEncode: null,
243
+ outputSizeInBytes: null,
230
244
  };
231
245
  };
232
246
  exports.getProgress = getProgress;
@@ -0,0 +1,8 @@
1
+ import type { _Object } from '@aws-sdk/client-s3';
2
+ export declare const getRenderedFramesProgress: ({ contents, renderId, framesPerLambda, everyNthFrame, frameRange, }: {
3
+ contents: _Object[];
4
+ renderId: string;
5
+ framesPerLambda: number;
6
+ frameRange: [number, number];
7
+ everyNthFrame: number;
8
+ }) => number;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRenderedFramesProgress = void 0;
4
+ const chunk_progress_1 = require("../../shared/chunk-progress");
5
+ const constants_1 = require("../../shared/constants");
6
+ const parse_chunk_key_1 = require("../../shared/parse-chunk-key");
7
+ const parse_lambda_initialized_key_1 = require("../../shared/parse-lambda-initialized-key");
8
+ const plan_frame_ranges_1 = require("../chunk-optimization/plan-frame-ranges");
9
+ const getRenderedFramesProgress = ({ contents, renderId, framesPerLambda, everyNthFrame, frameRange, }) => {
10
+ const chunkProgress = {};
11
+ const { chunks } = (0, plan_frame_ranges_1.planFrameRanges)({
12
+ everyNthFrame,
13
+ frameRange,
14
+ framesPerLambda,
15
+ });
16
+ // Sort, so only the latest attempt is used
17
+ const sortedChunks = contents
18
+ .filter((c) => {
19
+ return c.Key.startsWith((0, constants_1.lambdaChunkInitializedPrefix)(renderId));
20
+ })
21
+ .sort((a, b) => {
22
+ return a.Key.localeCompare(b.Key);
23
+ });
24
+ for (const chunk of sortedChunks) {
25
+ const key = (0, parse_lambda_initialized_key_1.parseLambdaInitializedKey)(chunk.Key);
26
+ chunkProgress[key.chunk] = (0, chunk_progress_1.getProgressOfChunk)(chunk.ETag);
27
+ }
28
+ for (const chunk of contents.filter((c) => { var _a; return (_a = c.Key) === null || _a === void 0 ? void 0 : _a.startsWith((0, constants_1.chunkKey)(renderId)); })) {
29
+ const parsed = (0, parse_chunk_key_1.parseLambdaChunkKey)(chunk.Key);
30
+ const frameRangeInChunk = chunks[parsed.chunk];
31
+ chunkProgress[parsed.chunk] =
32
+ frameRangeInChunk[1] - frameRangeInChunk[0] + 1;
33
+ }
34
+ const framesRendered = Object.values(chunkProgress).reduce((a, b) => a + b, 0);
35
+ return framesRendered;
36
+ };
37
+ exports.getRenderedFramesProgress = getRenderedFramesProgress;
@@ -1,12 +1,33 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.launchHandler = void 0;
7
27
  const client_lambda_1 = require("@aws-sdk/client-lambda");
8
28
  const renderer_1 = require("@remotion/renderer");
9
- const fs_1 = __importDefault(require("fs"));
29
+ const fs_1 = __importStar(require("fs"));
30
+ const path_1 = require("path");
10
31
  const remotion_1 = require("remotion");
11
32
  const version_1 = require("remotion/version");
12
33
  const aws_clients_1 = require("../shared/aws-clients");
@@ -29,7 +50,6 @@ const find_output_file_in_bucket_1 = require("./helpers/find-output-file-in-buck
29
50
  const get_browser_instance_1 = require("./helpers/get-browser-instance");
30
51
  const get_current_region_1 = require("./helpers/get-current-region");
31
52
  const get_files_to_delete_1 = require("./helpers/get-files-to-delete");
32
- const get_lambdas_invoked_stats_1 = require("./helpers/get-lambdas-invoked-stats");
33
53
  const get_output_url_from_metadata_1 = require("./helpers/get-output-url-from-metadata");
34
54
  const inspect_errors_1 = require("./helpers/inspect-errors");
35
55
  const io_1 = require("./helpers/io");
@@ -223,6 +243,8 @@ const innerLaunchHandler = async (params, options) => {
223
243
  renderId: params.renderId,
224
244
  outName: (_b = params.outName) !== null && _b !== void 0 ? _b : undefined,
225
245
  privacy: params.privacy,
246
+ everyNthFrame: params.everyNthFrame,
247
+ frameRange: realFrameRange,
226
248
  };
227
249
  const { key, renderBucketName, customCredentials } = (0, expected_out_name_1.getExpectedOutName)(renderMetadata, params.bucketName, typeof params.outName === 'string' || typeof params.outName === 'undefined'
228
250
  ? null
@@ -264,27 +286,17 @@ const innerLaunchHandler = async (params, options) => {
264
286
  }));
265
287
  reqSend.end();
266
288
  let lastProgressUploaded = 0;
267
- let encodingStop = null;
268
- const onProgress = (framesEncoded, start) => {
289
+ const onProgress = (framesEncoded) => {
269
290
  const relativeProgress = framesEncoded / frameCount.length;
270
291
  const deltaSinceLastProgressUploaded = relativeProgress - lastProgressUploaded;
271
- if (relativeProgress === 1) {
272
- encodingStop = Date.now();
273
- }
274
292
  if (deltaSinceLastProgressUploaded < 0.1) {
275
293
  return;
276
294
  }
277
295
  lastProgressUploaded = relativeProgress;
278
- const encodingProgress = {
279
- framesEncoded,
280
- totalFrames: frameCount.length,
281
- doneIn: encodingStop ? encodingStop - start : null,
282
- timeToInvoke: null,
283
- };
284
296
  (0, io_1.lambdaWriteFile)({
285
297
  bucketName: params.bucketName,
286
298
  key: (0, constants_1.encodingProgressKey)(params.renderId),
287
- body: JSON.stringify(encodingProgress),
299
+ body: String(framesEncoded),
288
300
  region: (0, get_current_region_1.getCurrentRegionInFunction)(),
289
301
  privacy: 'private',
290
302
  expectedBucketOwner: options.expectedBucketOwner,
@@ -338,24 +350,35 @@ const innerLaunchHandler = async (params, options) => {
338
350
  throw new Error('Stopping Lambda function because error occurred: ' + errors[0].stack);
339
351
  };
340
352
  const fps = comp.fps / params.everyNthFrame;
341
- const { outfile, cleanupChunksProm, encodingStart } = await (0, concat_videos_1.concatVideosS3)({
353
+ const outdir = (0, path_1.join)(renderer_1.RenderInternals.tmpDir(constants_1.CONCAT_FOLDER_TOKEN), 'bucket');
354
+ if ((0, fs_1.existsSync)(outdir)) {
355
+ (fs_1.rmSync !== null && fs_1.rmSync !== void 0 ? fs_1.rmSync : fs_1.rmdirSync)(outdir, {
356
+ recursive: true,
357
+ });
358
+ }
359
+ (0, fs_1.mkdirSync)(outdir);
360
+ const files = await (0, concat_videos_1.getAllFilesS3)({
342
361
  bucket: params.bucketName,
343
362
  expectedFiles: chunkCount,
344
- onProgress,
345
- numberOfFrames: frameCount.length,
363
+ outdir,
346
364
  renderId: params.renderId,
347
365
  region: (0, get_current_region_1.getCurrentRegionInFunction)(),
348
- codec: params.codec,
349
366
  expectedBucketOwner: options.expectedBucketOwner,
367
+ onErrors,
368
+ });
369
+ const encodingStart = Date.now();
370
+ const { outfile, cleanupChunksProm } = await (0, concat_videos_1.concatVideosS3)({
371
+ onProgress,
372
+ numberOfFrames: frameCount.length,
373
+ codec: params.codec,
350
374
  fps,
351
375
  numberOfGifLoops: params.numberOfGifLoops,
352
376
  ffmpegExecutable: null,
353
377
  remotionRoot: process.cwd(),
354
- onErrors,
378
+ files,
379
+ outdir,
355
380
  });
356
- if (!encodingStop) {
357
- encodingStop = Date.now();
358
- }
381
+ const encodingStop = Date.now();
359
382
  const outputSize = fs_1.default.statSync(outfile);
360
383
  await (0, io_1.lambdaWriteFile)({
361
384
  bucketName: renderBucketName,
@@ -373,22 +396,10 @@ const innerLaunchHandler = async (params, options) => {
373
396
  expectedBucketOwner: options.expectedBucketOwner,
374
397
  region: (0, get_current_region_1.getCurrentRegionInFunction)(),
375
398
  });
376
- const finalEncodingProgress = {
377
- framesEncoded: frameCount.length,
378
- totalFrames: frameCount.length,
379
- doneIn: encodingStop ? encodingStop - encodingStart : null,
380
- timeToInvoke: (0, get_lambdas_invoked_stats_1.getLambdasInvokedStats)({
381
- contents,
382
- renderId: params.renderId,
383
- estimatedRenderLambdaInvokations: renderMetadata.estimatedRenderLambdaInvokations,
384
- checkIfAllLambdasWereInvoked: false,
385
- startDate: renderMetadata.startedDate,
386
- }).timeToInvokeLambdas,
387
- };
388
399
  const finalEncodingProgressProm = (0, io_1.lambdaWriteFile)({
389
400
  bucketName: params.bucketName,
390
401
  key: (0, constants_1.encodingProgressKey)(params.renderId),
391
- body: JSON.stringify(finalEncodingProgress),
402
+ body: String(frameCount.length),
392
403
  region: (0, get_current_region_1.getCurrentRegionInFunction)(),
393
404
  privacy: 'private',
394
405
  expectedBucketOwner: options.expectedBucketOwner,
@@ -9,13 +9,11 @@ const renderer_1 = require("@remotion/renderer");
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const aws_clients_1 = require("../shared/aws-clients");
12
+ const chunk_progress_1 = require("../shared/chunk-progress");
12
13
  const constants_1 = require("../shared/constants");
13
14
  const deserialize_input_props_1 = require("../shared/deserialize-input-props");
14
- const clean_tmpdir_1 = require("./helpers/clean-tmpdir");
15
15
  const get_browser_instance_1 = require("./helpers/get-browser-instance");
16
16
  const get_current_region_1 = require("./helpers/get-current-region");
17
- const get_files_in_folder_1 = require("./helpers/get-files-in-folder");
18
- const get_folder_size_1 = require("./helpers/get-folder-size");
19
17
  const io_1 = require("./helpers/io");
20
18
  const write_lambda_error_1 = require("./helpers/write-lambda-error");
21
19
  const renderHandler = async (params, options, logs) => {
@@ -64,9 +62,17 @@ const renderHandler = async (params, options, logs) => {
64
62
  inputProps,
65
63
  frameRange: params.frameRange,
66
64
  onProgress: ({ renderedFrames, encodedFrames, stitchStage }) => {
67
- if (renderedFrames % 10 === 0 &&
65
+ if (renderedFrames % 5 === 0 &&
68
66
  renderer_1.RenderInternals.isEqualOrBelowLogLevel(params.logLevel, 'verbose')) {
69
67
  console.log(`Rendered ${renderedFrames} frames, encoded ${encodedFrames} frames, stage = ${stitchStage}`);
68
+ (0, chunk_progress_1.writeLambdaInitializedFile)({
69
+ attempt: params.attempt,
70
+ bucketName: params.bucketName,
71
+ chunk: params.chunk,
72
+ expectedBucketOwner: options.expectedBucketOwner,
73
+ framesRendered: renderedFrames,
74
+ renderId: params.renderId,
75
+ }).catch((err) => reject(err));
70
76
  }
71
77
  const allFrames = renderer_1.RenderInternals.getFramesToRender(params.frameRange, params.everyNthFrame);
72
78
  if (renderedFrames === allFrames.length) {
@@ -76,26 +82,13 @@ const renderHandler = async (params, options, logs) => {
76
82
  },
77
83
  concurrency: params.concurrencyPerLambda,
78
84
  onStart: () => {
79
- (0, io_1.lambdaWriteFile)({
80
- privacy: 'private',
85
+ (0, chunk_progress_1.writeLambdaInitializedFile)({
86
+ attempt: params.attempt,
81
87
  bucketName: params.bucketName,
82
- body: JSON.stringify({
83
- filesCleaned: clean_tmpdir_1.deletedFilesSize,
84
- filesInTmp: fs_1.default.readdirSync('/tmp'),
85
- isWarm: options.isWarm,
86
- deletedFiles: clean_tmpdir_1.deletedFiles,
87
- tmpSize: (0, get_folder_size_1.getFolderSizeRecursively)('/tmp'),
88
- tmpDirFiles: (0, get_files_in_folder_1.getFolderFiles)('/tmp'),
89
- }),
90
- key: (0, constants_1.lambdaChunkInitializedKey)({
91
- renderId: params.renderId,
92
- chunk: params.chunk,
93
- attempt: params.attempt,
94
- }),
95
- region: (0, get_current_region_1.getCurrentRegionInFunction)(),
88
+ chunk: params.chunk,
96
89
  expectedBucketOwner: options.expectedBucketOwner,
97
- downloadBehavior: null,
98
- customCredentials: null,
90
+ framesRendered: 0,
91
+ renderId: params.renderId,
99
92
  }).catch((err) => reject(err));
100
93
  },
101
94
  puppeteerInstance: browserInstance,
@@ -93,6 +93,8 @@ const innerStillHandler = async (lambdaParams, renderId, options) => {
93
93
  renderId,
94
94
  outName: (_b = lambdaParams.outName) !== null && _b !== void 0 ? _b : undefined,
95
95
  privacy: lambdaParams.privacy,
96
+ everyNthFrame: 1,
97
+ frameRange: [lambdaParams.frame, lambdaParams.frame],
96
98
  };
97
99
  await (0, io_1.lambdaWriteFile)({
98
100
  bucketName,
@@ -3,6 +3,7 @@ import { IAMClient } from '@aws-sdk/client-iam';
3
3
  import { LambdaClient } from '@aws-sdk/client-lambda';
4
4
  import { S3Client } from '@aws-sdk/client-s3';
5
5
  import { ServiceQuotasClient } from '@aws-sdk/client-service-quotas';
6
+ import { STSClient } from '@aws-sdk/client-sts';
6
7
  import type { AwsRegion } from '../pricing/aws-regions';
7
8
  export declare type ServiceMapping = {
8
9
  s3: S3Client;
@@ -10,6 +11,7 @@ export declare type ServiceMapping = {
10
11
  iam: IAMClient;
11
12
  lambda: LambdaClient;
12
13
  servicequotas: ServiceQuotasClient;
14
+ sts: STSClient;
13
15
  };
14
16
  export declare type CustomCredentialsWithoutSensitiveData = {
15
17
  endpoint: string;
@@ -28,3 +30,4 @@ export declare const getS3Client: (region: AwsRegion, customCredentials: CustomC
28
30
  export declare const getLambdaClient: (region: AwsRegion) => LambdaClient;
29
31
  export declare const getIamClient: (region: AwsRegion) => IAMClient;
30
32
  export declare const getServiceQuotasClient: (region: AwsRegion) => ServiceQuotasClient;
33
+ export declare const getStsClient: (region: AwsRegion) => STSClient;