@remotion/lambda 4.0.46 → 4.0.47

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.
package/LICENSE.md CHANGED
@@ -38,4 +38,4 @@ Support is provided on a best-we-can-do basis via GitHub Issues and Discord.
38
38
 
39
39
  You are required to obtain a company license to use Remotion if you are not within the group of entities eligible for a free license. This license will enable you to use Remotion for the allowed use cases specified in the free license, and give you access to prioritized support (read the [Support Policy](/docs/support)).
40
40
 
41
- Visit [companies.remotion.dev](https://companies.remotion.dev) for pricing and to buy a license.
41
+ Visit [remotion.pro](https://www.remotion.pro) for pricing and to buy a license.
@@ -22,6 +22,11 @@ const quit_1 = require("../../helpers/quit");
22
22
  const log_1 = require("../../log");
23
23
  const progress_1 = require("./progress");
24
24
  exports.RENDER_COMMAND = 'render';
25
+ function getTotalFrames(status) {
26
+ return status.renderMetadata
27
+ ? renderer_1.RenderInternals.getFramesToRender(status.renderMetadata.frameRange, status.renderMetadata.everyNthFrame).length
28
+ : null;
29
+ }
25
30
  const renderCommand = async (args, remotionRoot) => {
26
31
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
27
32
  const serveUrl = args[0];
@@ -299,8 +304,3 @@ const renderCommand = async (args, remotionRoot) => {
299
304
  }
300
305
  };
301
306
  exports.renderCommand = renderCommand;
302
- function getTotalFrames(status) {
303
- return status.renderMetadata
304
- ? renderer_1.RenderInternals.getFramesToRender(status.renderMetadata.frameRange, status.renderMetadata.everyNthFrame).length
305
- : null;
306
- }
@@ -0,0 +1,4 @@
1
+ import { Internals } from 'remotion';
2
+ export declare const validateFps: typeof Internals.validateFps;
3
+ export declare const validateDimension: typeof Internals.validateDimension;
4
+ export declare const validateDurationInFrames: typeof Internals.validateDurationInFrames;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateDurationInFrames = exports.validateDimension = exports.validateFps = void 0;
4
+ /* eslint-disable prefer-destructuring */
5
+ const remotion_1 = require("remotion");
6
+ exports.validateFps = remotion_1.Internals.validateFps;
7
+ exports.validateDimension = remotion_1.Internals.validateDimension;
8
+ exports.validateDurationInFrames = remotion_1.Internals.validateDurationInFrames;
package/dist/cli/log.d.ts CHANGED
@@ -2,24 +2,24 @@ export declare const Log: {
2
2
  verbose: (message?: any, ...optionalParams: any[]) => void;
3
3
  verboseAdvanced: (options: {
4
4
  indent: boolean;
5
- logLevel: "error" | "verbose" | "info" | "warn";
5
+ logLevel: "verbose" | "info" | "warn" | "error";
6
6
  } & {
7
7
  tag?: string | undefined;
8
8
  }, message?: any, ...optionalParams: any[]) => void;
9
9
  info: (message?: any, ...optionalParams: any[]) => void;
10
10
  infoAdvanced: (options: {
11
11
  indent: boolean;
12
- logLevel: "error" | "verbose" | "info" | "warn";
12
+ logLevel: "verbose" | "info" | "warn" | "error";
13
13
  }, message?: any, ...optionalParams: any[]) => void;
14
14
  warn: (message?: any, ...optionalParams: any[]) => void;
15
15
  warnAdvanced: (options: {
16
16
  indent: boolean;
17
- logLevel: "error" | "verbose" | "info" | "warn";
17
+ logLevel: "verbose" | "info" | "warn" | "error";
18
18
  }, message?: any, ...optionalParams: any[]) => void;
19
19
  error: (message?: any, ...optionalParams: any[]) => void;
20
20
  errorAdvanced: (options: {
21
21
  indent: boolean;
22
- logLevel: "error" | "verbose" | "info" | "warn";
22
+ logLevel: "verbose" | "info" | "warn" | "error";
23
23
  } & {
24
24
  tag?: string | undefined;
25
25
  }, message?: any, ...optionalParams: any[]) => void;
@@ -3,8 +3,5 @@ export declare const planFrameRanges: ({ framesPerLambda, frameRange, everyNthFr
3
3
  frameRange: [number, number];
4
4
  everyNthFrame: number;
5
5
  }) => {
6
- chunks: [
7
- number,
8
- number
9
- ][];
6
+ chunks: [number, number][];
10
7
  };
@@ -10,7 +10,7 @@ const convert_to_serve_url_1 = require("../shared/convert-to-serve-url");
10
10
  const get_browser_instance_1 = require("./helpers/get-browser-instance");
11
11
  const get_current_region_1 = require("./helpers/get-current-region");
12
12
  const compositionsHandler = async (lambdaParams, options) => {
13
- var _a, _b, _c;
13
+ var _a;
14
14
  if (lambdaParams.type !== defaults_1.LambdaRoutines.compositions) {
15
15
  throw new TypeError('Expected info compositions');
16
16
  }
@@ -21,16 +21,17 @@ const compositionsHandler = async (lambdaParams, options) => {
21
21
  throw new Error(`Version mismatch: When calling getCompositionsOnLambda(), you passed ${process.env.AWS_LAMBDA_FUNCTION_NAME} as the function, which has the version ${version_1.VERSION}, but the @remotion/lambda package you used to invoke the function has version ${lambdaParams.version}. Deploy a new function and use it to call getCompositionsOnLambda(). See: https://www.remotion.dev/docs/lambda/upgrading`);
22
22
  }
23
23
  const region = (0, get_current_region_1.getCurrentRegionInFunction)();
24
- const [bucketName, browserInstance] = await Promise.all([
25
- (_a = lambdaParams.bucketName) !== null && _a !== void 0 ? _a : (0, get_or_create_bucket_1.internalGetOrCreateBucket)({
24
+ const browserInstancePromise = (0, get_browser_instance_1.getBrowserInstance)(lambdaParams.logLevel, false, lambdaParams.chromiumOptions);
25
+ const bucketNamePromise = lambdaParams.bucketName
26
+ ? Promise.resolve(lambdaParams.bucketName)
27
+ : (0, get_or_create_bucket_1.internalGetOrCreateBucket)({
26
28
  region,
27
29
  enableFolderExpiry: null,
28
30
  customCredentials: null,
29
- }).then((b) => b.bucketName),
30
- (0, get_browser_instance_1.getBrowserInstance)(lambdaParams.logLevel, false, (_b = lambdaParams.chromiumOptions) !== null && _b !== void 0 ? _b : {}),
31
- ]);
31
+ }).then((b) => b.bucketName);
32
+ const bucketName = await bucketNamePromise;
32
33
  const serializedInputPropsWithCustomSchema = await (0, compress_props_1.decompressInputProps)({
33
- bucketName,
34
+ bucketName: await bucketNamePromise,
34
35
  expectedBucketOwner: options.expectedBucketOwner,
35
36
  region: (0, get_current_region_1.getCurrentRegionInFunction)(),
36
37
  serialized: lambdaParams.inputProps,
@@ -43,9 +44,9 @@ const compositionsHandler = async (lambdaParams, options) => {
43
44
  });
44
45
  const compositions = await renderer_1.RenderInternals.internalGetCompositions({
45
46
  serveUrlOrWebpackUrl: realServeUrl,
46
- puppeteerInstance: browserInstance,
47
+ puppeteerInstance: (await browserInstancePromise).instance,
47
48
  serializedInputPropsWithCustomSchema,
48
- envVariables: (_c = lambdaParams.envVariables) !== null && _c !== void 0 ? _c : {},
49
+ envVariables: (_a = lambdaParams.envVariables) !== null && _a !== void 0 ? _a : {},
49
50
  timeoutInMilliseconds: lambdaParams.timeoutInMilliseconds,
50
51
  chromiumOptions: lambdaParams.chromiumOptions,
51
52
  port: null,
@@ -56,6 +57,7 @@ const compositionsHandler = async (lambdaParams, options) => {
56
57
  onBrowserLog: null,
57
58
  offthreadVideoCacheSizeInBytes: lambdaParams.offthreadVideoCacheSizeInBytes,
58
59
  });
60
+ (await browserInstancePromise).instance.forgetEventLoop();
59
61
  return Promise.resolve({
60
62
  compositions,
61
63
  type: 'success',
@@ -1,2 +1,8 @@
1
1
  import type { ChromiumOptions, LogLevel, openBrowser } from '@remotion/renderer';
2
- export declare const getBrowserInstance: (logLevel: LogLevel, indent: boolean, chromiumOptions: ChromiumOptions) => ReturnType<typeof openBrowser>;
2
+ import type { Await } from '../../shared/await';
3
+ type LaunchedBrowser = {
4
+ instance: Await<ReturnType<typeof openBrowser>>;
5
+ configurationString: string;
6
+ };
7
+ export declare const getBrowserInstance: (logLevel: LogLevel, indent: boolean, chromiumOptions: ChromiumOptions) => Promise<LaunchedBrowser>;
8
+ export {};
@@ -3,6 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBrowserInstance = void 0;
4
4
  const renderer_1 = require("@remotion/renderer");
5
5
  const get_chromium_executable_path_1 = require("./get-chromium-executable-path");
6
+ const makeConfigurationString = (options, logLevel) => {
7
+ var _a, _b, _c;
8
+ return [
9
+ `web-security-${Boolean(options.disableWebSecurity)}`,
10
+ `multi-process-${Boolean(options.enableMultiProcessOnLinux)}`,
11
+ `ignore-certificate-errors-${Boolean(options.ignoreCertificateErrors)}`,
12
+ `log-level-${logLevel}`,
13
+ `gl-${(_a = options.gl) !== null && _a !== void 0 ? _a : null}`,
14
+ `userAgent-${(_b = options.userAgent) !== null && _b !== void 0 ? _b : null}`,
15
+ `headless-${(_c = options.headless) !== null && _c !== void 0 ? _c : false}`,
16
+ ].join('/');
17
+ };
6
18
  let _browserInstance;
7
19
  let launching = false;
8
20
  const waitForLaunched = () => {
@@ -21,38 +33,54 @@ const waitForLaunched = () => {
21
33
  };
22
34
  const getBrowserInstance = async (logLevel, indent, chromiumOptions) => {
23
35
  var _a;
36
+ const actualChromiumOptions = {
37
+ ...chromiumOptions,
38
+ // Override the `null` value, which might come from CLI with swANGLE
39
+ gl: (_a = chromiumOptions.gl) !== null && _a !== void 0 ? _a : 'swangle',
40
+ };
24
41
  if (launching) {
42
+ renderer_1.RenderInternals.Log.info('Already waiting for browser launch...');
25
43
  await waitForLaunched();
26
44
  if (!_browserInstance) {
27
45
  throw new Error('expected to launch');
28
46
  }
29
- return _browserInstance;
30
47
  }
31
- if (_browserInstance) {
48
+ const configurationString = makeConfigurationString(actualChromiumOptions, logLevel);
49
+ if (!_browserInstance) {
50
+ renderer_1.RenderInternals.Log.info('Cold Lambda function, launching new Lambda function');
51
+ launching = true;
52
+ const execPath = (0, get_chromium_executable_path_1.executablePath)();
53
+ const instance = await renderer_1.RenderInternals.internalOpenBrowser({
54
+ browser: 'chrome',
55
+ browserExecutable: execPath,
56
+ chromiumOptions: actualChromiumOptions,
57
+ forceDeviceScaleFactor: undefined,
58
+ indent: false,
59
+ viewport: null,
60
+ logLevel,
61
+ });
62
+ instance.on('disconnected', () => {
63
+ var _a;
64
+ console.log('Browser disconnected / crashed');
65
+ (_a = _browserInstance === null || _browserInstance === void 0 ? void 0 : _browserInstance.instance) === null || _a === void 0 ? void 0 : _a.close(true, logLevel, indent).catch(() => undefined);
66
+ _browserInstance = null;
67
+ });
68
+ _browserInstance = {
69
+ instance,
70
+ configurationString,
71
+ };
72
+ launching = false;
32
73
  return _browserInstance;
33
74
  }
34
- launching = true;
35
- const execPath = (0, get_chromium_executable_path_1.executablePath)();
36
- const actualChromiumOptions = {
37
- ...chromiumOptions,
38
- // Override the `null` value, which might come from CLI with swANGLE
39
- gl: (_a = chromiumOptions.gl) !== null && _a !== void 0 ? _a : 'swangle',
40
- };
41
- _browserInstance = await renderer_1.RenderInternals.internalOpenBrowser({
42
- browser: 'chrome',
43
- browserExecutable: execPath,
44
- chromiumOptions: actualChromiumOptions,
45
- forceDeviceScaleFactor: undefined,
46
- indent: false,
47
- viewport: null,
48
- logLevel,
49
- });
50
- _browserInstance.on('disconnected', () => {
51
- console.log('Browser disconnected / crashed');
52
- _browserInstance === null || _browserInstance === void 0 ? void 0 : _browserInstance.close(true, logLevel, indent).catch(() => undefined);
75
+ if (_browserInstance.configurationString !== configurationString) {
76
+ renderer_1.RenderInternals.Log.info('Warm Lambda function, but Browser configuration changed. Killing old browser instance.');
77
+ _browserInstance.instance.rememberEventLoop();
78
+ await _browserInstance.instance.close(true, logLevel, indent);
53
79
  _browserInstance = null;
54
- });
55
- launching = false;
80
+ return (0, exports.getBrowserInstance)(logLevel, indent, chromiumOptions);
81
+ }
82
+ renderer_1.RenderInternals.Log.info('Warm Lambda function, reusing browser instance');
83
+ _browserInstance.instance.rememberEventLoop();
56
84
  return _browserInstance;
57
85
  };
58
86
  exports.getBrowserInstance = getBrowserInstance;
@@ -22,6 +22,13 @@ class ResponseStream extends stream_1.Stream.Writable {
22
22
  }
23
23
  }
24
24
  exports.ResponseStream = ResponseStream;
25
+ function patchArgs(argList) {
26
+ if (!(argList[1] instanceof ResponseStream)) {
27
+ const responseStream = new ResponseStream();
28
+ argList.splice(1, 0, responseStream);
29
+ }
30
+ return argList[1];
31
+ }
25
32
  exports.HANDLER_STREAMING = Symbol.for('aws.lambda.runtime.handler.streaming');
26
33
  exports.STREAM_RESPONSE = 'response';
27
34
  function isInAWS(handler) {
@@ -61,10 +68,3 @@ function streamifyResponse(handler) {
61
68
  });
62
69
  }
63
70
  exports.streamifyResponse = streamifyResponse;
64
- function patchArgs(argList) {
65
- if (!(argList[1] instanceof ResponseStream)) {
66
- const responseStream = new ResponseStream();
67
- argList.splice(1, 0, responseStream);
68
- }
69
- return argList[1];
70
- }
@@ -164,12 +164,5 @@ const routine = async (params, responseStream, context) => {
164
164
  responseStream.write(JSON.stringify(res));
165
165
  responseStream.end();
166
166
  }
167
- finally {
168
- responseStream.on('close', () => {
169
- if (!process.env.VITEST) {
170
- process.exit(0);
171
- }
172
- });
173
- }
174
167
  };
175
168
  exports.handler = (0, streamify_response_1.streamifyResponse)(routine);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.launchHandler = void 0;
4
+ /* eslint-disable @typescript-eslint/no-use-before-define */
4
5
  const client_lambda_1 = require("@aws-sdk/client-lambda");
5
6
  const renderer_1 = require("@remotion/renderer");
6
7
  const version_1 = require("remotion/version");
@@ -56,7 +57,7 @@ const innerLaunchHandler = async ({ functionName, params, options, onAllChunksAv
56
57
  throw new Error('Expected launch type');
57
58
  }
58
59
  const startedDate = Date.now();
59
- const browserInstance = await (0, get_browser_instance_1.getBrowserInstance)(params.logLevel, false, params.chromiumOptions);
60
+ const browserInstance = (0, get_browser_instance_1.getBrowserInstance)(params.logLevel, false, params.chromiumOptions);
60
61
  const inputPropsPromise = (0, compress_props_1.decompressInputProps)({
61
62
  bucketName: params.bucketName,
62
63
  expectedBucketOwner: options.expectedBucketOwner,
@@ -69,7 +70,7 @@ const innerLaunchHandler = async ({ functionName, params, options, onAllChunksAv
69
70
  const comp = await (0, validate_composition_1.validateComposition)({
70
71
  serveUrl: params.serveUrl,
71
72
  composition: params.composition,
72
- browserInstance,
73
+ browserInstance: (await browserInstance).instance,
73
74
  serializedInputPropsWithCustomSchema,
74
75
  envVariables: (_a = params.envVariables) !== null && _a !== void 0 ? _a : {},
75
76
  timeoutInMilliseconds: params.timeoutInMilliseconds,
@@ -245,6 +246,7 @@ const innerLaunchHandler = async ({ functionName, params, options, onAllChunksAv
245
246
  await callFunctionWithRetry({ payload, retries: 0, functionName });
246
247
  }));
247
248
  reqSend.end();
249
+ (await browserInstance).instance.forgetEventLoop();
248
250
  const fps = comp.fps / params.everyNthFrame;
249
251
  const postRenderData = await (0, merge_chunks_1.mergeChunksAndFinishRender)({
250
252
  bucketName: params.bucketName,
@@ -20,7 +20,6 @@ const io_1 = require("./helpers/io");
20
20
  const on_downloads_logger_1 = require("./helpers/on-downloads-logger");
21
21
  const write_lambda_error_1 = require("./helpers/write-lambda-error");
22
22
  const renderHandler = async (params, options, logs) => {
23
- var _a;
24
23
  if (params.type !== constants_1.LambdaRoutines.renderer) {
25
24
  throw new Error('Params must be renderer');
26
25
  }
@@ -41,7 +40,7 @@ const renderHandler = async (params, options, logs) => {
41
40
  serialized: params.resolvedProps,
42
41
  propsType: 'resolved-props',
43
42
  });
44
- const browserInstance = await (0, get_browser_instance_1.getBrowserInstance)(params.logLevel, false, (_a = params.chromiumOptions) !== null && _a !== void 0 ? _a : {});
43
+ const browserInstance = await (0, get_browser_instance_1.getBrowserInstance)(params.logLevel, false, params.chromiumOptions);
45
44
  const outputPath = renderer_1.RenderInternals.tmpDir('remotion-render-');
46
45
  if (typeof params.chunk !== 'number') {
47
46
  throw new Error('must pass chunk');
@@ -115,7 +114,7 @@ const renderHandler = async (params, options, logs) => {
115
114
  renderId: params.renderId,
116
115
  }).catch((err) => reject(err));
117
116
  },
118
- puppeteerInstance: browserInstance,
117
+ puppeteerInstance: browserInstance.instance,
119
118
  serveUrl: params.serveUrl,
120
119
  jpegQuality: (_a = params.jpegQuality) !== null && _a !== void 0 ? _a : renderer_1.RenderInternals.DEFAULT_JPEG_QUALITY,
121
120
  envVariables: (_b = params.envVariables) !== null && _b !== void 0 ? _b : {},
@@ -209,6 +208,8 @@ const renderHandler = async (params, options, logs) => {
209
208
  customCredentials: null,
210
209
  }),
211
210
  ]);
211
+ browserInstance.instance.forgetEventLoop();
212
+ renderer_1.RenderInternals.Log.verbose('Done!');
212
213
  return {};
213
214
  };
214
215
  const rendererHandler = async (params, options) => {
@@ -31,7 +31,7 @@ const on_downloads_logger_1 = require("./helpers/on-downloads-logger");
31
31
  const validate_composition_1 = require("./helpers/validate-composition");
32
32
  const write_lambda_error_1 = require("./helpers/write-lambda-error");
33
33
  const innerStillHandler = async ({ params: lambdaParams, expectedBucketOwner, renderId, }) => {
34
- var _a, _b, _c, _d, _e, _f;
34
+ var _a, _b, _c, _d, _e;
35
35
  if (lambdaParams.type !== constants_1.LambdaRoutines.still) {
36
36
  throw new TypeError('Expected still type');
37
37
  }
@@ -45,17 +45,16 @@ const innerStillHandler = async ({ params: lambdaParams, expectedBucketOwner, re
45
45
  (0, validate_privacy_1.validatePrivacy)(lambdaParams.privacy, true);
46
46
  (0, validate_outname_1.validateOutname)(lambdaParams.outName, null, null);
47
47
  const start = Date.now();
48
- const [bucketName, browserInstance] = await Promise.all([
49
- (_a = lambdaParams.bucketName) !== null && _a !== void 0 ? _a : (0, get_or_create_bucket_1.internalGetOrCreateBucket)({
50
- region: (0, get_current_region_1.getCurrentRegionInFunction)(),
51
- enableFolderExpiry: null,
52
- customCredentials: null,
53
- }).then((b) => b.bucketName),
54
- (0, get_browser_instance_1.getBrowserInstance)(lambdaParams.logLevel, false, (_b = lambdaParams.chromiumOptions) !== null && _b !== void 0 ? _b : {}),
55
- ]);
48
+ const browserInstancePromise = (0, get_browser_instance_1.getBrowserInstance)(lambdaParams.logLevel, false, lambdaParams.chromiumOptions);
49
+ const bucketNamePromise = (_a = lambdaParams.bucketName) !== null && _a !== void 0 ? _a : (0, get_or_create_bucket_1.internalGetOrCreateBucket)({
50
+ region: (0, get_current_region_1.getCurrentRegionInFunction)(),
51
+ enableFolderExpiry: null,
52
+ customCredentials: null,
53
+ }).then((b) => b.bucketName);
56
54
  const outputDir = renderer_1.RenderInternals.tmpDir('remotion-render-');
57
55
  const outputPath = node_path_1.default.join(outputDir, 'output');
58
56
  const region = (0, get_current_region_1.getCurrentRegionInFunction)();
57
+ const bucketName = await bucketNamePromise;
59
58
  const serializedInputPropsWithCustomSchema = await (0, compress_props_1.decompressInputProps)({
60
59
  bucketName,
61
60
  expectedBucketOwner,
@@ -77,12 +76,13 @@ const innerStillHandler = async ({ params: lambdaParams, expectedBucketOwner, re
77
76
  webpackConfigOrServeUrl: serveUrl,
78
77
  offthreadVideoCacheSizeInBytes: lambdaParams.offthreadVideoCacheSizeInBytes,
79
78
  });
79
+ const browserInstance = await browserInstancePromise;
80
80
  const composition = await (0, validate_composition_1.validateComposition)({
81
81
  serveUrl,
82
- browserInstance,
82
+ browserInstance: browserInstance.instance,
83
83
  composition: lambdaParams.composition,
84
84
  serializedInputPropsWithCustomSchema,
85
- envVariables: (_c = lambdaParams.envVariables) !== null && _c !== void 0 ? _c : {},
85
+ envVariables: (_b = lambdaParams.envVariables) !== null && _b !== void 0 ? _b : {},
86
86
  chromiumOptions: lambdaParams.chromiumOptions,
87
87
  timeoutInMilliseconds: lambdaParams.timeoutInMilliseconds,
88
88
  port: null,
@@ -109,7 +109,7 @@ const innerStillHandler = async ({ params: lambdaParams, expectedBucketOwner, re
109
109
  memorySizeInMb: Number(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE),
110
110
  region: (0, get_current_region_1.getCurrentRegionInFunction)(),
111
111
  renderId,
112
- outName: (_d = lambdaParams.outName) !== null && _d !== void 0 ? _d : undefined,
112
+ outName: (_c = lambdaParams.outName) !== null && _c !== void 0 ? _c : undefined,
113
113
  privacy: lambdaParams.privacy,
114
114
  everyNthFrame: 1,
115
115
  frameRange: [lambdaParams.frame, lambdaParams.frame],
@@ -133,7 +133,7 @@ const innerStillHandler = async ({ params: lambdaParams, expectedBucketOwner, re
133
133
  composition,
134
134
  output: outputPath,
135
135
  serveUrl,
136
- envVariables: (_e = lambdaParams.envVariables) !== null && _e !== void 0 ? _e : {},
136
+ envVariables: (_d = lambdaParams.envVariables) !== null && _d !== void 0 ? _d : {},
137
137
  frame: renderer_1.RenderInternals.convertToPositiveFrameIndex({
138
138
  frame: lambdaParams.frame,
139
139
  durationInFrames: composition.durationInFrames,
@@ -141,8 +141,8 @@ const innerStillHandler = async ({ params: lambdaParams, expectedBucketOwner, re
141
141
  imageFormat: lambdaParams.imageFormat,
142
142
  serializedInputPropsWithCustomSchema,
143
143
  overwrite: false,
144
- puppeteerInstance: browserInstance,
145
- jpegQuality: (_f = lambdaParams.jpegQuality) !== null && _f !== void 0 ? _f : renderer_1.RenderInternals.DEFAULT_JPEG_QUALITY,
144
+ puppeteerInstance: browserInstance.instance,
145
+ jpegQuality: (_e = lambdaParams.jpegQuality) !== null && _e !== void 0 ? _e : renderer_1.RenderInternals.DEFAULT_JPEG_QUALITY,
146
146
  chromiumOptions: lambdaParams.chromiumOptions,
147
147
  scale: lambdaParams.scale,
148
148
  timeoutInMilliseconds: lambdaParams.timeoutInMilliseconds,
@@ -191,6 +191,7 @@ const innerStillHandler = async ({ params: lambdaParams, expectedBucketOwner, re
191
191
  // overestimate the price, but will only have a miniscule effect (~0.2%)
192
192
  diskSizeInMb: constants_1.MAX_EPHEMERAL_STORAGE_IN_MB,
193
193
  });
194
+ browserInstance.instance.forgetEventLoop();
194
195
  return {
195
196
  type: 'success',
196
197
  output: (0, get_output_url_from_metadata_1.getOutputUrlFromMetadata)(renderMetadata, bucketName, customCredentials),
@@ -1,60 +1,12 @@
1
1
  /// <reference types="node" />
2
- declare const framesRendered: "frames-rendered";
3
- declare const errorOccurred: "error-occurred";
4
- declare const renderIdDetermined: "render-id-determined";
5
- declare const chunkRendered: "chunk-rendered";
6
- declare const messageTypes: {
7
- readonly '1': {
8
- readonly type: "frames-rendered";
9
- };
10
- readonly '2': {
11
- readonly type: "error-occurred";
12
- };
13
- readonly '3': {
14
- readonly type: "render-id-determined";
15
- };
16
- readonly '4': {
17
- readonly type: "chunk-rendered";
18
- };
19
- };
20
- type MessageTypeId = keyof typeof messageTypes;
21
- type MessageType = (typeof messageTypes)[MessageTypeId]['type'];
22
- export declare const formatMap: {
23
- [key in MessageType]: 'json' | 'binary';
2
+ type OnMessage = (type: 'error' | 'success', nonce: string, data: Buffer) => void;
3
+ export declare const makeStreaming: (onMessage: OnMessage) => {
4
+ addData: (data: Buffer) => void;
24
5
  };
6
+ export declare const makePayloadMessage: (nonce: number, data: Buffer, status: 0 | 1) => Buffer;
25
7
  export type StreamingPayload = {
26
- type: typeof framesRendered;
27
- payload: {
28
- frames: number;
29
- };
30
- } | {
31
- type: typeof chunkRendered;
32
- payload: Buffer;
33
- } | {
34
- type: typeof errorOccurred;
35
- payload: {
36
- error: string;
37
- };
38
- } | {
39
- type: typeof renderIdDetermined;
40
- payload: {
41
- renderId: string;
42
- };
43
- };
44
- export declare const messageTypeIdToMessage: (messageTypeId: MessageTypeId) => MessageType;
45
- export declare const messageTypeToMessageId: (messageType: MessageType) => MessageTypeId;
46
- export type OnMessage = (options: {
47
- successType: 'error' | 'success';
48
- message: StreamingPayload;
49
- }) => void;
50
- export declare const makeStreaming: (options: {
51
- onMessage: OnMessage;
52
- }) => {
53
- addData: (data: Buffer) => void;
8
+ type: 'frames-rendered';
9
+ frames: number;
54
10
  };
55
- export declare const makePayloadMessage: ({ message, status, }: {
56
- message: StreamingPayload;
57
- status: 0 | 1;
58
- }) => Buffer;
59
11
  export type OnStream = (payload: StreamingPayload) => void;
60
12
  export {};
@@ -1,53 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makePayloadMessage = exports.makeStreaming = exports.messageTypeToMessageId = exports.messageTypeIdToMessage = exports.formatMap = void 0;
4
- const framesRendered = 'frames-rendered';
5
- const errorOccurred = 'error-occurred';
6
- const renderIdDetermined = 'render-id-determined';
7
- const chunkRendered = 'chunk-rendered';
8
- const messageTypes = {
9
- '1': { type: framesRendered },
10
- '2': { type: errorOccurred },
11
- '3': { type: renderIdDetermined },
12
- '4': { type: chunkRendered },
13
- };
14
- exports.formatMap = {
15
- [framesRendered]: 'json',
16
- [errorOccurred]: 'json',
17
- [renderIdDetermined]: 'json',
18
- [chunkRendered]: 'binary',
19
- };
20
- const messageTypeIdToMessage = (messageTypeId) => {
21
- const types = messageTypes[messageTypeId];
22
- if (!types) {
23
- throw new Error(`Unknown message type id ${messageTypeId}`);
24
- }
25
- return types.type;
26
- };
27
- exports.messageTypeIdToMessage = messageTypeIdToMessage;
28
- const messageTypeToMessageId = (messageType) => {
29
- const id = Object.keys(messageTypes).find((key) => messageTypes[key].type === messageType);
30
- if (!id) {
31
- throw new Error(`Unknown message type ${messageType}`);
32
- }
33
- return id;
34
- };
35
- exports.messageTypeToMessageId = messageTypeToMessageId;
36
- const magicSeparator = Buffer.from('remotion_buffer:');
37
- const makeStreaming = (options) => {
3
+ exports.makePayloadMessage = exports.makeStreaming = void 0;
4
+ const makeStreaming = (onMessage) => {
38
5
  let outputBuffer = Buffer.from('');
6
+ const separator = Buffer.from('remotion_buffer:');
39
7
  let unprocessedBuffers = [];
40
8
  let missingData = null;
41
9
  const processInput = () => {
42
- let separatorIndex = outputBuffer.indexOf(magicSeparator);
10
+ let separatorIndex = outputBuffer.indexOf(separator);
43
11
  if (separatorIndex === -1) {
44
12
  return;
45
13
  }
46
- separatorIndex += magicSeparator.length;
47
- let messageTypeString = '';
14
+ separatorIndex += separator.length;
15
+ let nonceString = '';
48
16
  let lengthString = '';
49
17
  let statusString = '';
50
- // Each message has the structure with `remotion_buffer:{[message_type_id]}:{[length]}`
18
+ // Each message from Rust is prefixed with `remotion_buffer;{[nonce]}:{[length]}`
51
19
  // Let's read the buffer to extract the nonce, and if the full length is available,
52
20
  // we'll extract the data and pass it to the callback.
53
21
  // eslint-disable-next-line no-constant-condition
@@ -59,7 +27,7 @@ const makeStreaming = (options) => {
59
27
  break;
60
28
  }
61
29
  separatorIndex++;
62
- messageTypeString += String.fromCharCode(nextDigit);
30
+ nonceString += String.fromCharCode(nextDigit);
63
31
  }
64
32
  // eslint-disable-next-line no-constant-condition
65
33
  while (true) {
@@ -90,17 +58,7 @@ const makeStreaming = (options) => {
90
58
  return;
91
59
  }
92
60
  const data = outputBuffer.subarray(separatorIndex + 1, separatorIndex + 1 + Number(lengthString));
93
- const messageType = (0, exports.messageTypeIdToMessage)(messageTypeString);
94
- const payload = {
95
- type: messageType,
96
- payload: exports.formatMap[messageType] === 'json'
97
- ? JSON.parse(data.toString('utf-8'))
98
- : data,
99
- };
100
- options.onMessage({
101
- successType: status === 1 ? 'error' : 'success',
102
- message: payload,
103
- });
61
+ onMessage(status === 1 ? 'error' : 'success', nonceString, data);
104
62
  missingData = null;
105
63
  outputBuffer = outputBuffer.subarray(separatorIndex + Number(lengthString) + 1);
106
64
  processInput();
@@ -108,7 +66,7 @@ const makeStreaming = (options) => {
108
66
  return {
109
67
  addData: (data) => {
110
68
  unprocessedBuffers.push(data);
111
- const separatorIndex = data.indexOf(magicSeparator);
69
+ const separatorIndex = data.indexOf(separator);
112
70
  if (separatorIndex === -1) {
113
71
  if (missingData) {
114
72
  missingData.dataMissing -= data.length;
@@ -120,24 +78,22 @@ const makeStreaming = (options) => {
120
78
  unprocessedBuffers.unshift(outputBuffer);
121
79
  outputBuffer = Buffer.concat(unprocessedBuffers);
122
80
  unprocessedBuffers = [];
81
+ console.log('the unprocessed input is now', new TextDecoder('utf-8').decode(outputBuffer));
123
82
  processInput();
124
83
  },
125
84
  };
126
85
  };
127
86
  exports.makeStreaming = makeStreaming;
128
- const makePayloadMessage = ({ message, status, }) => {
129
- const body = exports.formatMap[message.type] === 'json'
130
- ? Buffer.from(JSON.stringify(message.payload))
131
- : message.payload;
87
+ const makePayloadMessage = (nonce, data, status) => {
132
88
  const concat = Buffer.concat([
133
- magicSeparator,
134
- Buffer.from((0, exports.messageTypeToMessageId)(message.type).toString()),
89
+ Buffer.from('remotion_buffer:'),
90
+ Buffer.from(nonce.toString()),
135
91
  Buffer.from(':'),
136
- Buffer.from(body.length.toString()),
92
+ Buffer.from(data.length.toString()),
137
93
  Buffer.from(':'),
138
94
  Buffer.from(String(status)),
139
95
  Buffer.from(':'),
140
- body,
96
+ data,
141
97
  ]);
142
98
  return concat;
143
99
  };
@@ -5,6 +5,37 @@ const client_lambda_1 = require("@aws-sdk/client-lambda");
5
5
  const streaming_payloads_1 = require("../functions/helpers/streaming-payloads");
6
6
  const aws_clients_1 = require("./aws-clients");
7
7
  const INVALID_JSON_MESSAGE = 'Cannot parse Lambda response as JSON';
8
+ const parseJsonWithErrorSurfacing = (input) => {
9
+ try {
10
+ return JSON.parse(input);
11
+ }
12
+ catch (_a) {
13
+ throw new Error(`${INVALID_JSON_MESSAGE}. Response: ${input}`);
14
+ }
15
+ };
16
+ const parseJson = (input) => {
17
+ var _a;
18
+ let json = parseJsonWithErrorSurfacing(input);
19
+ if ('statusCode' in json) {
20
+ json = parseJsonWithErrorSurfacing(json.body);
21
+ }
22
+ if ('errorMessage' in json) {
23
+ const err = new Error(json.errorMessage);
24
+ err.name = json.errorType;
25
+ err.stack = ((_a = json.trace) !== null && _a !== void 0 ? _a : []).join('\n');
26
+ throw err;
27
+ }
28
+ // This will not happen, it is for narrowing purposes
29
+ if ('statusCode' in json) {
30
+ throw new Error(`Lambda function failed with status code ${json.statusCode}`);
31
+ }
32
+ if (json.type === 'error') {
33
+ const err = new Error(json.message);
34
+ err.stack = json.stack;
35
+ throw err;
36
+ }
37
+ return json;
38
+ };
8
39
  const callLambda = async (options) => {
9
40
  // As of August 2023, Lambda streaming sometimes misses parts of the JSON response.
10
41
  // Handling this for now by applying a retry mechanism.
@@ -61,34 +92,3 @@ const callLambdaWithoutRetry = async ({ functionName, type, payload, region, rec
61
92
  const json = parseJson(responsePayload.trim());
62
93
  return json;
63
94
  };
64
- const parseJsonWithErrorSurfacing = (input) => {
65
- try {
66
- return JSON.parse(input);
67
- }
68
- catch (_a) {
69
- throw new Error(`${INVALID_JSON_MESSAGE}. Response: ${input}`);
70
- }
71
- };
72
- const parseJson = (input) => {
73
- var _a;
74
- let json = parseJsonWithErrorSurfacing(input);
75
- if ('statusCode' in json) {
76
- json = parseJsonWithErrorSurfacing(json.body);
77
- }
78
- if ('errorMessage' in json) {
79
- const err = new Error(json.errorMessage);
80
- err.name = json.errorType;
81
- err.stack = ((_a = json.trace) !== null && _a !== void 0 ? _a : []).join('\n');
82
- throw err;
83
- }
84
- // This will not happen, it is for narrowing purposes
85
- if ('statusCode' in json) {
86
- throw new Error(`Lambda function failed with status code ${json.statusCode}`);
87
- }
88
- if (json.type === 'error') {
89
- const err = new Error(json.message);
90
- err.stack = json.stack;
91
- throw err;
92
- }
93
- return json;
94
- };
@@ -8,6 +8,12 @@ const random_hash_1 = require("./random-hash");
8
8
  const serialize_props_1 = require("./serialize-props");
9
9
  const stream_to_string_1 = require("./stream-to-string");
10
10
  const validate_webhook_1 = require("./validate-webhook");
11
+ const makeKey = (type, hash) => {
12
+ if (type === 'input-props') {
13
+ return (0, constants_1.inputPropsKey)(hash);
14
+ }
15
+ return (0, constants_1.resolvedPropsKey)(hash);
16
+ };
11
17
  const serializeOrThrow = (inputProps, propsType) => {
12
18
  try {
13
19
  const payload = (0, serialize_props_1.serializeJSONWithDate)({
@@ -82,9 +88,3 @@ const decompressInputProps = async ({ serialized, region, bucketName, expectedBu
82
88
  }
83
89
  };
84
90
  exports.decompressInputProps = decompressInputProps;
85
- const makeKey = (type, hash) => {
86
- if (type === 'input-props') {
87
- return (0, constants_1.inputPropsKey)(hash);
88
- }
89
- return (0, constants_1.resolvedPropsKey)(hash);
90
- };
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getS3RenderUrl = exports.getCloudwatchRendererUrl = exports.getCloudwatchMethodUrl = void 0;
4
4
  const encode_aws_url_params_1 = require("./encode-aws-url-params");
5
+ const cloudWatchUrlWithQuery = ({ region, functionNameToUse, query, }) => {
6
+ return `https://${region}.console.aws.amazon.com/cloudwatch/home?region=${region}#logsV2:log-groups/log-group/$252Faws$252Flambda$252F${functionNameToUse}/log-events$3FfilterPattern$3D${(0, encode_aws_url_params_1.encodeAwsUrlParams)(query)}`;
7
+ };
5
8
  const getCloudwatchMethodUrl = ({ region, functionName, renderId, rendererFunctionName, method, }) => {
6
9
  const functionNameToUse = rendererFunctionName !== null && rendererFunctionName !== void 0 ? rendererFunctionName : functionName;
7
10
  const query = `"method=${method},renderId=${renderId}"`;
@@ -14,9 +17,6 @@ const getCloudwatchRendererUrl = ({ region, functionName, renderId, rendererFunc
14
17
  return cloudWatchUrlWithQuery({ region, functionNameToUse, query });
15
18
  };
16
19
  exports.getCloudwatchRendererUrl = getCloudwatchRendererUrl;
17
- const cloudWatchUrlWithQuery = ({ region, functionNameToUse, query, }) => {
18
- return `https://${region}.console.aws.amazon.com/cloudwatch/home?region=${region}#logsV2:log-groups/log-group/$252Faws$252Flambda$252F${functionNameToUse}/log-events$3FfilterPattern$3D${(0, encode_aws_url_params_1.encodeAwsUrlParams)(query)}`;
19
- };
20
20
  const getS3RenderUrl = ({ renderId, region, bucketName, }) => {
21
21
  return `https://s3.console.aws.amazon.com/s3/buckets/${bucketName}?region=${region}&prefix=renders/${renderId}/`;
22
22
  };
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import https from 'https';
2
4
  import http from 'node:http';
3
5
  import type { EnhancedErrorInfo } from '../functions/helpers/write-lambda-error';
@@ -47,6 +47,10 @@ function calculateSignature(payload, secret) {
47
47
  return signature;
48
48
  }
49
49
  exports.calculateSignature = calculateSignature;
50
+ exports.mockableHttpClients = {
51
+ http: node_http_1.default.request,
52
+ https: https_1.default.request,
53
+ };
50
54
  const getWebhookClient = (url) => {
51
55
  if (url.startsWith('https://')) {
52
56
  return exports.mockableHttpClients.https;
@@ -56,10 +60,6 @@ const getWebhookClient = (url) => {
56
60
  }
57
61
  throw new Error('Can only request URLs starting with http:// or https://');
58
62
  };
59
- exports.mockableHttpClients = {
60
- http: node_http_1.default.request,
61
- https: https_1.default.request,
62
- };
63
63
  function invokeWebhookRaw({ payload, secret, url, }) {
64
64
  const jsonPayload = JSON.stringify(payload);
65
65
  return new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/lambda",
3
- "version": "4.0.46",
3
+ "version": "4.0.47",
4
4
  "description": "Distributed renderer for Remotion based on AWS Lambda",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -26,13 +26,13 @@
26
26
  "aws-policies": "^1.0.1",
27
27
  "mime-types": "2.1.34",
28
28
  "zod": "3.22.3",
29
- "@remotion/bundler": "4.0.46",
30
- "remotion": "4.0.46",
31
- "@remotion/renderer": "4.0.46",
32
- "@remotion/cli": "4.0.46"
29
+ "@remotion/bundler": "4.0.47",
30
+ "@remotion/renderer": "4.0.47",
31
+ "@remotion/cli": "4.0.47",
32
+ "remotion": "4.0.47"
33
33
  },
34
34
  "devDependencies": {
35
- "@jonny/eslint-config": "3.0.266",
35
+ "@jonny/eslint-config": "3.0.276",
36
36
  "@types/mime-types": "2.1.1",
37
37
  "@types/minimist": "1.2.2",
38
38
  "@types/node": "18.14.6",
@@ -43,11 +43,11 @@
43
43
  "ts-node": "^10.8.0",
44
44
  "vitest": "0.31.1",
45
45
  "zip-lib": "^0.7.2",
46
- "@remotion/bundler": "4.0.46",
47
- "@remotion/compositor-linux-arm64-gnu": "4.0.46"
46
+ "@remotion/bundler": "4.0.47",
47
+ "@remotion/compositor-linux-arm64-gnu": "4.0.47"
48
48
  },
49
49
  "peerDependencies": {
50
- "@remotion/bundler": "4.0.46"
50
+ "@remotion/bundler": "4.0.47"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"
Binary file