@remotion/renderer 3.0.25 → 3.0.26

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.
@@ -1,20 +1,33 @@
1
1
  import type { TAsset } from 'remotion';
2
2
  export declare type RenderMediaOnDownload = (src: string) => ((progress: {
3
- percent: number;
3
+ percent: number | null;
4
+ downloaded: number;
5
+ totalSize: number | null;
4
6
  }) => void) | undefined | void;
5
- export declare const waitForAssetToBeDownloaded: (src: string, to: string) => Promise<void>;
7
+ export declare const waitForAssetToBeDownloaded: ({ src, downloadDir, }: {
8
+ src: string;
9
+ downloadDir: string;
10
+ }) => Promise<string>;
11
+ export declare const downloadAsset: ({ src, onDownload, downloadDir, }: {
12
+ src: string;
13
+ onDownload: RenderMediaOnDownload;
14
+ downloadDir: string;
15
+ }) => Promise<string>;
6
16
  export declare const markAllAssetsAsDownloaded: () => void;
7
- export declare const getSanitizedFilenameForAssetUrl: ({ src, downloadDir, }: {
17
+ export declare const getFilename: ({ contentDisposition, src, }: {
18
+ src: string;
19
+ contentDisposition: string | null;
20
+ }) => {
21
+ pathname: string;
22
+ search: string;
23
+ };
24
+ export declare const getSanitizedFilenameForAssetUrl: ({ src, downloadDir, contentDisposition, }: {
8
25
  src: string;
9
26
  downloadDir: string;
27
+ contentDisposition: string | null;
10
28
  }) => string;
11
29
  export declare const downloadAndMapAssetsToFileUrl: ({ asset, downloadDir, onDownload, }: {
12
30
  asset: TAsset;
13
31
  downloadDir: string;
14
32
  onDownload: RenderMediaOnDownload;
15
33
  }) => Promise<TAsset>;
16
- export declare const startDownloadForSrc: ({ src, downloadDir, onDownload, }: {
17
- src: string;
18
- downloadDir: string;
19
- onDownload: RenderMediaOnDownload;
20
- }) => Promise<string>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.startDownloadForSrc = exports.downloadAndMapAssetsToFileUrl = exports.getSanitizedFilenameForAssetUrl = exports.markAllAssetsAsDownloaded = exports.waitForAssetToBeDownloaded = void 0;
6
+ exports.downloadAndMapAssetsToFileUrl = exports.getSanitizedFilenameForAssetUrl = exports.getFilename = exports.markAllAssetsAsDownloaded = exports.downloadAsset = exports.waitForAssetToBeDownloaded = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const remotion_1 = require("remotion");
@@ -13,38 +13,41 @@ const sanitize_filepath_1 = require("./sanitize-filepath");
13
13
  const isDownloadingMap = {};
14
14
  const hasBeenDownloadedMap = {};
15
15
  const listeners = {};
16
- const waitForAssetToBeDownloaded = (src, to) => {
17
- var _a;
18
- if ((_a = hasBeenDownloadedMap[src]) === null || _a === void 0 ? void 0 : _a[to]) {
19
- return Promise.resolve();
16
+ const waitForAssetToBeDownloaded = ({ src, downloadDir, }) => {
17
+ var _a, _b;
18
+ if ((_a = hasBeenDownloadedMap[src]) === null || _a === void 0 ? void 0 : _a[downloadDir]) {
19
+ return Promise.resolve((_b = hasBeenDownloadedMap[src]) === null || _b === void 0 ? void 0 : _b[downloadDir]);
20
20
  }
21
21
  if (!listeners[src]) {
22
22
  listeners[src] = {};
23
23
  }
24
- if (!listeners[src][to]) {
25
- listeners[src][to] = [];
24
+ if (!listeners[src][downloadDir]) {
25
+ listeners[src][downloadDir] = [];
26
26
  }
27
27
  return new Promise((resolve) => {
28
- listeners[src][to].push(() => resolve());
28
+ listeners[src][downloadDir].push(() => {
29
+ var _a;
30
+ resolve((_a = hasBeenDownloadedMap[src]) === null || _a === void 0 ? void 0 : _a[downloadDir]);
31
+ });
29
32
  });
30
33
  };
31
34
  exports.waitForAssetToBeDownloaded = waitForAssetToBeDownloaded;
32
- const notifyAssetIsDownloaded = (src, to) => {
35
+ const notifyAssetIsDownloaded = ({ src, downloadDir, to, }) => {
33
36
  if (!listeners[src]) {
34
37
  listeners[src] = {};
35
38
  }
36
- if (!listeners[src][to]) {
37
- listeners[src][to] = [];
39
+ if (!listeners[src][downloadDir]) {
40
+ listeners[src][downloadDir] = [];
38
41
  }
39
- listeners[src][to].forEach((fn) => fn());
42
+ listeners[src][downloadDir].forEach((fn) => fn());
40
43
  if (!isDownloadingMap[src]) {
41
44
  isDownloadingMap[src] = {};
42
45
  }
43
- isDownloadingMap[src][to] = false;
46
+ isDownloadingMap[src][downloadDir] = true;
44
47
  if (!hasBeenDownloadedMap[src]) {
45
48
  hasBeenDownloadedMap[src] = {};
46
49
  }
47
- hasBeenDownloadedMap[src][to] = true;
50
+ hasBeenDownloadedMap[src][downloadDir] = to;
48
51
  };
49
52
  const validateMimeType = (mimeType, src) => {
50
53
  if (!mimeType.includes('/')) {
@@ -85,21 +88,29 @@ function validateBufferEncoding(potentialEncoding, dataUrl) {
85
88
  throw new TypeError(errMessage);
86
89
  }
87
90
  }
88
- const downloadAsset = async (src, to, onDownload) => {
89
- var _a, _b;
90
- if ((_a = hasBeenDownloadedMap[src]) === null || _a === void 0 ? void 0 : _a[to]) {
91
- return;
91
+ const downloadAsset = async ({ src, onDownload, downloadDir, }) => {
92
+ var _a, _b, _c;
93
+ if (remotion_1.Internals.AssetCompression.isAssetCompressed(src)) {
94
+ return src;
95
+ }
96
+ if ((_a = hasBeenDownloadedMap[src]) === null || _a === void 0 ? void 0 : _a[downloadDir]) {
97
+ return (_b = hasBeenDownloadedMap[src]) === null || _b === void 0 ? void 0 : _b[downloadDir];
92
98
  }
93
- if ((_b = isDownloadingMap[src]) === null || _b === void 0 ? void 0 : _b[to]) {
94
- return (0, exports.waitForAssetToBeDownloaded)(src, to);
99
+ if ((_c = isDownloadingMap[src]) === null || _c === void 0 ? void 0 : _c[downloadDir]) {
100
+ return (0, exports.waitForAssetToBeDownloaded)({ src, downloadDir });
95
101
  }
96
102
  if (!isDownloadingMap[src]) {
97
103
  isDownloadingMap[src] = {};
98
104
  }
99
- isDownloadingMap[src][to] = true;
105
+ isDownloadingMap[src][downloadDir] = true;
100
106
  const onProgress = onDownload(src);
101
- (0, ensure_output_directory_1.ensureOutputDirectory)(to);
102
107
  if (src.startsWith('data:')) {
108
+ const output = (0, exports.getSanitizedFilenameForAssetUrl)({
109
+ contentDisposition: null,
110
+ downloadDir,
111
+ src,
112
+ });
113
+ (0, ensure_output_directory_1.ensureOutputDirectory)(output);
103
114
  const [assetDetails, assetData] = src.substring('data:'.length).split(',');
104
115
  if (!assetDetails.includes(';')) {
105
116
  const errMessage = [
@@ -114,17 +125,21 @@ const downloadAsset = async (src, to, onDownload) => {
114
125
  validateMimeType(mimeType, src);
115
126
  validateBufferEncoding(encoding, src);
116
127
  const buff = Buffer.from(assetData, encoding);
117
- await fs_1.default.promises.writeFile(to, buff);
118
- notifyAssetIsDownloaded(src, to);
119
- return;
128
+ await fs_1.default.promises.writeFile(output, buff);
129
+ notifyAssetIsDownloaded({ src, downloadDir, to: output });
130
+ return output;
120
131
  }
121
- await (0, download_file_1.downloadFile)(src, to, ({ progress }) => {
122
- onProgress === null || onProgress === void 0 ? void 0 : onProgress({
123
- percent: progress,
124
- });
132
+ const { to } = await (0, download_file_1.downloadFile)({
133
+ url: src,
134
+ onProgress: (progress) => {
135
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(progress);
136
+ },
137
+ to: (contentDisposition) => (0, exports.getSanitizedFilenameForAssetUrl)({ contentDisposition, downloadDir, src }),
125
138
  });
126
- notifyAssetIsDownloaded(src, to);
139
+ notifyAssetIsDownloaded({ src, downloadDir, to });
140
+ return to;
127
141
  };
142
+ exports.downloadAsset = downloadAsset;
128
143
  const markAllAssetsAsDownloaded = () => {
129
144
  Object.keys(hasBeenDownloadedMap).forEach((key) => {
130
145
  delete hasBeenDownloadedMap[key];
@@ -134,21 +149,40 @@ const markAllAssetsAsDownloaded = () => {
134
149
  });
135
150
  };
136
151
  exports.markAllAssetsAsDownloaded = markAllAssetsAsDownloaded;
137
- const getSanitizedFilenameForAssetUrl = ({ src, downloadDir, }) => {
152
+ const getFilename = ({ contentDisposition, src, }) => {
153
+ const filenameProbe = 'filename=';
154
+ if (contentDisposition === null || contentDisposition === void 0 ? void 0 : contentDisposition.includes(filenameProbe)) {
155
+ const start = contentDisposition.indexOf(filenameProbe);
156
+ const onlyFromFileName = contentDisposition.substring(start + filenameProbe.length);
157
+ const hasSemi = onlyFromFileName.indexOf(';');
158
+ if (hasSemi === -1) {
159
+ return { pathname: onlyFromFileName.trim(), search: '' };
160
+ }
161
+ return {
162
+ search: '',
163
+ pathname: onlyFromFileName.substring(0, hasSemi).trim(),
164
+ };
165
+ }
166
+ const { pathname, search } = new URL(src);
167
+ return { pathname, search };
168
+ };
169
+ exports.getFilename = getFilename;
170
+ const getSanitizedFilenameForAssetUrl = ({ src, downloadDir, contentDisposition, }) => {
138
171
  if (remotion_1.Internals.AssetCompression.isAssetCompressed(src)) {
139
172
  return src;
140
173
  }
141
- const { pathname, search } = new URL(src);
174
+ const { pathname, search } = (0, exports.getFilename)({ contentDisposition, src });
142
175
  const split = pathname.split('.');
143
176
  const fileExtension = split.length > 1 && split[split.length - 1]
144
177
  ? `.${split[split.length - 1]}`
145
178
  : '';
146
179
  const hashedFileName = String((0, remotion_1.random)(`${pathname}${search}`)).replace('0.', '');
147
- return path_1.default.join(downloadDir, (0, sanitize_filepath_1.sanitizeFilePath)(hashedFileName + fileExtension));
180
+ const filename = hashedFileName + fileExtension;
181
+ return path_1.default.join(downloadDir, (0, sanitize_filepath_1.sanitizeFilePath)(filename));
148
182
  };
149
183
  exports.getSanitizedFilenameForAssetUrl = getSanitizedFilenameForAssetUrl;
150
184
  const downloadAndMapAssetsToFileUrl = async ({ asset, downloadDir, onDownload, }) => {
151
- const newSrc = await (0, exports.startDownloadForSrc)({
185
+ const newSrc = await (0, exports.downloadAsset)({
152
186
  src: asset.src,
153
187
  downloadDir,
154
188
  onDownload,
@@ -159,11 +193,3 @@ const downloadAndMapAssetsToFileUrl = async ({ asset, downloadDir, onDownload, }
159
193
  };
160
194
  };
161
195
  exports.downloadAndMapAssetsToFileUrl = downloadAndMapAssetsToFileUrl;
162
- const startDownloadForSrc = async ({ src, downloadDir, onDownload, }) => {
163
- const newSrc = (0, exports.getSanitizedFilenameForAssetUrl)({ downloadDir, src });
164
- if (!remotion_1.Internals.AssetCompression.isAssetCompressed(newSrc)) {
165
- await downloadAsset(src, newSrc, onDownload);
166
- }
167
- return newSrc;
168
- };
169
- exports.startDownloadForSrc = startDownloadForSrc;
@@ -1,7 +1,12 @@
1
- export declare const downloadFile: (url: string, to: string, onProgress: ((progress: {
2
- progress: number;
3
- downloaded: number;
4
- totalSize: number;
5
- }) => void) | undefined) => Promise<{
1
+ export declare const downloadFile: ({ onProgress, url, to: toFn, }: {
2
+ url: string;
3
+ to: (contentDisposition: string | null) => string;
4
+ onProgress: ((progress: {
5
+ percent: number | null;
6
+ downloaded: number;
7
+ totalSize: number | null;
8
+ }) => void) | undefined;
9
+ }) => Promise<{
6
10
  sizeInBytes: number;
11
+ to: string;
7
12
  }>;
@@ -2,25 +2,38 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.downloadFile = void 0;
4
4
  const fs_1 = require("fs");
5
+ const ensure_output_directory_1 = require("../ensure-output-directory");
5
6
  const read_file_1 = require("./read-file");
6
- const downloadFile = (url, to, onProgress) => {
7
+ const downloadFile = ({ onProgress, url, to: toFn, }) => {
7
8
  return new Promise((resolve, reject) => {
8
9
  (0, read_file_1.readFile)(url)
9
10
  .then((res) => {
10
- const totalSize = Number(res.headers['content-length']);
11
+ var _a;
12
+ const contentDisposition = (_a = res.headers['content-disposition']) !== null && _a !== void 0 ? _a : null;
13
+ const to = toFn(contentDisposition);
14
+ (0, ensure_output_directory_1.ensureOutputDirectory)(to);
15
+ const sizeHeader = res.headers['content-length'];
16
+ const totalSize = typeof sizeHeader === 'undefined' ? null : Number(sizeHeader);
11
17
  const writeStream = (0, fs_1.createWriteStream)(to);
18
+ let downloaded = 0;
12
19
  // Listen to 'close' event instead of more
13
20
  // concise method to avoid this problem
14
21
  // https://github.com/remotion-dev/remotion/issues/384#issuecomment-844398183
15
- writeStream.on('close', () => resolve({ sizeInBytes: totalSize }));
22
+ writeStream.on('close', () => {
23
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
24
+ downloaded,
25
+ percent: 1,
26
+ totalSize: downloaded,
27
+ });
28
+ return resolve({ sizeInBytes: downloaded, to });
29
+ });
16
30
  writeStream.on('error', (err) => reject(err));
17
- let downloaded = 0;
18
31
  res.pipe(writeStream).on('error', (err) => reject(err));
19
32
  res.on('data', (d) => {
20
33
  downloaded += d.length;
21
34
  onProgress === null || onProgress === void 0 ? void 0 : onProgress({
22
35
  downloaded,
23
- progress: downloaded / totalSize,
36
+ percent: totalSize === null ? null : downloaded / totalSize,
24
37
  totalSize,
25
38
  });
26
39
  });
@@ -4,9 +4,8 @@ declare type FfmpegVolumeExpression = {
4
4
  eval: FfmpegEval;
5
5
  value: string;
6
6
  };
7
- export declare const ffmpegVolumeExpression: ({ volume, startInVideo, fps, trimLeft, }: {
7
+ export declare const ffmpegVolumeExpression: ({ volume, fps, trimLeft, }: {
8
8
  volume: AssetVolume;
9
- startInVideo: number;
10
9
  trimLeft: number;
11
10
  fps: number;
12
11
  }) => FfmpegVolumeExpression;
@@ -43,7 +43,7 @@ const ffmpegBuildVolumeExpression = (arr, delay, fps) => {
43
43
  const [volume, frames] = first;
44
44
  return ffmpegIfOrElse(ffmpegIsOneOfFrames({ frames, trimLeft: delay, fps }), String(volume), ffmpegBuildVolumeExpression(rest, delay, fps));
45
45
  };
46
- const ffmpegVolumeExpression = ({ volume, startInVideo, fps, trimLeft, }) => {
46
+ const ffmpegVolumeExpression = ({ volume, fps, trimLeft, }) => {
47
47
  // If it's a static volume, we return it and tell
48
48
  // FFMPEG it only has to evaluate it once
49
49
  if (typeof volume === 'number') {
@@ -55,7 +55,6 @@ const ffmpegVolumeExpression = ({ volume, startInVideo, fps, trimLeft, }) => {
55
55
  if ([...new Set(volume)].length === 1) {
56
56
  return (0, exports.ffmpegVolumeExpression)({
57
57
  volume: volume[0],
58
- startInVideo,
59
58
  fps,
60
59
  trimLeft,
61
60
  });
@@ -76,7 +75,7 @@ const ffmpegVolumeExpression = ({ volume, startInVideo, fps, trimLeft, }) => {
76
75
  if (!volumeMap[actualVolume]) {
77
76
  volumeMap[actualVolume] = [];
78
77
  }
79
- volumeMap[actualVolume].push(frame + startInVideo);
78
+ volumeMap[actualVolume].push(frame);
80
79
  });
81
80
  // Sort the map so that the most common volume is last
82
81
  // this is going to be the else statement so the expression is short
@@ -22,6 +22,11 @@ declare type BrowserCloseCallback = () => Promise<void> | void;
22
22
  interface WaitForTargetOptions {
23
23
  timeout?: number;
24
24
  }
25
+ export declare const enum BrowserEmittedEvents {
26
+ TargetChanged = "targetchanged",
27
+ TargetCreated = "targetcreated",
28
+ Closed = "closed"
29
+ }
25
30
  export declare class Browser extends EventEmitter {
26
31
  #private;
27
32
  static _create({ connection, contextIds, defaultViewport, closeCallback, }: {
@@ -111,7 +111,7 @@ class Browser extends EventEmitter_1.EventEmitter {
111
111
  return await targetPromise;
112
112
  }
113
113
  this.targets().forEach(check);
114
- return await (0, util_1.waitWithTimeout)(targetPromise, 'target', timeout);
114
+ return await (0, util_1.waitWithTimeout)(targetPromise, 'target', timeout, this);
115
115
  }
116
116
  finally {
117
117
  this.off("targetcreated" /* BrowserEmittedEvents.TargetCreated */, check);
@@ -136,6 +136,7 @@ class Browser extends EventEmitter_1.EventEmitter {
136
136
  async close() {
137
137
  await __classPrivateFieldGet(this, _Browser_closeCallback, "f").call(null);
138
138
  this.disconnect();
139
+ this.emit("closed" /* BrowserEmittedEvents.Closed */);
139
140
  }
140
141
  disconnect() {
141
142
  __classPrivateFieldGet(this, _Browser_connection, "f").dispose();
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import type { Browser } from './Browser';
16
17
  import type { EvaluateFn, EvaluateFnReturnType, EvaluateHandleFn, SerializableOrJSHandle, UnwrapPromiseLike } from './EvalTypes';
17
18
  import type { ExecutionContext } from './ExecutionContext';
18
19
  import type { Frame } from './FrameManager';
@@ -29,7 +30,7 @@ export declare class DOMWorld {
29
30
  executionContext(): Promise<ExecutionContext>;
30
31
  evaluateHandle<HandlerType extends JSHandle = JSHandle>(pageFunction: EvaluateHandleFn, ...args: SerializableOrJSHandle[]): Promise<HandlerType>;
31
32
  evaluate<T extends EvaluateFn>(pageFunction: T, ...args: SerializableOrJSHandle[]): Promise<UnwrapPromiseLike<EvaluateFnReturnType<T>>>;
32
- waitForFunction(pageFunction: Function | string, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
33
+ waitForFunction(browser: Browser, pageFunction: Function | string, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
33
34
  title(): Promise<string>;
34
35
  }
35
36
  interface WaitTaskOptions {
@@ -37,12 +38,14 @@ interface WaitTaskOptions {
37
38
  predicateBody: Function | string;
38
39
  title: string;
39
40
  timeout: number;
41
+ browser: Browser;
40
42
  args: SerializableOrJSHandle[];
41
43
  }
42
44
  declare class WaitTask {
43
45
  #private;
44
46
  promise: Promise<JSHandle>;
45
47
  constructor(options: WaitTaskOptions);
48
+ onBrowserClose: () => void;
46
49
  terminate(error: Error): void;
47
50
  rerun(): Promise<void>;
48
51
  }
@@ -25,7 +25,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
25
25
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
26
26
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
27
27
  };
28
- var _DOMWorld_frame, _DOMWorld_timeoutSettings, _DOMWorld_contextPromise, _DOMWorld_contextResolveCallback, _DOMWorld_detached, _DOMWorld_waitTasks, _WaitTask_instances, _WaitTask_domWorld, _WaitTask_timeout, _WaitTask_predicateBody, _WaitTask_args, _WaitTask_runCount, _WaitTask_resolve, _WaitTask_reject, _WaitTask_timeoutTimer, _WaitTask_terminated, _WaitTask_cleanup;
28
+ var _DOMWorld_frame, _DOMWorld_timeoutSettings, _DOMWorld_contextPromise, _DOMWorld_contextResolveCallback, _DOMWorld_detached, _DOMWorld_waitTasks, _WaitTask_instances, _WaitTask_domWorld, _WaitTask_timeout, _WaitTask_predicateBody, _WaitTask_args, _WaitTask_runCount, _WaitTask_resolve, _WaitTask_reject, _WaitTask_timeoutTimer, _WaitTask_terminated, _WaitTask_browser, _WaitTask_cleanup;
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.DOMWorld = void 0;
31
31
  const assert_1 = require("./assert");
@@ -93,7 +93,7 @@ class DOMWorld {
93
93
  const context = await this.executionContext();
94
94
  return context.evaluate(pageFunction, ...args);
95
95
  }
96
- waitForFunction(pageFunction, ...args) {
96
+ waitForFunction(browser, pageFunction, ...args) {
97
97
  const timeout = __classPrivateFieldGet(this, _DOMWorld_timeoutSettings, "f").timeout();
98
98
  const waitTaskOptions = {
99
99
  domWorld: this,
@@ -101,6 +101,7 @@ class DOMWorld {
101
101
  title: 'function',
102
102
  timeout,
103
103
  args,
104
+ browser,
104
105
  };
105
106
  const waitTask = new WaitTask(waitTaskOptions);
106
107
  return waitTask.promise;
@@ -126,6 +127,10 @@ class WaitTask {
126
127
  _WaitTask_reject.set(this, noop);
127
128
  _WaitTask_timeoutTimer.set(this, void 0);
128
129
  _WaitTask_terminated.set(this, false);
130
+ _WaitTask_browser.set(this, void 0);
131
+ this.onBrowserClose = () => {
132
+ return this.terminate(new Error('Browser was closed'));
133
+ };
129
134
  function getPredicateBody(predicateBody) {
130
135
  if ((0, util_1.isString)(predicateBody)) {
131
136
  return `return (${predicateBody});`;
@@ -150,6 +155,8 @@ class WaitTask {
150
155
  return this.terminate(timeoutError);
151
156
  }, options.timeout), "f");
152
157
  }
158
+ __classPrivateFieldSet(this, _WaitTask_browser, options.browser, "f");
159
+ __classPrivateFieldGet(this, _WaitTask_browser, "f").on("closed" /* BrowserEmittedEvents.Closed */, this.onBrowserClose);
153
160
  this.rerun();
154
161
  }
155
162
  terminate(error) {
@@ -230,10 +237,11 @@ class WaitTask {
230
237
  __classPrivateFieldGet(this, _WaitTask_instances, "m", _WaitTask_cleanup).call(this);
231
238
  }
232
239
  }
233
- _WaitTask_domWorld = new WeakMap(), _WaitTask_timeout = new WeakMap(), _WaitTask_predicateBody = new WeakMap(), _WaitTask_args = new WeakMap(), _WaitTask_runCount = new WeakMap(), _WaitTask_resolve = new WeakMap(), _WaitTask_reject = new WeakMap(), _WaitTask_timeoutTimer = new WeakMap(), _WaitTask_terminated = new WeakMap(), _WaitTask_instances = new WeakSet(), _WaitTask_cleanup = function _WaitTask_cleanup() {
240
+ _WaitTask_domWorld = new WeakMap(), _WaitTask_timeout = new WeakMap(), _WaitTask_predicateBody = new WeakMap(), _WaitTask_args = new WeakMap(), _WaitTask_runCount = new WeakMap(), _WaitTask_resolve = new WeakMap(), _WaitTask_reject = new WeakMap(), _WaitTask_timeoutTimer = new WeakMap(), _WaitTask_terminated = new WeakMap(), _WaitTask_browser = new WeakMap(), _WaitTask_instances = new WeakSet(), _WaitTask_cleanup = function _WaitTask_cleanup() {
234
241
  if (__classPrivateFieldGet(this, _WaitTask_timeoutTimer, "f") !== undefined) {
235
242
  clearTimeout(__classPrivateFieldGet(this, _WaitTask_timeoutTimer, "f"));
236
243
  }
244
+ __classPrivateFieldGet(this, _WaitTask_browser, "f").off("closed" /* BrowserEmittedEvents.Closed */, this.onBrowserClose);
237
245
  __classPrivateFieldGet(this, _WaitTask_domWorld, "f")._waitTasks.delete(this);
238
246
  };
239
247
  function waitForPredicatePageFunction(predicateBody, timeout, ...args) {
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import type { Protocol } from 'devtools-protocol';
17
+ import type { Browser } from './Browser';
17
18
  import type { CDPSession } from './Connection';
18
19
  import { DOMWorld } from './DOMWorld';
19
20
  import type { EvaluateFn, EvaluateFnReturnType, EvaluateHandleFn, SerializableOrJSHandle, UnwrapPromiseLike } from './EvalTypes';
@@ -82,7 +83,7 @@ export declare class Frame {
82
83
  evaluate<T extends EvaluateFn>(pageFunction: T, ...args: SerializableOrJSHandle[]): Promise<UnwrapPromiseLike<EvaluateFnReturnType<T>>>;
83
84
  url(): string;
84
85
  childFrames(): Frame[];
85
- waitForFunction(pageFunction: Function | string, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
86
+ waitForFunction(browser: Browser, pageFunction: Function | string, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
86
87
  _navigated(framePayload: Protocol.Page.Frame): void;
87
88
  _navigatedWithinDocument(url: string): void;
88
89
  _onLifecycleEvent(loaderId: string, name: string): void;
@@ -460,8 +460,8 @@ class Frame {
460
460
  childFrames() {
461
461
  return Array.from(this._childFrames);
462
462
  }
463
- waitForFunction(pageFunction, ...args) {
464
- return this._mainWorld.waitForFunction(pageFunction, ...args);
463
+ waitForFunction(browser, pageFunction, ...args) {
464
+ return this._mainWorld.waitForFunction(browser, pageFunction, ...args);
465
465
  }
466
466
  _navigated(framePayload) {
467
467
  this._name = framePayload.name;
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import type { Browser } from './Browser';
16
17
  import type { CDPSession } from './Connection';
17
18
  import { ConsoleMessage } from './ConsoleMessage';
18
19
  import type { EvaluateFn, EvaluateFnReturnType, EvaluateHandleFn, SerializableOrJSHandle, UnwrapPromiseLike } from './EvalTypes';
@@ -32,9 +33,10 @@ interface PageEventObject {
32
33
  }
33
34
  export declare class Page extends EventEmitter {
34
35
  #private;
35
- static _create(client: CDPSession, target: Target, defaultViewport: Viewport): Promise<Page>;
36
+ static _create(client: CDPSession, target: Target, defaultViewport: Viewport, browser: Browser): Promise<Page>;
37
+ browser: Browser;
36
38
  screenshotTaskQueue: TaskQueue;
37
- constructor(client: CDPSession, target: Target);
39
+ constructor(client: CDPSession, target: Target, browser: Browser);
38
40
  /**
39
41
  * Listen to page events.
40
42
  */
@@ -67,6 +69,6 @@ export declare class Page extends EventEmitter {
67
69
  runBeforeUnload?: boolean;
68
70
  }): Promise<void>;
69
71
  isClosed(): boolean;
70
- waitForFunction(pageFunction: Function | string, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
72
+ waitForFunction(browser: Browser, pageFunction: Function | string, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
71
73
  }
72
74
  export {};
@@ -37,7 +37,7 @@ const TaskQueue_1 = require("./TaskQueue");
37
37
  const TimeoutSettings_1 = require("./TimeoutSettings");
38
38
  const util_1 = require("./util");
39
39
  class Page extends EventEmitter_1.EventEmitter {
40
- constructor(client, target) {
40
+ constructor(client, target, browser) {
41
41
  super();
42
42
  _Page_instances.add(this);
43
43
  _Page_closed.set(this, false);
@@ -50,6 +50,7 @@ class Page extends EventEmitter_1.EventEmitter {
50
50
  __classPrivateFieldSet(this, _Page_target, target, "f");
51
51
  __classPrivateFieldSet(this, _Page_frameManager, new FrameManager_1.FrameManager(client, this, __classPrivateFieldGet(this, _Page_timeoutSettings, "f")), "f");
52
52
  this.screenshotTaskQueue = new TaskQueue_1.TaskQueue();
53
+ this.browser = browser;
53
54
  client.on('Target.attachedToTarget', (event) => {
54
55
  switch (event.targetInfo.type) {
55
56
  case 'iframe':
@@ -83,8 +84,8 @@ class Page extends EventEmitter_1.EventEmitter {
83
84
  return __classPrivateFieldGet(this, _Page_instances, "m", _Page_onLogEntryAdded).call(this, event);
84
85
  });
85
86
  }
86
- static async _create(client, target, defaultViewport) {
87
- const page = new Page(client, target);
87
+ static async _create(client, target, defaultViewport, browser) {
88
+ const page = new Page(client, target, browser);
88
89
  await __classPrivateFieldGet(page, _Page_instances, "m", _Page_initialize).call(page);
89
90
  await page.setViewport(defaultViewport);
90
91
  return page;
@@ -180,8 +181,8 @@ class Page extends EventEmitter_1.EventEmitter {
180
181
  isClosed() {
181
182
  return __classPrivateFieldGet(this, _Page_closed, "f");
182
183
  }
183
- waitForFunction(pageFunction, ...args) {
184
- return this.mainFrame().waitForFunction(pageFunction, ...args);
184
+ waitForFunction(browser, pageFunction, ...args) {
185
+ return this.mainFrame().waitForFunction(browser, pageFunction, ...args);
185
186
  }
186
187
  }
187
188
  exports.Page = Page;
@@ -84,7 +84,7 @@ class Target {
84
84
  if (isPagetTarget(__classPrivateFieldGet(this, _Target_targetInfo, "f")) && !__classPrivateFieldGet(this, _Target_pagePromise, "f")) {
85
85
  __classPrivateFieldSet(this, _Target_pagePromise, __classPrivateFieldGet(this, _Target_sessionFactory, "f").call(this).then((client) => {
86
86
  var _a;
87
- return Page_1.Page._create(client, this, (_a = __classPrivateFieldGet(this, _Target_defaultViewport, "f")) !== null && _a !== void 0 ? _a : null);
87
+ return Page_1.Page._create(client, this, (_a = __classPrivateFieldGet(this, _Target_defaultViewport, "f")) !== null && _a !== void 0 ? _a : null, this.browser());
88
88
  }), "f");
89
89
  }
90
90
  return (_a = (await __classPrivateFieldGet(this, _Target_pagePromise, "f"))) !== null && _a !== void 0 ? _a : null;
@@ -15,6 +15,7 @@
15
15
  */
16
16
  /// <reference types="node" />
17
17
  import type { Protocol } from 'devtools-protocol';
18
+ import type { Browser } from './Browser';
18
19
  import type { CDPSession } from './Connection';
19
20
  import type { CommonEventEmitter } from './EventEmitter';
20
21
  export declare function getExceptionMessage(exceptionDetails: Protocol.Runtime.ExceptionDetails): string;
@@ -36,7 +37,7 @@ export declare function evaluationString(fun: Function | string, ...args: unknow
36
37
  export declare function pageBindingDeliverResultString(name: string, seq: number, result: unknown): string;
37
38
  export declare function pageBindingDeliverErrorString(name: string, seq: number, message: string, stack?: string): string;
38
39
  export declare function pageBindingDeliverErrorValueString(name: string, seq: number, value: unknown): string;
39
- export declare function waitWithTimeout<T>(promise: Promise<T>, taskName: string, timeout: number): Promise<T>;
40
+ export declare function waitWithTimeout<T>(promise: Promise<T>, taskName: string, timeout: number, browser: Browser): Promise<T>;
40
41
  interface ErrorLike extends Error {
41
42
  name: string;
42
43
  message: string;
@@ -128,7 +128,7 @@ function pageBindingDeliverErrorValueString(name, seq, value) {
128
128
  return evaluationString(deliverErrorValue, name, seq, value);
129
129
  }
130
130
  exports.pageBindingDeliverErrorValueString = pageBindingDeliverErrorValueString;
131
- async function waitWithTimeout(promise, taskName, timeout) {
131
+ async function waitWithTimeout(promise, taskName, timeout, browser) {
132
132
  let reject;
133
133
  const timeoutError = new Errors_1.TimeoutError(`waiting for ${taskName} failed: timeout ${timeout}ms exceeded`);
134
134
  const timeoutPromise = new Promise((_res, rej) => {
@@ -141,7 +141,15 @@ async function waitWithTimeout(promise, taskName, timeout) {
141
141
  }, timeout);
142
142
  }
143
143
  try {
144
- return await Promise.race([promise, timeoutPromise]);
144
+ return await Promise.race([
145
+ new Promise((_, rej) => {
146
+ browser.once("closed" /* BrowserEmittedEvents.Closed */, () => {
147
+ return rej();
148
+ });
149
+ }),
150
+ promise,
151
+ timeoutPromise,
152
+ ]);
145
153
  }
146
154
  finally {
147
155
  if (timeoutTimer) {
@@ -40,7 +40,7 @@ const innerGetCompositions = async (serveUrl, page, config, proxyPort) => {
40
40
  frame: null,
41
41
  args: [],
42
42
  });
43
- await page.waitForFunction('window.ready === true');
43
+ await page.waitForFunction(page.browser, 'window.ready === true');
44
44
  const result = await (0, puppeteer_evaluate_1.puppeteerEvaluateWithCatch)({
45
45
  pageFunction: () => {
46
46
  return window.getStaticCompositions();
package/dist/get-port.js CHANGED
@@ -14,7 +14,7 @@ const getAvailablePort = (portToTry) => new Promise((resolve) => {
14
14
  status = 'unavailable';
15
15
  socket.destroy();
16
16
  });
17
- socket.setTimeout(1000);
17
+ socket.setTimeout(3000);
18
18
  socket.on('timeout', () => {
19
19
  status = 'unavailable';
20
20
  socket.destroy();
@@ -26,15 +26,9 @@ const getAvailablePort = (portToTry) => new Promise((resolve) => {
26
26
  socket.on('close', () => resolve(status));
27
27
  socket.connect(portToTry, host);
28
28
  });
29
- const portCheckSequence = function* (ports) {
30
- if (ports) {
31
- yield* ports;
32
- }
33
- yield 0; // Fall back to 0 if anything else failed
34
- };
35
29
  const getPort = async (from, to) => {
36
30
  const ports = makeRange(from, to);
37
- for (const port of portCheckSequence(ports)) {
31
+ for (const port of ports) {
38
32
  if ((await getAvailablePort(port)) === 'available') {
39
33
  return port;
40
34
  }
@@ -71,10 +65,7 @@ const makeRange = (from, to) => {
71
65
  if (to < from) {
72
66
  throw new RangeError('`to` must be greater than or equal to `from`');
73
67
  }
74
- const generator = function* (f, t) {
75
- for (let port = f; port <= t; port++) {
76
- yield port;
77
- }
78
- };
79
- return generator(from, to);
68
+ return new Array(to - from + 1).fill(true).map((_, i) => {
69
+ return i + from;
70
+ });
80
71
  };
package/dist/index.d.ts CHANGED
@@ -52,7 +52,7 @@ export declare const RenderInternals: {
52
52
  }) => void;
53
53
  normalizeServeUrl: (unnormalized: string) => string;
54
54
  spawnFfmpeg: (options: import("./stitch-frames-to-video").StitcherOptions) => Promise<{
55
- task: Promise<void>;
55
+ task: Promise<Buffer | null>;
56
56
  getLogs: () => string;
57
57
  }>;
58
58
  getFileExtensionFromCodec: (codec: "h264" | "h265" | "vp8" | "vp9" | "mp3" | "aac" | "wav" | "prores" | "h264-mkv", type: "chunk" | "final") => "mp3" | "aac" | "wav" | "mp4" | "mkv" | "mov" | "webm";
@@ -62,12 +62,17 @@ export declare const RenderInternals: {
62
62
  ensureOutputDirectory: (outputLocation: string) => void;
63
63
  getRealFrameRange: (durationInFrames: number, frameRange: import("remotion").FrameRange | null) => [number, number];
64
64
  validatePuppeteerTimeout: (timeoutInMilliseconds: unknown) => void;
65
- downloadFile: (url: string, to: string, onProgress: ((progress: {
66
- progress: number;
67
- downloaded: number;
68
- totalSize: number;
69
- }) => void) | undefined) => Promise<{
65
+ downloadFile: ({ onProgress, url, to: toFn, }: {
66
+ url: string;
67
+ to: (contentDisposition: string | null) => string;
68
+ onProgress: ((progress: {
69
+ percent: number | null;
70
+ downloaded: number;
71
+ totalSize: number | null;
72
+ }) => void) | undefined;
73
+ }) => Promise<{
70
74
  sizeInBytes: number;
75
+ to: string;
71
76
  }>;
72
77
  validateScale: (scale: unknown) => void;
73
78
  killAllBrowsers: () => Promise<void>;
@@ -97,4 +102,6 @@ export declare const RenderInternals: {
97
102
  node(scriptPath: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
98
103
  node(scriptPath: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
99
104
  };
105
+ registerErrorSymbolicationLock: () => number;
106
+ unlockErrorSymbolicationLock: (id: number) => void;
100
107
  };
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ const validate_even_dimensions_with_codec_1 = require("./validate-even-dimension
31
31
  const validate_ffmpeg_1 = require("./validate-ffmpeg");
32
32
  const validate_puppeteer_timeout_1 = require("./validate-puppeteer-timeout");
33
33
  const validate_scale_1 = require("./validate-scale");
34
+ const wait_for_symbolication_error_to_be_done_1 = require("./wait-for-symbolication-error-to-be-done");
34
35
  var combine_videos_1 = require("./combine-videos");
35
36
  Object.defineProperty(exports, "combineVideos", { enumerable: true, get: function () { return combine_videos_1.combineVideos; } });
36
37
  var handle_javascript_exception_1 = require("./error-handling/handle-javascript-exception");
@@ -80,4 +81,6 @@ exports.RenderInternals = {
80
81
  mime: mime_types_1.default,
81
82
  isPathInside: is_path_inside_1.isPathInside,
82
83
  execa: execa_1.default,
84
+ registerErrorSymbolicationLock: wait_for_symbolication_error_to_be_done_1.registerErrorSymbolicationLock,
85
+ unlockErrorSymbolicationLock: wait_for_symbolication_error_to_be_done_1.unlockErrorSymbolicationLock,
83
86
  };
@@ -45,12 +45,8 @@ const startOffthreadVideoServer = ({ ffmpegExecutable, ffprobeExecutable, downlo
45
45
  const { src, time, imageFormat } = (0, exports.extractUrlAndSourceFromUrl)(req.url);
46
46
  res.setHeader('access-control-allow-origin', '*');
47
47
  res.setHeader('content-type', `image/${imageFormat === 'jpeg' ? 'jpg' : 'png'}`);
48
- const to = (0, download_and_map_assets_to_file_1.getSanitizedFilenameForAssetUrl)({ downloadDir, src });
49
- (0, download_and_map_assets_to_file_1.startDownloadForSrc)({ src, downloadDir, onDownload }).catch((err) => {
50
- onError(new Error(`Error while downloading asset: ${err.stack}`));
51
- });
52
- (0, download_and_map_assets_to_file_1.waitForAssetToBeDownloaded)(src, to)
53
- .then(() => {
48
+ (0, download_and_map_assets_to_file_1.downloadAsset)({ src, downloadDir, onDownload })
49
+ .then((to) => {
54
50
  return (0, extract_frame_from_video_1.extractFrameFromVideo)({
55
51
  time,
56
52
  src: to,
@@ -8,6 +8,7 @@ const fs_1 = require("fs");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const is_serve_url_1 = require("./is-serve-url");
10
10
  const serve_static_1 = require("./serve-static");
11
+ const wait_for_symbolication_error_to_be_done_1 = require("./wait-for-symbolication-error-to-be-done");
11
12
  const prepareServer = async ({ downloadDir, ffmpegExecutable, ffprobeExecutable, onDownload, onError, webpackConfigOrServeUrl, port, }) => {
12
13
  if ((0, is_serve_url_1.isServeUrl)(webpackConfigOrServeUrl)) {
13
14
  const { port: offthreadPort, close: closeProxy } = await (0, serve_static_1.serveStatic)(null, {
@@ -20,7 +21,9 @@ const prepareServer = async ({ downloadDir, ffmpegExecutable, ffprobeExecutable,
20
21
  });
21
22
  return Promise.resolve({
22
23
  serveUrl: webpackConfigOrServeUrl,
23
- closeServer: () => closeProxy(),
24
+ closeServer: () => {
25
+ return closeProxy();
26
+ },
24
27
  offthreadPort,
25
28
  });
26
29
  }
@@ -40,7 +43,7 @@ const prepareServer = async ({ downloadDir, ffmpegExecutable, ffprobeExecutable,
40
43
  });
41
44
  return Promise.resolve({
42
45
  closeServer: () => {
43
- return close();
46
+ return (0, wait_for_symbolication_error_to_be_done_1.waitForSymbolicationToBeDone)().then(() => close());
44
47
  },
45
48
  serveUrl: `http://localhost:${serverPort}`,
46
49
  offthreadPort: serverPort,
@@ -203,18 +203,11 @@ const innerRenderFrames = ({ onFrameUpdate, outputDir, onStart, inputProps, qual
203
203
  };
204
204
  return returnValue;
205
205
  });
206
- return Promise.race([
207
- happyPath
208
- .then(() => {
209
- return Promise.all(downloadPromises);
210
- })
211
- .then(() => happyPath),
212
- new Promise((_resolve, reject) => {
213
- cancelSignal === null || cancelSignal === void 0 ? void 0 : cancelSignal(() => {
214
- reject(new Error('renderFrames() got cancelled'));
215
- });
216
- }),
217
- ]);
206
+ return happyPath
207
+ .then(() => {
208
+ return Promise.all(downloadPromises);
209
+ })
210
+ .then(() => happyPath);
218
211
  };
219
212
  const renderFrames = (options) => {
220
213
  var _a, _b, _c, _d;
@@ -248,40 +241,42 @@ const renderFrames = (options) => {
248
241
  const onError = (err) => {
249
242
  reject(err);
250
243
  };
251
- Promise.all([
252
- (0, prepare_server_1.prepareServer)({
253
- webpackConfigOrServeUrl: selectedServeUrl,
254
- downloadDir,
255
- onDownload,
256
- onError,
257
- ffmpegExecutable: (_a = options.ffmpegExecutable) !== null && _a !== void 0 ? _a : null,
258
- ffprobeExecutable: (_b = options.ffprobeExecutable) !== null && _b !== void 0 ? _b : null,
259
- port: (_c = options.port) !== null && _c !== void 0 ? _c : null,
244
+ Promise.race([
245
+ new Promise((_, rej) => {
246
+ var _a;
247
+ (_a = options.cancelSignal) === null || _a === void 0 ? void 0 : _a.call(options, () => {
248
+ rej(new Error('renderFrames() got cancelled'));
249
+ });
250
+ }),
251
+ Promise.all([
252
+ (0, prepare_server_1.prepareServer)({
253
+ webpackConfigOrServeUrl: selectedServeUrl,
254
+ downloadDir,
255
+ onDownload,
256
+ onError,
257
+ ffmpegExecutable: (_a = options.ffmpegExecutable) !== null && _a !== void 0 ? _a : null,
258
+ ffprobeExecutable: (_b = options.ffprobeExecutable) !== null && _b !== void 0 ? _b : null,
259
+ port: (_c = options.port) !== null && _c !== void 0 ? _c : null,
260
+ }),
261
+ browserInstance,
262
+ ]).then(([{ serveUrl, closeServer, offthreadPort }, puppeteerInstance]) => {
263
+ const { stopCycling } = (0, cycle_browser_tabs_1.cycleBrowserTabs)(puppeteerInstance, actualParallelism);
264
+ cleanup.push(stopCycling);
265
+ cleanup.push(closeServer);
266
+ return innerRenderFrames({
267
+ ...options,
268
+ puppeteerInstance,
269
+ onError,
270
+ pagesArray: openedPages,
271
+ serveUrl,
272
+ composition,
273
+ actualParallelism,
274
+ onDownload,
275
+ downloadDir,
276
+ proxyPort: offthreadPort,
277
+ });
260
278
  }),
261
- browserInstance,
262
279
  ])
263
- .then(([{ serveUrl, closeServer, offthreadPort }, puppeteerInstance]) => {
264
- var _a;
265
- const { stopCycling } = (0, cycle_browser_tabs_1.cycleBrowserTabs)(puppeteerInstance, actualParallelism);
266
- cleanup.push(stopCycling);
267
- (_a = options.cancelSignal) === null || _a === void 0 ? void 0 : _a.call(options, () => {
268
- stopCycling();
269
- closeServer();
270
- });
271
- cleanup.push(closeServer);
272
- return innerRenderFrames({
273
- ...options,
274
- puppeteerInstance,
275
- onError,
276
- pagesArray: openedPages,
277
- serveUrl,
278
- composition,
279
- actualParallelism,
280
- onDownload,
281
- downloadDir,
282
- proxyPort: offthreadPort,
283
- });
284
- })
285
280
  .then((res) => {
286
281
  return resolve(res);
287
282
  })
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { BrowserExecutable, Codec, FfmpegExecutable, FrameRange, PixelFormat, ProResProfile, SmallTCompMetadata } from 'remotion';
2
3
  import type { RenderMediaOnDownload } from './assets/download-and-map-assets-to-file';
3
4
  import type { BrowserLog } from './browser-log';
@@ -15,7 +16,7 @@ export declare type RenderMediaOnProgress = (progress: {
15
16
  stitchStage: StitchingState;
16
17
  }) => void;
17
18
  export declare type RenderMediaOptions = {
18
- outputLocation: string;
19
+ outputLocation?: string | null;
19
20
  codec: Codec;
20
21
  composition: SmallTCompMetadata;
21
22
  inputProps?: unknown;
@@ -48,4 +49,4 @@ export declare type RenderMediaOptions = {
48
49
  * @description Render a video from a composition
49
50
  * @link https://www.remotion.dev/docs/renderer/render-media
50
51
  */
51
- export declare const renderMedia: ({ parallelism, proResProfile, crf, composition, imageFormat, ffmpegExecutable, ffprobeExecutable, inputProps, pixelFormat, codec, envVariables, quality, frameRange, puppeteerInstance, outputLocation, onProgress, overwrite, onDownload, dumpBrowserLogs, onBrowserLog, onStart, timeoutInMilliseconds, chromiumOptions, scale, browserExecutable, port, cancelSignal, ...options }: RenderMediaOptions) => Promise<void>;
52
+ export declare const renderMedia: ({ parallelism, proResProfile, crf, composition, imageFormat, ffmpegExecutable, ffprobeExecutable, inputProps, pixelFormat, codec, envVariables, quality, frameRange, puppeteerInstance, outputLocation, onProgress, overwrite, onDownload, dumpBrowserLogs, onBrowserLog, onStart, timeoutInMilliseconds, chromiumOptions, scale, browserExecutable, port, cancelSignal, ...options }: RenderMediaOptions) => Promise<Buffer | null>;
@@ -34,7 +34,9 @@ const renderMedia = ({ parallelism, proResProfile, crf, composition, imageFormat
34
34
  if (typeof crf !== 'undefined' && crf !== null) {
35
35
  remotion_1.Internals.validateSelectedCrfAndCodecCombination(crf, codec);
36
36
  }
37
- (0, validate_output_filename_1.validateOutputFilename)(codec, (0, get_extension_of_filename_1.getExtensionOfFilename)(outputLocation));
37
+ if (outputLocation) {
38
+ (0, validate_output_filename_1.validateOutputFilename)(codec, (0, get_extension_of_filename_1.getExtensionOfFilename)(outputLocation));
39
+ }
38
40
  (0, validate_scale_1.validateScale)(scale);
39
41
  const serveUrl = (0, legacy_webpack_config_1.getServeUrlWithFallback)(options);
40
42
  let stitchStage = 'encoding';
@@ -169,7 +171,9 @@ const renderMedia = ({ parallelism, proResProfile, crf, composition, imageFormat
169
171
  .then(([{ assetsInfo }]) => {
170
172
  renderedDoneIn = Date.now() - renderStart;
171
173
  callUpdate();
172
- (0, ensure_output_directory_1.ensureOutputDirectory)(outputLocation);
174
+ if (outputLocation) {
175
+ (0, ensure_output_directory_1.ensureOutputDirectory)(outputLocation);
176
+ }
173
177
  const stitchStart = Date.now();
174
178
  return Promise.all([
175
179
  (0, stitch_frames_to_video_1.stitchFramesToVideo)({
@@ -202,10 +206,11 @@ const renderMedia = ({ parallelism, proResProfile, crf, composition, imageFormat
202
206
  stitchStart,
203
207
  ]);
204
208
  })
205
- .then(([, stitchStart]) => {
209
+ .then(([buffer, stitchStart]) => {
206
210
  encodedFrames = (0, get_duration_from_frame_range_1.getDurationFromFrameRange)(frameRange !== null && frameRange !== void 0 ? frameRange : null, composition.durationInFrames);
207
211
  encodedDoneIn = Date.now() - stitchStart;
208
212
  callUpdate();
213
+ return buffer;
209
214
  })
210
215
  .catch((err) => {
211
216
  /**
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.seekToFrame = void 0;
4
4
  const puppeteer_evaluate_1 = require("./puppeteer-evaluate");
5
5
  const seekToFrame = async ({ frame, page, }) => {
6
- await page.waitForFunction('window.ready === true');
6
+ await page.waitForFunction(page.browser, 'window.ready === true');
7
7
  await (0, puppeteer_evaluate_1.puppeteerEvaluateWithCatch)({
8
8
  pageFunction: (f) => {
9
9
  window.remotion_setFrame(f);
@@ -12,7 +12,7 @@ const seekToFrame = async ({ frame, page, }) => {
12
12
  frame,
13
13
  page,
14
14
  });
15
- await page.waitForFunction('window.ready === true');
15
+ await page.waitForFunction(page.browser, 'window.ready === true');
16
16
  await page.evaluateHandle('document.fonts.ready');
17
17
  };
18
18
  exports.seekToFrame = seekToFrame;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { Codec, FfmpegExecutable, ImageFormat, PixelFormat, ProResProfile, RenderAssetInfo } from 'remotion';
2
3
  import type { RenderMediaOnDownload } from './assets/download-and-map-assets-to-file';
3
4
  import type { CancelSignal } from './make-cancel-signal';
@@ -5,7 +6,7 @@ export declare type StitcherOptions = {
5
6
  fps: number;
6
7
  width: number;
7
8
  height: number;
8
- outputLocation: string;
9
+ outputLocation?: string | null;
9
10
  force: boolean;
10
11
  assetsInfo: RenderAssetInfo;
11
12
  pixelFormat?: PixelFormat;
@@ -25,9 +26,9 @@ export declare type StitcherOptions = {
25
26
  };
26
27
  };
27
28
  declare type ReturnType = {
28
- task: Promise<void>;
29
+ task: Promise<Buffer | null>;
29
30
  getLogs: () => string;
30
31
  };
31
32
  export declare const spawnFfmpeg: (options: StitcherOptions) => Promise<ReturnType>;
32
- export declare const stitchFramesToVideo: (options: StitcherOptions) => Promise<void>;
33
+ export declare const stitchFramesToVideo: (options: StitcherOptions) => Promise<Buffer | null>;
33
34
  export {};
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.stitchFramesToVideo = exports.spawnFfmpeg = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
+ const promises_1 = require("fs/promises");
9
10
  const path_1 = __importDefault(require("path"));
10
11
  const remotion_1 = require("remotion");
11
12
  const calculate_asset_positions_1 = require("./assets/calculate-asset-positions");
@@ -14,6 +15,7 @@ const download_and_map_assets_to_file_1 = require("./assets/download-and-map-ass
14
15
  const delete_directory_1 = require("./delete-directory");
15
16
  const get_audio_codec_name_1 = require("./get-audio-codec-name");
16
17
  const get_codec_name_1 = require("./get-codec-name");
18
+ const get_extension_from_codec_1 = require("./get-extension-from-codec");
17
19
  const get_prores_profile_name_1 = require("./get-prores-profile-name");
18
20
  const merge_audio_track_1 = require("./merge-audio-track");
19
21
  const parse_ffmpeg_progress_1 = require("./parse-ffmpeg-progress");
@@ -69,7 +71,7 @@ const getAssetsData = async ({ assets, downloadDir, onDownload, fps, expectedFra
69
71
  return outName;
70
72
  };
71
73
  const spawnFfmpeg = async (options) => {
72
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
74
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
73
75
  remotion_1.Internals.validateDimension(options.height, 'height', 'passed to `stitchFramesToVideo()`');
74
76
  remotion_1.Internals.validateDimension(options.width, 'width', 'passed to `stitchFramesToVideo()`');
75
77
  remotion_1.Internals.validateFps(options.fps, 'passed to `stitchFramesToVideo()`');
@@ -88,6 +90,9 @@ const spawnFfmpeg = async (options) => {
88
90
  const proResProfileName = (0, get_prores_profile_name_1.getProResProfileName)(codec, options.proResProfile);
89
91
  const isAudioOnly = encoderName === null;
90
92
  const supportsCrf = encoderName && codec !== 'prores';
93
+ const tempFile = options.outputLocation
94
+ ? null
95
+ : path_1.default.join((0, tmp_dir_1.tmpDir)('remotion-stitch-temp-dir'), `out.${(0, get_extension_from_codec_1.getFileExtensionFromCodec)(codec, 'final')}`);
91
96
  if (options.verbose) {
92
97
  console.log('[verbose] ffmpeg', (_e = options.ffmpegExecutable) !== null && _e !== void 0 ? _e : 'ffmpeg in PATH');
93
98
  console.log('[verbose] encoder', encoderName);
@@ -132,22 +137,23 @@ const spawnFfmpeg = async (options) => {
132
137
  '-b:a',
133
138
  '320k',
134
139
  options.force ? '-y' : null,
135
- options.outputLocation,
140
+ (_j = options.outputLocation) !== null && _j !== void 0 ? _j : tempFile,
136
141
  ].filter(remotion_1.Internals.truthy));
137
- (_j = options.cancelSignal) === null || _j === void 0 ? void 0 : _j.call(options, () => {
142
+ (_k = options.cancelSignal) === null || _k === void 0 ? void 0 : _k.call(options, () => {
138
143
  ffmpegTask.kill();
139
144
  });
140
145
  await ffmpegTask;
141
- (_k = options.onProgress) === null || _k === void 0 ? void 0 : _k.call(options, expectedFrames);
146
+ (_l = options.onProgress) === null || _l === void 0 ? void 0 : _l.call(options, expectedFrames);
147
+ const file = tempFile ? await (0, promises_1.readFile)(tempFile) : null;
142
148
  return {
143
149
  getLogs: () => '',
144
- task: Promise.resolve(),
150
+ task: Promise.resolve(file),
145
151
  };
146
152
  }
147
153
  const ffmpegArgs = [
148
154
  ['-r', String(options.fps)],
149
- ...(((_l = options.internalOptions) === null || _l === void 0 ? void 0 : _l.preEncodedFileLocation)
150
- ? [['-i', (_m = options.internalOptions) === null || _m === void 0 ? void 0 : _m.preEncodedFileLocation]]
155
+ ...(((_m = options.internalOptions) === null || _m === void 0 ? void 0 : _m.preEncodedFileLocation)
156
+ ? [['-i', (_o = options.internalOptions) === null || _o === void 0 ? void 0 : _o.preEncodedFileLocation]]
151
157
  : [
152
158
  ['-f', 'image2'],
153
159
  ['-s', `${options.width}x${options.height}`],
@@ -158,7 +164,7 @@ const spawnFfmpeg = async (options) => {
158
164
  // -c:v is the same as -vcodec as -codec:video
159
165
  // and specified the video codec.
160
166
  ['-c:v', encoderName],
161
- ...(((_o = options.internalOptions) === null || _o === void 0 ? void 0 : _o.preEncodedFileLocation)
167
+ ...(((_p = options.internalOptions) === null || _p === void 0 ? void 0 : _p.preEncodedFileLocation)
162
168
  ? []
163
169
  : [
164
170
  proResProfileName ? ['-profile:v', proResProfileName] : null,
@@ -181,22 +187,22 @@ const spawnFfmpeg = async (options) => {
181
187
  [`Made with Remotion`, packageJson ? packageJson.version : null].join(' '),
182
188
  ],
183
189
  options.force ? '-y' : null,
184
- options.outputLocation,
190
+ (_q = options.outputLocation) !== null && _q !== void 0 ? _q : tempFile,
185
191
  ];
186
192
  if (options.verbose) {
187
193
  console.log('Generated FFMPEG command:');
188
194
  console.log(ffmpegArgs);
189
195
  }
190
196
  const ffmpegString = ffmpegArgs.flat(2).filter(Boolean);
191
- const task = (0, execa_1.default)((_p = options.ffmpegExecutable) !== null && _p !== void 0 ? _p : 'ffmpeg', ffmpegString, {
197
+ const task = (0, execa_1.default)((_r = options.ffmpegExecutable) !== null && _r !== void 0 ? _r : 'ffmpeg', ffmpegString, {
192
198
  cwd: options.dir,
193
199
  });
194
- (_q = options.cancelSignal) === null || _q === void 0 ? void 0 : _q.call(options, () => {
200
+ (_s = options.cancelSignal) === null || _s === void 0 ? void 0 : _s.call(options, () => {
195
201
  task.kill();
196
202
  });
197
203
  let ffmpegOutput = '';
198
204
  let isFinished = false;
199
- (_r = task.stderr) === null || _r === void 0 ? void 0 : _r.on('data', (data) => {
205
+ (_t = task.stderr) === null || _t === void 0 ? void 0 : _t.on('data', (data) => {
200
206
  var _a;
201
207
  const str = data.toString();
202
208
  ffmpegOutput += str;
@@ -218,7 +224,19 @@ const spawnFfmpeg = async (options) => {
218
224
  }
219
225
  }
220
226
  });
221
- return { task: task.then(() => undefined), getLogs: () => ffmpegOutput };
227
+ return {
228
+ task: task.then(() => {
229
+ if (options.outputLocation) {
230
+ return null;
231
+ }
232
+ return (0, promises_1.readFile)(tempFile)
233
+ .then((file) => {
234
+ return Promise.all([file, (0, promises_1.unlink)(tempFile)]);
235
+ })
236
+ .then(([file]) => file);
237
+ }),
238
+ getLogs: () => ffmpegOutput,
239
+ };
222
240
  };
223
241
  exports.spawnFfmpeg = spawnFfmpeg;
224
242
  const stitchFramesToVideo = async (options) => {
@@ -12,7 +12,6 @@ const stringifyFfmpegFilter = ({ trimLeft, trimRight, channels, startInVideo, vo
12
12
  }
13
13
  const volumeFilter = (0, ffmpeg_volume_expression_1.ffmpegVolumeExpression)({
14
14
  volume,
15
- startInVideo,
16
15
  fps,
17
16
  trimLeft,
18
17
  });
@@ -29,6 +28,12 @@ const stringifyFfmpegFilter = ({ trimLeft, trimRight, channels, startInVideo, vo
29
28
  `atrim=${trimLeft.toFixed(6)}:${actualTrimRight.toFixed(6)}`,
30
29
  // then set the tempo
31
30
  (0, calculate_atempo_1.calculateATempo)(playbackRate),
31
+ // set the volume if needed
32
+ // The timings for volume must include whatever is in atrim, unless the volume
33
+ // filter gets applied before atrim
34
+ volumeFilter.value === '1'
35
+ ? null
36
+ : `volume=${volumeFilter.value}:eval=${volumeFilter.eval}`,
32
37
  // For n channels, we delay n + 1 channels.
33
38
  // This is because `ffprobe` for some audio files reports the wrong amount
34
39
  // of channels.
@@ -40,12 +45,6 @@ const stringifyFfmpegFilter = ({ trimLeft, trimRight, channels, startInVideo, vo
40
45
  : `adelay=${new Array(channels + 1)
41
46
  .fill((startInVideoSeconds * 1000).toFixed(0))
42
47
  .join('|')}`,
43
- // set the volume if needed
44
- // The timings for volume must include whatever is in atrim, unless the volume
45
- // filter gets applied before atrim
46
- volumeFilter.value === '1'
47
- ? null
48
- : `volume=${volumeFilter.value}:eval=${volumeFilter.eval}`,
49
48
  // Only in the end, we pad to the full length.
50
49
  padAtEnd > 0.0000001
51
50
  ? 'apad=pad_len=' + Math.round(padAtEnd * sample_rate_1.DEFAULT_SAMPLE_RATE)
@@ -0,0 +1,3 @@
1
+ export declare const registerErrorSymbolicationLock: () => number;
2
+ export declare const unlockErrorSymbolicationLock: (id: number) => void;
3
+ export declare const waitForSymbolicationToBeDone: () => Promise<unknown>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitForSymbolicationToBeDone = exports.unlockErrorSymbolicationLock = exports.registerErrorSymbolicationLock = void 0;
4
+ let locks = [];
5
+ const waiters = [];
6
+ const registerErrorSymbolicationLock = () => {
7
+ const id = Math.random();
8
+ locks.push(id);
9
+ return id;
10
+ };
11
+ exports.registerErrorSymbolicationLock = registerErrorSymbolicationLock;
12
+ const unlockErrorSymbolicationLock = (id) => {
13
+ locks = locks.filter((l) => l !== id);
14
+ resolveWaiters();
15
+ };
16
+ exports.unlockErrorSymbolicationLock = unlockErrorSymbolicationLock;
17
+ const resolveWaiters = () => {
18
+ if (locks.length === 0) {
19
+ waiters.forEach((w) => w());
20
+ }
21
+ };
22
+ const waitForSymbolicationToBeDone = () => {
23
+ const success = new Promise((resolve) => {
24
+ waiters.push(() => {
25
+ resolve();
26
+ });
27
+ });
28
+ const timeout = new Promise((resolve) => {
29
+ setTimeout(() => resolve(), 5000);
30
+ });
31
+ resolveWaiters();
32
+ return Promise.all([success, timeout]);
33
+ };
34
+ exports.waitForSymbolicationToBeDone = waitForSymbolicationToBeDone;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/renderer",
3
- "version": "3.0.25",
3
+ "version": "3.0.26",
4
4
  "description": "Renderer for Remotion",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "execa": "5.1.1",
24
24
  "extract-zip": "2.0.1",
25
25
  "mime-types": "2.1.35",
26
- "remotion": "3.0.25",
26
+ "remotion": "3.0.26",
27
27
  "source-map": "^0.8.0-beta.0",
28
28
  "ws": "8.7.0"
29
29
  },
@@ -63,5 +63,5 @@
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "27ec369ebe9cf3d063095383c1e30dc83c60f010"
66
+ "gitHead": "790e9bb2d66f2fe97efc209237cc57d7cad2e793"
67
67
  }