@remotion/renderer 4.0.0-offthread.32 → 4.0.0-offthread.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/assets/download-and-map-assets-to-file.d.ts +1 -1
  2. package/dist/assets/download-and-map-assets-to-file.js +30 -13
  3. package/dist/combine-videos.d.ts +2 -1
  4. package/dist/combine-videos.js +3 -1
  5. package/dist/create-ffmpeg-complex-filter.d.ts +1 -4
  6. package/dist/cycle-browser-tabs.d.ts +2 -1
  7. package/dist/cycle-browser-tabs.js +9 -2
  8. package/dist/extract-frame-from-video.d.ts +0 -5
  9. package/dist/extract-frame-from-video.js +60 -37
  10. package/dist/get-compositions.d.ts +2 -1
  11. package/dist/get-compositions.js +3 -1
  12. package/dist/index.d.ts +2 -13
  13. package/dist/index.js +3 -5
  14. package/dist/last-frame-from-video-cache.d.ts +11 -0
  15. package/dist/last-frame-from-video-cache.js +52 -0
  16. package/dist/make-cancel-signal.d.ts +7 -0
  17. package/dist/make-cancel-signal.js +25 -0
  18. package/dist/merge-audio-track.js +2 -2
  19. package/dist/offthread-video-server.d.ts +6 -1
  20. package/dist/offthread-video-server.js +5 -4
  21. package/dist/open-browser.d.ts +5 -5
  22. package/dist/open-browser.js +2 -1
  23. package/dist/prepare-server.d.ts +2 -1
  24. package/dist/prepare-server.js +6 -6
  25. package/dist/prespawn-ffmpeg.d.ts +2 -0
  26. package/dist/prespawn-ffmpeg.js +3 -0
  27. package/dist/puppeteer-screenshot.js +5 -1
  28. package/dist/render-frames.d.ts +3 -0
  29. package/dist/render-frames.js +76 -37
  30. package/dist/render-media.d.ts +6 -2
  31. package/dist/render-media.js +117 -55
  32. package/dist/render-still.d.ts +7 -3
  33. package/dist/render-still.js +30 -12
  34. package/dist/serve-static.js +9 -1
  35. package/dist/set-props-and-env.d.ts +2 -1
  36. package/dist/set-props-and-env.js +22 -3
  37. package/dist/stitch-frames-to-video.d.ts +3 -1
  38. package/dist/stitch-frames-to-video.js +27 -14
  39. package/package.json +4 -4
@@ -2,7 +2,7 @@ import { TAsset } from 'remotion';
2
2
  export declare type RenderMediaOnDownload = (src: string) => ((progress: {
3
3
  percent: number;
4
4
  }) => void) | undefined | void;
5
- export declare const waitForAssetToBeDownloaded: (src: string) => Promise<string>;
5
+ export declare const waitForAssetToBeDownloaded: (src: string, to: string) => Promise<void>;
6
6
  export declare const markAllAssetsAsDownloaded: () => void;
7
7
  export declare const getSanitizedFilenameForAssetUrl: ({ src, downloadDir, }: {
8
8
  src: string;
@@ -13,25 +13,38 @@ const sanitize_filepath_1 = require("./sanitize-filepath");
13
13
  const isDownloadingMap = {};
14
14
  const hasBeenDownloadedMap = {};
15
15
  const listeners = {};
16
- const waitForAssetToBeDownloaded = (src) => {
17
- if (hasBeenDownloadedMap[src]) {
18
- return Promise.resolve(hasBeenDownloadedMap[src]);
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();
19
20
  }
20
21
  if (!listeners[src]) {
21
- listeners[src] = [];
22
+ listeners[src] = {};
23
+ }
24
+ if (!listeners[src][to]) {
25
+ listeners[src][to] = [];
22
26
  }
23
27
  return new Promise((resolve) => {
24
- listeners[src].push((to) => resolve(to));
28
+ listeners[src][to].push(() => resolve());
25
29
  });
26
30
  };
27
31
  exports.waitForAssetToBeDownloaded = waitForAssetToBeDownloaded;
28
32
  const notifyAssetIsDownloaded = (src, to) => {
29
33
  if (!listeners[src]) {
30
- listeners[src] = [];
34
+ listeners[src] = {};
35
+ }
36
+ if (!listeners[src][to]) {
37
+ listeners[src][to] = [];
38
+ }
39
+ listeners[src][to].forEach((fn) => fn());
40
+ if (!isDownloadingMap[src]) {
41
+ isDownloadingMap[src] = {};
31
42
  }
32
- listeners[src].forEach((fn) => fn(to));
33
- isDownloadingMap[src] = false;
34
- hasBeenDownloadedMap[src] = to;
43
+ isDownloadingMap[src][to] = false;
44
+ if (!hasBeenDownloadedMap[src]) {
45
+ hasBeenDownloadedMap[src] = {};
46
+ }
47
+ hasBeenDownloadedMap[src][to] = true;
35
48
  };
36
49
  const validateMimeType = (mimeType, src) => {
37
50
  if (!mimeType.includes('/')) {
@@ -73,13 +86,17 @@ function validateBufferEncoding(potentialEncoding, dataUrl) {
73
86
  }
74
87
  }
75
88
  const downloadAsset = async (src, to, onDownload) => {
76
- if (hasBeenDownloadedMap[src]) {
89
+ var _a, _b;
90
+ if ((_a = hasBeenDownloadedMap[src]) === null || _a === void 0 ? void 0 : _a[to]) {
77
91
  return;
78
92
  }
79
- if (isDownloadingMap[src]) {
80
- return (0, exports.waitForAssetToBeDownloaded)(src);
93
+ if ((_b = isDownloadingMap[src]) === null || _b === void 0 ? void 0 : _b[to]) {
94
+ return (0, exports.waitForAssetToBeDownloaded)(src, to);
95
+ }
96
+ if (!isDownloadingMap[src]) {
97
+ isDownloadingMap[src] = {};
81
98
  }
82
- isDownloadingMap[src] = true;
99
+ isDownloadingMap[src][to] = true;
83
100
  const onProgress = onDownload(src);
84
101
  (0, ensure_output_directory_1.ensureOutputDirectory)(to);
85
102
  if (src.startsWith('data:')) {
@@ -1,9 +1,10 @@
1
1
  import { Codec } from 'remotion';
2
- export declare const combineVideos: ({ files, filelistDir, output, onProgress, numberOfFrames, codec, }: {
2
+ export declare const combineVideos: ({ files, filelistDir, output, onProgress, numberOfFrames, codec, fps, }: {
3
3
  files: string[];
4
4
  filelistDir: string;
5
5
  output: string;
6
6
  onProgress: (p: number) => void;
7
7
  numberOfFrames: number;
8
8
  codec: Codec;
9
+ fps: number;
9
10
  }) => Promise<void>;
@@ -11,13 +11,15 @@ const path_1 = require("path");
11
11
  const remotion_1 = require("remotion");
12
12
  const get_audio_codec_name_1 = require("./get-audio-codec-name");
13
13
  const parse_ffmpeg_progress_1 = require("./parse-ffmpeg-progress");
14
- const combineVideos = async ({ files, filelistDir, output, onProgress, numberOfFrames, codec, }) => {
14
+ const combineVideos = async ({ files, filelistDir, output, onProgress, numberOfFrames, codec, fps, }) => {
15
15
  var _a;
16
16
  const fileList = files.map((p) => `file '${p}'`).join('\n');
17
17
  const fileListTxt = (0, path_1.join)(filelistDir, 'files.txt');
18
18
  (0, fs_1.writeFileSync)(fileListTxt, fileList);
19
19
  try {
20
20
  const task = (0, execa_1.default)('ffmpeg', [
21
+ remotion_1.Internals.isAudioCodec(codec) ? null : '-r',
22
+ remotion_1.Internals.isAudioCodec(codec) ? null : String(fps),
21
23
  '-f',
22
24
  'concat',
23
25
  '-safe',
@@ -1,7 +1,4 @@
1
1
  export declare const createFfmpegComplexFilter: (filters: number) => Promise<{
2
- complexFilterFlag: [
3
- string,
4
- string
5
- ] | null;
2
+ complexFilterFlag: [string, string] | null;
6
3
  cleanup: () => void;
7
4
  }>;
@@ -1,6 +1,7 @@
1
1
  import { openBrowser } from './open-browser';
2
2
  declare type Await<T> = T extends PromiseLike<infer U> ? U : T;
3
- export declare const cycleBrowserTabs: (puppeteerInstance: Await<ReturnType<typeof openBrowser>>, concurrency: number) => {
3
+ declare type Browser = Await<ReturnType<typeof openBrowser>>;
4
+ export declare const cycleBrowserTabs: (puppeteerInstance: Browser, concurrency: number) => {
4
5
  stopCycling: () => void;
5
6
  };
6
7
  export {};
@@ -9,15 +9,21 @@ const cycleBrowserTabs = (puppeteerInstance, concurrency) => {
9
9
  }
10
10
  let interval = null;
11
11
  let i = 0;
12
+ let stopped = false;
12
13
  const set = () => {
13
14
  interval = setTimeout(() => {
14
15
  puppeteerInstance
15
16
  .pages()
16
17
  .then((pages) => {
17
- var _a, _b;
18
+ var _a;
19
+ if (pages.length === 0) {
20
+ return;
21
+ }
18
22
  const currentPage = pages[i % pages.length];
19
23
  i++;
20
- if (!((_b = (_a = currentPage === null || currentPage === void 0 ? void 0 : currentPage.isClosed) === null || _a === void 0 ? void 0 : _a.call(currentPage)) !== null && _b !== void 0 ? _b : true)) {
24
+ if (!((_a = currentPage === null || currentPage === void 0 ? void 0 : currentPage.isClosed) === null || _a === void 0 ? void 0 : _a.call(currentPage)) &&
25
+ !stopped &&
26
+ (currentPage === null || currentPage === void 0 ? void 0 : currentPage.url()) !== 'about:blank') {
21
27
  return currentPage.bringToFront();
22
28
  }
23
29
  })
@@ -33,6 +39,7 @@ const cycleBrowserTabs = (puppeteerInstance, concurrency) => {
33
39
  if (!interval) {
34
40
  return;
35
41
  }
42
+ stopped = true;
36
43
  return clearInterval(interval);
37
44
  },
38
45
  };
@@ -2,11 +2,6 @@
2
2
  import { FfmpegExecutable } from 'remotion';
3
3
  import { Readable } from 'stream';
4
4
  export declare function streamToString(stream: Readable): Promise<string>;
5
- export declare const getLastFrameOfVideo: ({ ffmpegExecutable, offset, src, }: {
6
- ffmpegExecutable: FfmpegExecutable;
7
- offset: number;
8
- src: string;
9
- }) => Promise<Buffer>;
10
5
  declare type Options = {
11
6
  time: number;
12
7
  src: string;
@@ -3,9 +3,10 @@ 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.extractFrameFromVideo = exports.extractFrameFromVideoFn = exports.getLastFrameOfVideo = exports.streamToString = void 0;
6
+ exports.extractFrameFromVideo = exports.extractFrameFromVideoFn = exports.streamToString = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
8
  const frame_to_ffmpeg_timestamp_1 = require("./frame-to-ffmpeg-timestamp");
9
+ const last_frame_from_video_cache_1 = require("./last-frame-from-video-cache");
9
10
  const p_limit_1 = require("./p-limit");
10
11
  function streamToString(stream) {
11
12
  const chunks = [];
@@ -16,7 +17,8 @@ function streamToString(stream) {
16
17
  });
17
18
  }
18
19
  exports.streamToString = streamToString;
19
- const getLastFrameOfVideo = ({ ffmpegExecutable, offset, src, }) => {
20
+ const limit = (0, p_limit_1.pLimit)(5);
21
+ const getLastFrameOfVideoUnlimited = async ({ ffmpegExecutable, offset, src, }) => {
20
22
  if (offset > 100) {
21
23
  throw new Error('could not get last frame of ' +
22
24
  src +
@@ -40,33 +42,41 @@ const getLastFrameOfVideo = ({ ffmpegExecutable, offset, src, }) => {
40
42
  if (!stdout) {
41
43
  throw new Error('unexpectedly did not get stdout');
42
44
  }
43
- const chunks = [];
44
- return new Promise((resolve, reject) => {
45
- let isEmpty = false;
46
- stderr.on('data', (d) => {
47
- if (d.toString().includes('Output file is empty')) {
48
- isEmpty = true;
49
- (0, exports.getLastFrameOfVideo)({ ffmpegExecutable, offset: offset + 10, src })
50
- .then((frame) => resolve(frame))
51
- .catch((err) => reject(err));
52
- }
53
- });
45
+ const stderrChunks = [];
46
+ const stdoutChunks = [];
47
+ const stdErrString = new Promise((resolve, reject) => {
48
+ stderr.on('data', (d) => stderrChunks.push(d));
49
+ stderr.on('error', (err) => reject(err));
50
+ stderr.on('end', () => resolve(Buffer.concat(stderrChunks).toString('utf-8')));
51
+ });
52
+ const stdoutChunk = new Promise((resolve, reject) => {
54
53
  stdout.on('data', (d) => {
55
- chunks.push(d);
54
+ stdoutChunks.push(d);
56
55
  });
57
56
  stdout.on('error', (err) => {
58
57
  reject(err);
59
58
  });
60
59
  stdout.on('end', () => {
61
- if (!isEmpty) {
62
- resolve(Buffer.concat(chunks));
63
- }
60
+ resolve(Buffer.concat(stdoutChunks));
64
61
  });
65
62
  });
63
+ const [stdErr, stdoutBuffer] = await Promise.all([stdErrString, stdoutChunk]);
64
+ const isEmpty = stdErr.includes('Output file is empty');
65
+ if (isEmpty) {
66
+ return getLastFrameOfVideo({ ffmpegExecutable, offset: offset + 10, src });
67
+ }
68
+ return stdoutBuffer;
66
69
  };
67
- exports.getLastFrameOfVideo = getLastFrameOfVideo;
68
- const limit = (0, p_limit_1.pLimit)(5);
69
- const extractFrameFromVideoFn = ({ time, src, ffmpegExecutable, }) => {
70
+ const getLastFrameOfVideo = async (options) => {
71
+ const fromCache = (0, last_frame_from_video_cache_1.getLastFrameFromCache)(options);
72
+ if (fromCache) {
73
+ return fromCache;
74
+ }
75
+ const result = await limit(getLastFrameOfVideoUnlimited, options);
76
+ (0, last_frame_from_video_cache_1.setLastFrameInCache)(options, result);
77
+ return result;
78
+ };
79
+ const extractFrameFromVideoFn = async ({ time, src, ffmpegExecutable, }) => {
70
80
  const ffmpegTimestamp = (0, frame_to_ffmpeg_timestamp_1.frameToFfmpegTimestamp)(time);
71
81
  const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
72
82
  '-ss',
@@ -87,29 +97,42 @@ const extractFrameFromVideoFn = ({ time, src, ffmpegExecutable, }) => {
87
97
  if (!stdout) {
88
98
  throw new Error('unexpectedly did not get stdout');
89
99
  }
90
- const chunks = [];
91
- return new Promise((resolve, reject) => {
92
- let isEmpty = false;
93
- stderr === null || stderr === void 0 ? void 0 : stderr.on('data', (d) => {
94
- if (d.toString().includes('Output file is empty')) {
95
- isEmpty = true;
96
- (0, exports.getLastFrameOfVideo)({ ffmpegExecutable, offset: 0, src })
97
- .then((frame) => resolve(frame))
98
- .catch((err) => reject(err));
99
- }
100
+ const stdoutChunks = [];
101
+ const stderrChunks = [];
102
+ const stderrStringProm = new Promise((resolve, reject) => {
103
+ stderr.on('data', (d) => {
104
+ stderrChunks.push(d);
105
+ });
106
+ stderr.on('error', (err) => {
107
+ reject(err);
100
108
  });
101
- stdout === null || stdout === void 0 ? void 0 : stdout.on('data', (d) => {
102
- chunks.push(d);
109
+ stderr.on('end', () => {
110
+ resolve(Buffer.concat(stderrChunks).toString('utf8'));
111
+ });
112
+ });
113
+ const stdoutBuffer = new Promise((resolve, reject) => {
114
+ stdout.on('data', (d) => {
115
+ stdoutChunks.push(d);
103
116
  });
104
- stdout === null || stdout === void 0 ? void 0 : stdout.on('error', (err) => {
117
+ stdout.on('error', (err) => {
105
118
  reject(err);
106
119
  });
107
- stdout === null || stdout === void 0 ? void 0 : stdout.on('end', () => {
108
- if (!isEmpty) {
109
- resolve(Buffer.concat(chunks));
110
- }
120
+ stdout.on('end', () => {
121
+ resolve(Buffer.concat(stdoutChunks));
111
122
  });
112
123
  });
124
+ const [stderrStr, stdOut] = await Promise.all([
125
+ stderrStringProm,
126
+ stdoutBuffer,
127
+ ]);
128
+ if (stderrStr.includes('Output file is empty')) {
129
+ return getLastFrameOfVideo({
130
+ ffmpegExecutable,
131
+ offset: 0,
132
+ src,
133
+ });
134
+ }
135
+ return stdOut;
113
136
  };
114
137
  exports.extractFrameFromVideoFn = extractFrameFromVideoFn;
115
138
  const extractFrameFromVideo = (options) => {
@@ -11,6 +11,7 @@ declare type GetCompositionsConfig = {
11
11
  timeoutInMilliseconds?: number;
12
12
  chromiumOptions?: ChromiumOptions;
13
13
  ffmpegExecutable?: FfmpegExecutable;
14
+ port?: number | null;
14
15
  };
15
- export declare const getCompositions: (serveUrlOrWebpackUrl: string, config?: GetCompositionsConfig | undefined) => Promise<TCompMetadata[]>;
16
+ export declare const getCompositions: (serveUrlOrWebpackUrl: string, config?: GetCompositionsConfig) => Promise<TCompMetadata[]>;
16
17
  export {};
@@ -28,6 +28,7 @@ const innerGetCompositions = async (serveUrl, page, config, proxyPort) => {
28
28
  initialFrame: 0,
29
29
  timeoutInMilliseconds: config === null || config === void 0 ? void 0 : config.timeoutInMilliseconds,
30
30
  proxyPort,
31
+ retriesRemaining: 2,
31
32
  });
32
33
  await (0, puppeteer_evaluate_1.puppeteerEvaluateWithCatch)({
33
34
  page,
@@ -59,7 +60,7 @@ const getCompositions = async (serveUrlOrWebpackUrl, config) => {
59
60
  chromiumOptions: (_b = config === null || config === void 0 ? void 0 : config.chromiumOptions) !== null && _b !== void 0 ? _b : {},
60
61
  });
61
62
  return new Promise((resolve, reject) => {
62
- var _a;
63
+ var _a, _b;
63
64
  const onError = (err) => reject(err);
64
65
  const cleanupPageError = (0, handle_javascript_exception_1.handleJavascriptException)({
65
66
  page,
@@ -73,6 +74,7 @@ const getCompositions = async (serveUrlOrWebpackUrl, config) => {
73
74
  onDownload: () => undefined,
74
75
  onError,
75
76
  ffmpegExecutable: (_a = config === null || config === void 0 ? void 0 : config.ffmpegExecutable) !== null && _a !== void 0 ? _a : null,
77
+ port: (_b = config === null || config === void 0 ? void 0 : config.port) !== null && _b !== void 0 ? _b : null,
76
78
  })
77
79
  .then(({ serveUrl, closeServer, offthreadPort }) => {
78
80
  close = closeServer;
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { combineVideos } from './combine-videos';
5
5
  export { ErrorWithStackFrame } from './error-handling/handle-javascript-exception';
6
6
  export { FfmpegVersion } from './ffmpeg-flags';
7
7
  export { getCompositions } from './get-compositions';
8
+ export { CancelSignal, makeCancelSignal } from './make-cancel-signal';
8
9
  export { openBrowser } from './open-browser';
9
10
  export type { ChromiumOptions } from './open-browser';
10
11
  export { renderFrames } from './render-frames';
@@ -47,24 +48,12 @@ export declare const RenderInternals: {
47
48
  }) => void;
48
49
  normalizeServeUrl: (unnormalized: string) => string;
49
50
  spawnFfmpeg: (options: import("./stitch-frames-to-video").StitcherOptions) => Promise<{
50
- task: Promise<unknown>;
51
+ task: Promise<void>;
51
52
  getLogs: () => string;
52
53
  }>;
53
54
  getFileExtensionFromCodec: (codec: "h264" | "h265" | "vp8" | "vp9" | "mp3" | "aac" | "wav" | "prores" | "h264-mkv", type: "chunk" | "final") => "mp3" | "aac" | "wav" | "mp4" | "mkv" | "mov" | "webm";
54
- makeAssetsDownloadTmpDir: () => string;
55
55
  tmpDir: (str: string) => string;
56
56
  deleteDirectory: (directory: string) => Promise<void>;
57
- prepareServer: ({ downloadDir, ffmpegExecutable, onDownload, onError, webpackConfigOrServeUrl, }: {
58
- webpackConfigOrServeUrl: string;
59
- downloadDir: string;
60
- onDownload: import("./assets/download-and-map-assets-to-file").RenderMediaOnDownload;
61
- onError: (err: Error) => void;
62
- ffmpegExecutable: import("remotion").FfmpegExecutable;
63
- }) => Promise<{
64
- serveUrl: string;
65
- closeServer: () => Promise<unknown>;
66
- offthreadPort: number;
67
- }>;
68
57
  isServeUrl: (potentialUrl: string) => boolean;
69
58
  ensureOutputDirectory: (outputLocation: string) => void;
70
59
  getRealFrameRange: (durationInFrames: number, frameRange: import("remotion").FrameRange | null) => [number, number];
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RenderInternals = exports.stitchFramesToVideo = exports.renderStill = exports.renderMedia = exports.renderFrames = exports.openBrowser = exports.getCompositions = exports.ErrorWithStackFrame = exports.combineVideos = void 0;
3
+ exports.RenderInternals = exports.stitchFramesToVideo = exports.renderStill = exports.renderMedia = exports.renderFrames = exports.openBrowser = exports.makeCancelSignal = exports.getCompositions = exports.ErrorWithStackFrame = exports.combineVideos = void 0;
4
4
  const download_file_1 = require("./assets/download-file");
5
5
  const delete_directory_1 = require("./delete-directory");
6
6
  const ensure_output_directory_1 = require("./ensure-output-directory");
@@ -14,11 +14,9 @@ const get_extension_of_filename_1 = require("./get-extension-of-filename");
14
14
  const get_frame_to_render_1 = require("./get-frame-to-render");
15
15
  const get_local_browser_executable_1 = require("./get-local-browser-executable");
16
16
  const is_serve_url_1 = require("./is-serve-url");
17
- const make_assets_download_dir_1 = require("./make-assets-download-dir");
18
17
  const normalize_serve_url_1 = require("./normalize-serve-url");
19
18
  const open_browser_1 = require("./open-browser");
20
19
  const parse_browser_error_stack_1 = require("./parse-browser-error-stack");
21
- const prepare_server_1 = require("./prepare-server");
22
20
  const serve_static_1 = require("./serve-static");
23
21
  const stitch_frames_to_video_1 = require("./stitch-frames-to-video");
24
22
  const tmp_dir_1 = require("./tmp-dir");
@@ -32,6 +30,8 @@ var handle_javascript_exception_1 = require("./error-handling/handle-javascript-
32
30
  Object.defineProperty(exports, "ErrorWithStackFrame", { enumerable: true, get: function () { return handle_javascript_exception_1.ErrorWithStackFrame; } });
33
31
  var get_compositions_1 = require("./get-compositions");
34
32
  Object.defineProperty(exports, "getCompositions", { enumerable: true, get: function () { return get_compositions_1.getCompositions; } });
33
+ var make_cancel_signal_1 = require("./make-cancel-signal");
34
+ Object.defineProperty(exports, "makeCancelSignal", { enumerable: true, get: function () { return make_cancel_signal_1.makeCancelSignal; } });
35
35
  var open_browser_2 = require("./open-browser");
36
36
  Object.defineProperty(exports, "openBrowser", { enumerable: true, get: function () { return open_browser_2.openBrowser; } });
37
37
  var render_frames_1 = require("./render-frames");
@@ -55,10 +55,8 @@ exports.RenderInternals = {
55
55
  normalizeServeUrl: normalize_serve_url_1.normalizeServeUrl,
56
56
  spawnFfmpeg: stitch_frames_to_video_1.spawnFfmpeg,
57
57
  getFileExtensionFromCodec: get_extension_from_codec_1.getFileExtensionFromCodec,
58
- makeAssetsDownloadTmpDir: make_assets_download_dir_1.makeAssetsDownloadTmpDir,
59
58
  tmpDir: tmp_dir_1.tmpDir,
60
59
  deleteDirectory: delete_directory_1.deleteDirectory,
61
- prepareServer: prepare_server_1.prepareServer,
62
60
  isServeUrl: is_serve_url_1.isServeUrl,
63
61
  ensureOutputDirectory: ensure_output_directory_1.ensureOutputDirectory,
64
62
  getRealFrameRange: get_frame_to_render_1.getRealFrameRange,
@@ -0,0 +1,11 @@
1
+ import { FfmpegExecutable } from 'remotion';
2
+ export declare type LastFrameOptions = {
3
+ ffmpegExecutable: FfmpegExecutable;
4
+ offset: number;
5
+ src: string;
6
+ };
7
+ export declare const setLastFrameInCache: (options: LastFrameOptions, data: Buffer) => void;
8
+ export declare const getLastFrameFromCache: (options: LastFrameOptions) => Buffer | null;
9
+ export declare const removedLastFrameFromCache: (key: string) => void;
10
+ export declare const ensureMaxSize: () => void;
11
+ export declare const clearLastFileCache: () => void;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ // OffthreadVideo requires sometimes that the last frame of a video gets extracted, however, this can be slow. We allocate a cache for it but that can be garbage collected
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.clearLastFileCache = exports.ensureMaxSize = exports.removedLastFrameFromCache = exports.getLastFrameFromCache = exports.setLastFrameInCache = void 0;
5
+ let map = {};
6
+ const MAX_CACHE_SIZE = 50 * 1024 * 1024; // 50MB
7
+ let bufferSize = 0;
8
+ const makeLastFrameCacheKey = (options) => {
9
+ return [options.ffmpegExecutable, options.offset, options.src].join('-');
10
+ };
11
+ const setLastFrameInCache = (options, data) => {
12
+ const key = makeLastFrameCacheKey(options);
13
+ if (map[key]) {
14
+ bufferSize -= map[key].data.byteLength;
15
+ }
16
+ map[key] = { data, lastAccessed: Date.now() };
17
+ bufferSize += data.byteLength;
18
+ (0, exports.ensureMaxSize)();
19
+ };
20
+ exports.setLastFrameInCache = setLastFrameInCache;
21
+ const getLastFrameFromCache = (options) => {
22
+ var _a;
23
+ const key = makeLastFrameCacheKey(options);
24
+ if (!map[key]) {
25
+ return null;
26
+ }
27
+ map[key].lastAccessed = Date.now();
28
+ return (_a = map[key].data) !== null && _a !== void 0 ? _a : null;
29
+ };
30
+ exports.getLastFrameFromCache = getLastFrameFromCache;
31
+ const removedLastFrameFromCache = (key) => {
32
+ if (!map[key]) {
33
+ return;
34
+ }
35
+ bufferSize -= map[key].data.byteLength;
36
+ delete map[key];
37
+ };
38
+ exports.removedLastFrameFromCache = removedLastFrameFromCache;
39
+ const ensureMaxSize = () => {
40
+ // eslint-disable-next-line no-unmodified-loop-condition
41
+ while (bufferSize > MAX_CACHE_SIZE) {
42
+ const earliest = Object.entries(map).sort((a, b) => {
43
+ return a[1].lastAccessed - b[1].lastAccessed;
44
+ })[0];
45
+ (0, exports.removedLastFrameFromCache)(earliest[0]);
46
+ }
47
+ };
48
+ exports.ensureMaxSize = ensureMaxSize;
49
+ const clearLastFileCache = () => {
50
+ map = {};
51
+ };
52
+ exports.clearLastFileCache = clearLastFileCache;
@@ -0,0 +1,7 @@
1
+ declare type Callback = () => void;
2
+ export declare type CancelSignal = (callback: Callback) => void;
3
+ export declare const makeCancelSignal: () => {
4
+ cancelSignal: CancelSignal;
5
+ cancel: () => void;
6
+ };
7
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeCancelSignal = void 0;
4
+ const makeCancelSignal = () => {
5
+ const callbacks = [];
6
+ let cancelled = false;
7
+ return {
8
+ cancelSignal: (callback) => {
9
+ callbacks.push(callback);
10
+ if (cancelled) {
11
+ callback();
12
+ }
13
+ },
14
+ cancel: () => {
15
+ if (cancelled) {
16
+ return;
17
+ }
18
+ callbacks.forEach((cb) => {
19
+ cb();
20
+ });
21
+ cancelled = true;
22
+ },
23
+ };
24
+ };
25
+ exports.makeCancelSignal = makeCancelSignal;
@@ -30,8 +30,8 @@ const mergeAudioTrackUnlimited = async ({ ffmpegExecutable, outName, files, numb
30
30
  });
31
31
  return;
32
32
  }
33
- // FFMPEG has a limit of 64 tracks that can be merged at once
34
- if (files.length > 64) {
33
+ // In FFMPEG, the total number of left and right tracks that can be merged at one time is limited to 64
34
+ if (files.length >= 32) {
35
35
  const chunked = (0, chunk_1.chunk)(files, 10);
36
36
  const tempPath = (0, tmp_dir_1.tmpDir)('remotion-large-audio-mixing');
37
37
  const chunkNames = await Promise.all(chunked.map(async (chunkFiles, i) => {
@@ -5,4 +5,9 @@ export declare const extractUrlAndSourceFromUrl: (url: string) => {
5
5
  src: string;
6
6
  time: number;
7
7
  };
8
- export declare const startOffthreadVideoServer: (ffmpegExecutable: FfmpegExecutable, downloadDir: string, onDownload: RenderMediaOnDownload, onError: (err: Error) => void) => RequestListener;
8
+ export declare const startOffthreadVideoServer: ({ ffmpegExecutable, downloadDir, onDownload, onError, }: {
9
+ ffmpegExecutable: FfmpegExecutable;
10
+ downloadDir: string;
11
+ onDownload: RenderMediaOnDownload;
12
+ onError: (err: Error) => void;
13
+ }) => RequestListener;
@@ -22,7 +22,7 @@ const extractUrlAndSourceFromUrl = (url) => {
22
22
  return { src, time: parseFloat(time) };
23
23
  };
24
24
  exports.extractUrlAndSourceFromUrl = extractUrlAndSourceFromUrl;
25
- const startOffthreadVideoServer = (ffmpegExecutable, downloadDir, onDownload, onError) => {
25
+ const startOffthreadVideoServer = ({ ffmpegExecutable, downloadDir, onDownload, onError, }) => {
26
26
  return (req, res) => {
27
27
  if (!req.url) {
28
28
  throw new Error('Request came in without URL');
@@ -35,14 +35,15 @@ const startOffthreadVideoServer = (ffmpegExecutable, downloadDir, onDownload, on
35
35
  res.setHeader('access-control-allow-origin', '*');
36
36
  res.setHeader('content-type', 'image/jpg');
37
37
  const { src, time } = (0, exports.extractUrlAndSourceFromUrl)(req.url);
38
+ const to = (0, download_and_map_assets_to_file_1.getSanitizedFilenameForAssetUrl)({ downloadDir, src });
38
39
  (0, download_and_map_assets_to_file_1.startDownloadForSrc)({ src, downloadDir, onDownload }).catch((err) => {
39
40
  onError(new Error(`Error while downloading asset: ${err.stack}`));
40
41
  });
41
- (0, download_and_map_assets_to_file_1.waitForAssetToBeDownloaded)(src)
42
- .then((newSrc) => {
42
+ (0, download_and_map_assets_to_file_1.waitForAssetToBeDownloaded)(src, to)
43
+ .then(() => {
43
44
  return (0, extract_frame_from_video_1.extractFrameFromVideo)({
44
45
  time,
45
- src: newSrc,
46
+ src: to,
46
47
  ffmpegExecutable,
47
48
  });
48
49
  })
@@ -10,9 +10,9 @@ export declare type ChromiumOptions = {
10
10
  };
11
11
  export declare const killAllBrowsers: () => Promise<void>;
12
12
  export declare const openBrowser: (browser: Browser, options?: {
13
- shouldDumpIo?: boolean | undefined;
14
- browserExecutable?: string | null | undefined;
15
- chromiumOptions?: ChromiumOptions | undefined;
16
- forceDeviceScaleFactor?: number | undefined;
17
- } | undefined) => Promise<puppeteer.Browser>;
13
+ shouldDumpIo?: boolean;
14
+ browserExecutable?: string | null;
15
+ chromiumOptions?: ChromiumOptions;
16
+ forceDeviceScaleFactor?: number;
17
+ }) => Promise<puppeteer.Browser>;
18
18
  export {};
@@ -98,6 +98,7 @@ const openBrowser = async (browser, options) => {
98
98
  '--hide-scrollbars',
99
99
  '--no-default-browser-check',
100
100
  '--no-pings',
101
+ '--font-render-hinting=none',
101
102
  '--no-zygote',
102
103
  (options === null || options === void 0 ? void 0 : options.forceDeviceScaleFactor)
103
104
  ? `--force-device-scale-factor=${options.forceDeviceScaleFactor}`
@@ -115,7 +116,7 @@ const openBrowser = async (browser, options) => {
115
116
  ].filter(Boolean),
116
117
  });
117
118
  const pages = await browserInstance.pages();
118
- pages.forEach((p) => p.close());
119
+ await pages[0].close();
119
120
  browserInstances.push(browserInstance);
120
121
  return browserInstance;
121
122
  };
@@ -1,11 +1,12 @@
1
1
  import { FfmpegExecutable } from 'remotion';
2
2
  import { RenderMediaOnDownload } from './assets/download-and-map-assets-to-file';
3
- export declare const prepareServer: ({ downloadDir, ffmpegExecutable, onDownload, onError, webpackConfigOrServeUrl, }: {
3
+ export declare const prepareServer: ({ downloadDir, ffmpegExecutable, onDownload, onError, webpackConfigOrServeUrl, port, }: {
4
4
  webpackConfigOrServeUrl: string;
5
5
  downloadDir: string;
6
6
  onDownload: RenderMediaOnDownload;
7
7
  onError: (err: Error) => void;
8
8
  ffmpegExecutable: FfmpegExecutable;
9
+ port: number | null;
9
10
  }) => Promise<{
10
11
  serveUrl: string;
11
12
  closeServer: () => Promise<unknown>;