@remotion/renderer 3.2.44 → 3.3.1

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 (77) hide show
  1. package/dist/assets/download-and-map-assets-to-file.js +7 -7
  2. package/dist/assets/download-file.d.ts +6 -4
  3. package/dist/assets/download-file.js +44 -5
  4. package/dist/assets/get-audio-channels.d.ts +1 -1
  5. package/dist/assets/get-audio-channels.js +5 -4
  6. package/dist/assets/get-video-stream-duration.d.ts +1 -1
  7. package/dist/assets/get-video-stream-duration.js +5 -4
  8. package/dist/browser/Browser.d.ts +4 -2
  9. package/dist/browser/Browser.js +15 -12
  10. package/dist/browser/BrowserFetcher.d.ts +1 -0
  11. package/dist/browser/BrowserFetcher.js +11 -10
  12. package/dist/browser/BrowserPage.d.ts +8 -2
  13. package/dist/browser/BrowserPage.js +7 -10
  14. package/dist/browser/Connection.js +1 -1
  15. package/dist/browser/DOMWorld.d.ts +2 -1
  16. package/dist/browser/DOMWorld.js +8 -1
  17. package/dist/browser/FrameManager.d.ts +0 -2
  18. package/dist/browser/FrameManager.js +0 -3
  19. package/dist/browser/Launcher.d.ts +7 -1
  20. package/dist/browser/Launcher.js +3 -5
  21. package/dist/browser/NodeWebSocketTransport.js +1 -1
  22. package/dist/browser/PuppeteerNode.js +2 -6
  23. package/dist/combine-videos.d.ts +7 -2
  24. package/dist/combine-videos.js +4 -2
  25. package/dist/convert-to-pcm.d.ts +2 -1
  26. package/dist/convert-to-pcm.js +3 -2
  27. package/dist/create-silent-audio.d.ts +2 -1
  28. package/dist/create-silent-audio.js +3 -2
  29. package/dist/cycle-browser-tabs.d.ts +2 -5
  30. package/dist/cycle-browser-tabs.js +5 -5
  31. package/dist/ensure-ffmpeg.d.ts +10 -0
  32. package/dist/ensure-ffmpeg.js +50 -0
  33. package/dist/ensure-presentation-timestamp.d.ts +8 -1
  34. package/dist/ensure-presentation-timestamp.js +14 -5
  35. package/dist/extract-frame-from-video.d.ts +1 -0
  36. package/dist/extract-frame-from-video.js +22 -9
  37. package/dist/ffmpeg-flags.d.ts +16 -1
  38. package/dist/ffmpeg-flags.js +168 -7
  39. package/dist/get-browser-instance.js +1 -1
  40. package/dist/get-compositions.js +10 -6
  41. package/dist/get-extension-from-codec.d.ts +1 -1
  42. package/dist/get-video-info.d.ts +1 -1
  43. package/dist/get-video-info.js +5 -4
  44. package/dist/guess-extension-for-media.d.ts +5 -1
  45. package/dist/guess-extension-for-media.js +3 -2
  46. package/dist/index.d.ts +8 -3
  47. package/dist/index.js +7 -1
  48. package/dist/last-frame-from-video-cache.d.ts +1 -0
  49. package/dist/merge-audio-track.d.ts +1 -0
  50. package/dist/merge-audio-track.js +7 -2
  51. package/dist/offthread-video-server.d.ts +2 -1
  52. package/dist/offthread-video-server.js +2 -1
  53. package/dist/open-browser.js +1 -1
  54. package/dist/prepare-server.d.ts +2 -1
  55. package/dist/prepare-server.js +3 -1
  56. package/dist/preprocess-audio-track.d.ts +1 -0
  57. package/dist/preprocess-audio-track.js +4 -3
  58. package/dist/prespawn-ffmpeg.d.ts +1 -1
  59. package/dist/prespawn-ffmpeg.js +4 -3
  60. package/dist/puppeteer-screenshot.js +1 -1
  61. package/dist/render-frames.js +43 -28
  62. package/dist/render-media.d.ts +1 -0
  63. package/dist/render-media.js +4 -2
  64. package/dist/render-still.js +3 -1
  65. package/dist/replace-browser.d.ts +1 -1
  66. package/dist/replace-browser.js +3 -2
  67. package/dist/screenshot-task.d.ts +1 -1
  68. package/dist/screenshot-task.js +3 -3
  69. package/dist/seek-to-frame.d.ts +1 -0
  70. package/dist/seek-to-frame.js +24 -3
  71. package/dist/serve-static.d.ts +1 -0
  72. package/dist/serve-static.js +1 -0
  73. package/dist/stitch-frames-to-video.d.ts +7 -0
  74. package/dist/stitch-frames-to-video.js +55 -24
  75. package/dist/validate-ffmpeg.d.ts +4 -2
  76. package/dist/validate-ffmpeg.js +35 -46
  77. package/package.json +3 -3
@@ -8,17 +8,19 @@ exports.combineVideos = void 0;
8
8
  const execa_1 = __importDefault(require("execa"));
9
9
  const fs_1 = require("fs");
10
10
  const path_1 = require("path");
11
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
11
12
  const get_audio_codec_name_1 = require("./get-audio-codec-name");
12
13
  const is_audio_codec_1 = require("./is-audio-codec");
13
14
  const parse_ffmpeg_progress_1 = require("./parse-ffmpeg-progress");
14
15
  const truthy_1 = require("./truthy");
15
- const combineVideos = async ({ files, filelistDir, output, onProgress, numberOfFrames, codec, fps, numberOfGifLoops, }) => {
16
+ const combineVideos = async (options) => {
16
17
  var _a;
18
+ const { files, filelistDir, output, onProgress, numberOfFrames, codec, fps, numberOfGifLoops, ffmpegExecutable, remotionRoot, } = options;
17
19
  const fileList = files.map((p) => `file '${p}'`).join('\n');
18
20
  const fileListTxt = (0, path_1.join)(filelistDir, 'files.txt');
19
21
  (0, fs_1.writeFileSync)(fileListTxt, fileList);
20
22
  try {
21
- const task = (0, execa_1.default)('ffmpeg', [
23
+ const task = (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), [
22
24
  (0, is_audio_codec_1.isAudioCodec)(codec) ? null : '-r',
23
25
  (0, is_audio_codec_1.isAudioCodec)(codec) ? null : String(fps),
24
26
  '-f',
@@ -1,6 +1,7 @@
1
1
  import type { FfmpegExecutable } from './ffmpeg-executable';
2
- export declare const convertToPcm: ({ ffmpegExecutable, input, outName, }: {
2
+ export declare const convertToPcm: ({ ffmpegExecutable, input, outName, remotionRoot, }: {
3
3
  ffmpegExecutable: FfmpegExecutable;
4
4
  input: string;
5
5
  outName: string;
6
+ remotionRoot: string;
6
7
  }) => Promise<void>;
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.convertToPcm = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
8
9
  const sample_rate_1 = require("./sample-rate");
9
- const convertToPcm = async ({ ffmpegExecutable, input, outName, }) => {
10
- await (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
10
+ const convertToPcm = async ({ ffmpegExecutable, input, outName, remotionRoot, }) => {
11
+ await (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), [
11
12
  '-i',
12
13
  input,
13
14
  '-c:a',
@@ -1,6 +1,7 @@
1
1
  import type { FfmpegExecutable } from './ffmpeg-executable';
2
- export declare const createSilentAudio: ({ ffmpegExecutable, numberOfSeconds, outName, }: {
2
+ export declare const createSilentAudio: ({ ffmpegExecutable, numberOfSeconds, outName, remotionRoot, }: {
3
3
  ffmpegExecutable: FfmpegExecutable;
4
4
  numberOfSeconds: number;
5
5
  outName: string;
6
+ remotionRoot: string;
6
7
  }) => Promise<void>;
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createSilentAudio = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
8
9
  const sample_rate_1 = require("./sample-rate");
9
- const createSilentAudio = async ({ ffmpegExecutable, numberOfSeconds, outName, }) => {
10
- await (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
10
+ const createSilentAudio = async ({ ffmpegExecutable, numberOfSeconds, outName, remotionRoot, }) => {
11
+ await (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), [
11
12
  '-f',
12
13
  'lavfi',
13
14
  '-i',
@@ -1,7 +1,4 @@
1
- import type { openBrowser } from './open-browser';
2
- declare type Await<T> = T extends PromiseLike<infer U> ? U : T;
3
- declare type Browser = Await<ReturnType<typeof openBrowser>>;
4
- export declare const cycleBrowserTabs: (puppeteerInstance: Browser, concurrency: number) => {
1
+ import type { BrowserReplacer } from './replace-browser';
2
+ export declare const cycleBrowserTabs: (puppeteerInstance: BrowserReplacer, concurrency: number) => {
5
3
  stopCycling: () => void;
6
4
  };
7
- export {};
@@ -13,24 +13,24 @@ const cycleBrowserTabs = (puppeteerInstance, concurrency) => {
13
13
  const set = () => {
14
14
  interval = setTimeout(() => {
15
15
  puppeteerInstance
16
+ .getBrowser()
16
17
  .pages()
17
18
  .then((pages) => {
18
- var _a;
19
19
  if (pages.length === 0) {
20
20
  return;
21
21
  }
22
22
  const currentPage = pages[i % pages.length];
23
23
  i++;
24
- if (!((_a = currentPage === null || currentPage === void 0 ? void 0 : currentPage.isClosed) === null || _a === void 0 ? void 0 : _a.call(currentPage)) &&
24
+ if (!(currentPage === null || currentPage === void 0 ? void 0 : currentPage.closed) &&
25
25
  !stopped &&
26
26
  (currentPage === null || currentPage === void 0 ? void 0 : currentPage.url()) !== 'about:blank') {
27
27
  return currentPage.bringToFront();
28
28
  }
29
29
  })
30
- .then(() => {
30
+ .catch((err) => console.log(err))
31
+ .finally(() => {
31
32
  set();
32
- })
33
- .catch((err) => console.log(err));
33
+ });
34
34
  }, 200);
35
35
  };
36
36
  set();
@@ -0,0 +1,10 @@
1
+ export declare type EnsureFfmpegOptions = {
2
+ remotionRoot?: string;
3
+ };
4
+ declare type Result = {
5
+ result: 'found-in-path' | 'found-in-node-modules' | 'installed';
6
+ wasAlreadyInstalled: boolean;
7
+ };
8
+ export declare const ensureFfmpeg: (options?: EnsureFfmpegOptions) => Promise<Result>;
9
+ export declare const ensureFfprobe: (options?: EnsureFfmpegOptions) => Promise<Result>;
10
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ensureFfprobe = exports.ensureFfmpeg = void 0;
7
+ const fs_1 = require("fs");
8
+ const os_1 = __importDefault(require("os"));
9
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
10
+ const validate_ffmpeg_1 = require("./validate-ffmpeg");
11
+ const ensureFfmpegOrFfprobe = async (binary, options) => {
12
+ var _a;
13
+ const exists = (0, validate_ffmpeg_1.binaryExists)(binary);
14
+ const remotionRoot = (_a = options === null || options === void 0 ? void 0 : options.remotionRoot) !== null && _a !== void 0 ? _a : process.cwd();
15
+ if (exists) {
16
+ return {
17
+ wasAlreadyInstalled: true,
18
+ result: 'found-in-path',
19
+ };
20
+ }
21
+ if (process.platform === 'linux' && (0, fs_1.existsSync)(ffmpeg_flags_1.lambdaFfmpegPaths[binary])) {
22
+ return {
23
+ wasAlreadyInstalled: true,
24
+ result: 'found-in-path',
25
+ };
26
+ }
27
+ if ((0, ffmpeg_flags_1.ffmpegInNodeModules)(remotionRoot, binary)) {
28
+ return {
29
+ result: 'found-in-node-modules',
30
+ wasAlreadyInstalled: true,
31
+ };
32
+ }
33
+ const binaryUrl = (0, ffmpeg_flags_1.getBinaryDownloadUrl)(binary);
34
+ if (binaryUrl) {
35
+ await (0, ffmpeg_flags_1.downloadBinary)(remotionRoot, binaryUrl.url, binary);
36
+ return {
37
+ result: 'installed',
38
+ wasAlreadyInstalled: false,
39
+ };
40
+ }
41
+ throw new Error(`${binary} could not be installed automatically. Your architecture and OS combination (os = ${os_1.default.platform()}, arch = ${process.arch}) is not supported. Please install ${binary} manually and add "${binary}" to your PATH.`);
42
+ };
43
+ const ensureFfmpeg = (options) => {
44
+ return ensureFfmpegOrFfprobe('ffmpeg', options);
45
+ };
46
+ exports.ensureFfmpeg = ensureFfmpeg;
47
+ const ensureFfprobe = (options) => {
48
+ return ensureFfmpegOrFfprobe('ffprobe', options);
49
+ };
50
+ exports.ensureFfprobe = ensureFfprobe;
@@ -1,2 +1,9 @@
1
1
  import type { DownloadMap } from './assets/download-map';
2
- export declare const ensurePresentationTimestamps: (downloadMap: DownloadMap, src: string) => Promise<string>;
2
+ import type { FfmpegExecutable } from './ffmpeg-executable';
3
+ export declare const ensurePresentationTimestamps: ({ downloadMap, src, remotionRoot, ffmpegExecutable, ffprobeExecutable, }: {
4
+ downloadMap: DownloadMap;
5
+ src: string;
6
+ remotionRoot: string;
7
+ ffmpegExecutable: FfmpegExecutable;
8
+ ffprobeExecutable: FfmpegExecutable;
9
+ }) => Promise<string>;
@@ -6,16 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ensurePresentationTimestamps = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
8
  const path_1 = __importDefault(require("path"));
9
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
9
10
  const guess_extension_for_media_1 = require("./guess-extension-for-media");
10
11
  const truthy_1 = require("./truthy");
11
12
  let callbacks = [];
12
- const getTemporaryOutputName = async (src) => {
13
+ const getTemporaryOutputName = async ({ src, remotionRoot, ffprobeBinary, }) => {
13
14
  const parts = src.split(path_1.default.sep);
14
15
  // If there is no file extension for the video, then we need to temporarily add an extension
15
16
  const lastPart = parts[parts.length - 1];
16
17
  const extraExtension = lastPart.includes('.')
17
18
  ? null
18
- : await (0, guess_extension_for_media_1.guessExtensionForVideo)(src);
19
+ : await (0, guess_extension_for_media_1.guessExtensionForVideo)({
20
+ src,
21
+ remotionRoot,
22
+ ffprobeBinary,
23
+ });
19
24
  return parts
20
25
  .map((p, i) => {
21
26
  if (i === parts.length - 1) {
@@ -25,7 +30,7 @@ const getTemporaryOutputName = async (src) => {
25
30
  })
26
31
  .join(path_1.default.sep);
27
32
  };
28
- const ensurePresentationTimestamps = async (downloadMap, src) => {
33
+ const ensurePresentationTimestamps = async ({ downloadMap, src, remotionRoot, ffmpegExecutable, ffprobeExecutable, }) => {
29
34
  const elem = downloadMap.ensureFileHasPresentationTimestamp[src];
30
35
  if ((elem === null || elem === void 0 ? void 0 : elem.type) === 'encoding') {
31
36
  return new Promise((resolve) => {
@@ -40,8 +45,12 @@ const ensurePresentationTimestamps = async (downloadMap, src) => {
40
45
  }
41
46
  downloadMap.ensureFileHasPresentationTimestamp[src] = { type: 'encoding' };
42
47
  // If there is no file extension for the video, then we need to tempoa
43
- const output = await getTemporaryOutputName(src);
44
- await (0, execa_1.default)('ffmpeg', [
48
+ const output = await getTemporaryOutputName({
49
+ src,
50
+ remotionRoot,
51
+ ffprobeBinary: ffprobeExecutable,
52
+ });
53
+ await (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), [
45
54
  '-i',
46
55
  src,
47
56
  '-fflags',
@@ -11,6 +11,7 @@ declare type Options = {
11
11
  ffprobeExecutable: FfmpegExecutable;
12
12
  imageFormat: OffthreadVideoImageFormat;
13
13
  downloadMap: DownloadMap;
14
+ remotionRoot: string;
14
15
  };
15
16
  export declare const extractFrameFromVideo: (options: Options) => Promise<Buffer>;
16
17
  export {};
@@ -7,6 +7,7 @@ exports.extractFrameFromVideo = exports.getLastFrameOfVideo = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
8
  const get_video_stream_duration_1 = require("./assets/get-video-stream-duration");
9
9
  const ensure_presentation_timestamp_1 = require("./ensure-presentation-timestamp");
10
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
10
11
  const frame_to_ffmpeg_timestamp_1 = require("./frame-to-ffmpeg-timestamp");
11
12
  const get_video_info_1 = require("./get-video-info");
12
13
  const is_beyond_last_frame_1 = require("./is-beyond-last-frame");
@@ -32,7 +33,7 @@ const determineResizeParams = (needsResize) => {
32
33
  };
33
34
  // Uses no seeking, therefore the whole video has to be decoded. This is a last resort and should only happen
34
35
  // if the video is corrupted
35
- const getFrameOfVideoSlow = async ({ src, duration, ffmpegExecutable, imageFormat, specialVCodecForTransparency, needsResize, offset, fps, }) => {
36
+ const getFrameOfVideoSlow = async ({ src, duration, ffmpegExecutable, imageFormat, specialVCodecForTransparency, needsResize, offset, fps, remotionRoot, }) => {
36
37
  console.warn(`\nUsing a slow method to extract the frame at ${duration}ms of ${src}. See https://remotion.dev/docs/slow-method-to-extract-frame for advice`);
37
38
  const actualOffset = `-${duration * 1000 - offset}ms`;
38
39
  const command = [
@@ -50,7 +51,7 @@ const getFrameOfVideoSlow = async ({ src, duration, ffmpegExecutable, imageForma
50
51
  ...determineResizeParams(needsResize),
51
52
  '-',
52
53
  ].filter(truthy_1.truthy);
53
- const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', command);
54
+ const { stdout, stderr } = (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), command);
54
55
  if (!stderr) {
55
56
  throw new Error('unexpectedly did not get stderr');
56
57
  }
@@ -85,6 +86,7 @@ const getFrameOfVideoSlow = async ({ src, duration, ffmpegExecutable, imageForma
85
86
  specialVCodecForTransparency,
86
87
  needsResize,
87
88
  fps,
89
+ remotionRoot,
88
90
  });
89
91
  }
90
92
  return stdoutBuffer;
@@ -95,7 +97,7 @@ const getLastFrameOfVideoFastUnlimited = async (options) => {
95
97
  if (fromCache) {
96
98
  return fromCache;
97
99
  }
98
- const { duration, fps } = await (0, get_video_stream_duration_1.getVideoStreamDuration)(downloadMap, src, ffprobeExecutable);
100
+ const { duration, fps } = await (0, get_video_stream_duration_1.getVideoStreamDuration)(downloadMap, src, ffprobeExecutable, options.remotionRoot);
99
101
  if (duration === null) {
100
102
  throw new Error(`Could not determine the duration of ${src} using FFMPEG. The file is not supported.`);
101
103
  }
@@ -109,11 +111,12 @@ const getLastFrameOfVideoFastUnlimited = async (options) => {
109
111
  needsResize: options.needsResize,
110
112
  offset: offset - 1000 / (fps === null ? 10 : fps),
111
113
  fps,
114
+ remotionRoot: options.remotionRoot,
112
115
  });
113
116
  return last;
114
117
  }
115
118
  const actualOffset = `${duration * 1000 - offset}ms`;
116
- const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
119
+ const { stdout, stderr } = (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, options.remotionRoot, 'ffmpeg'), [
117
120
  '-ss',
118
121
  actualOffset,
119
122
  ...determineVcodecFfmepgFlags(options.specialVCodecForTransparency),
@@ -165,6 +168,7 @@ const getLastFrameOfVideoFastUnlimited = async (options) => {
165
168
  specialVCodecForTransparency: options.specialVCodecForTransparency,
166
169
  needsResize: options.needsResize,
167
170
  downloadMap: options.downloadMap,
171
+ remotionRoot: options.remotionRoot,
168
172
  });
169
173
  return unlimited;
170
174
  }
@@ -176,13 +180,19 @@ const getLastFrameOfVideo = async (options) => {
176
180
  return result;
177
181
  };
178
182
  exports.getLastFrameOfVideo = getLastFrameOfVideo;
179
- const extractFrameFromVideoFn = async ({ time, ffmpegExecutable, ffprobeExecutable, imageFormat, downloadMap, ...options }) => {
183
+ const extractFrameFromVideoFn = async ({ time, ffmpegExecutable, ffprobeExecutable, imageFormat, downloadMap, remotionRoot, ...options }) => {
180
184
  // We make a new copy of the video only for video because the conversion may affect
181
185
  // audio rendering, so we work with 2 different files
182
- const src = await (0, ensure_presentation_timestamp_1.ensurePresentationTimestamps)(downloadMap, options.src);
183
- const { specialVcodec, needsResize } = await (0, get_video_info_1.getVideoInfo)(downloadMap, src, ffprobeExecutable);
186
+ const src = await (0, ensure_presentation_timestamp_1.ensurePresentationTimestamps)({
187
+ downloadMap,
188
+ src: options.src,
189
+ remotionRoot,
190
+ ffmpegExecutable,
191
+ ffprobeExecutable,
192
+ });
193
+ const { specialVcodec, needsResize } = await (0, get_video_info_1.getVideoInfo)(downloadMap, src, ffprobeExecutable, remotionRoot);
184
194
  if (specialVcodec === 'vp8') {
185
- const { fps } = await (0, get_video_stream_duration_1.getVideoStreamDuration)(downloadMap, src, ffprobeExecutable);
195
+ const { fps } = await (0, get_video_stream_duration_1.getVideoStreamDuration)(downloadMap, src, ffprobeExecutable, remotionRoot);
186
196
  return getFrameOfVideoSlow({
187
197
  ffmpegExecutable,
188
198
  imageFormat,
@@ -192,6 +202,7 @@ const extractFrameFromVideoFn = async ({ time, ffmpegExecutable, ffprobeExecutab
192
202
  needsResize,
193
203
  offset: 0,
194
204
  fps,
205
+ remotionRoot,
195
206
  });
196
207
  }
197
208
  if ((0, is_beyond_last_frame_1.isBeyondLastFrame)(downloadMap, src, time)) {
@@ -204,11 +215,12 @@ const extractFrameFromVideoFn = async ({ time, ffmpegExecutable, ffprobeExecutab
204
215
  specialVCodecForTransparency: specialVcodec,
205
216
  needsResize,
206
217
  downloadMap,
218
+ remotionRoot,
207
219
  });
208
220
  return lastFrame;
209
221
  }
210
222
  const ffmpegTimestamp = (0, frame_to_ffmpeg_timestamp_1.frameToFfmpegTimestamp)(time);
211
- const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
223
+ const { stdout, stderr } = (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), [
212
224
  '-ss',
213
225
  ffmpegTimestamp,
214
226
  ...determineVcodecFfmepgFlags(specialVcodec),
@@ -258,6 +270,7 @@ const extractFrameFromVideoFn = async ({ time, ffmpegExecutable, ffprobeExecutab
258
270
  specialVCodecForTransparency: specialVcodec,
259
271
  needsResize,
260
272
  downloadMap,
273
+ remotionRoot,
261
274
  });
262
275
  return last;
263
276
  }
@@ -1,15 +1,30 @@
1
+ import type { FfmpegExecutable } from './ffmpeg-executable';
1
2
  export declare type FfmpegVersion = [number, number, number] | null;
2
3
  export declare const getFfmpegBuildInfo: (options: {
3
4
  ffmpegExecutable: string | null;
5
+ remotionRoot: string;
4
6
  }) => Promise<string>;
5
- export declare const ffmpegHasFeature: ({ ffmpegExecutable, feature, }: {
7
+ export declare const ffmpegInNodeModules: (remotionRoot: string, binary: 'ffmpeg' | 'ffprobe') => string | null;
8
+ export declare const ffmpegHasFeature: ({ ffmpegExecutable, feature, remotionRoot, }: {
6
9
  ffmpegExecutable: string | null;
7
10
  feature: 'enable-gpl' | 'enable-libx265' | 'enable-libvpx';
11
+ remotionRoot: string;
8
12
  }) => Promise<boolean>;
9
13
  export declare const parseFfmpegVersion: (buildconf: string) => FfmpegVersion;
10
14
  export declare const getFfmpegVersion: (options: {
11
15
  ffmpegExecutable: string | null;
16
+ remotionRoot: string;
12
17
  }) => Promise<FfmpegVersion>;
18
+ export declare const downloadBinary: (remotionRoot: string, url: string, binary: 'ffmpeg' | 'ffprobe') => Promise<string>;
19
+ export declare const lambdaFfmpegPaths: {
20
+ readonly ffmpeg: "/opt/bin/ffmpeg";
21
+ readonly ffprobe: "/opt/bin/ffprobe";
22
+ };
23
+ export declare const getExecutableBinary: (ffmpegExecutable: FfmpegExecutable, remotionRoot: string, binary: 'ffmpeg' | 'ffprobe') => string | Promise<string>;
24
+ export declare const getBinaryDownloadUrl: (binary: 'ffmpeg' | 'ffprobe') => {
25
+ url: string;
26
+ contentLength: number;
27
+ } | null;
13
28
  export declare const warnAboutFfmpegVersion: ({ ffmpegVersion, buildConf, }: {
14
29
  ffmpegVersion: FfmpegVersion;
15
30
  buildConf: string | null;
@@ -3,27 +3,79 @@ 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.warnAboutFfmpegVersion = exports.getFfmpegVersion = exports.parseFfmpegVersion = exports.ffmpegHasFeature = exports.getFfmpegBuildInfo = void 0;
6
+ exports.warnAboutFfmpegVersion = exports.getBinaryDownloadUrl = exports.getExecutableBinary = exports.lambdaFfmpegPaths = exports.downloadBinary = exports.getFfmpegVersion = exports.parseFfmpegVersion = exports.ffmpegHasFeature = exports.ffmpegInNodeModules = exports.getFfmpegBuildInfo = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const os_1 = __importDefault(require("os"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const BrowserFetcher_1 = require("./browser/BrowserFetcher");
8
12
  const validate_ffmpeg_1 = require("./validate-ffmpeg");
9
13
  let buildConfig = null;
14
+ const listeners = {};
15
+ const isDownloading = {};
10
16
  const getFfmpegBuildInfo = async (options) => {
11
- var _a;
12
17
  if (buildConfig !== null) {
13
18
  return buildConfig;
14
19
  }
15
- const data = await (0, execa_1.default)((_a = options.ffmpegExecutable) !== null && _a !== void 0 ? _a : 'ffmpeg', ['-buildconf'], {
20
+ const data = await (0, execa_1.default)(await (0, exports.getExecutableBinary)(options.ffmpegExecutable, options.remotionRoot, 'ffmpeg'), ['-buildconf'], {
16
21
  reject: false,
17
22
  });
18
23
  buildConfig = data.stderr;
19
24
  return buildConfig;
20
25
  };
21
26
  exports.getFfmpegBuildInfo = getFfmpegBuildInfo;
22
- const ffmpegHasFeature = async ({ ffmpegExecutable, feature, }) => {
23
- if (!(0, validate_ffmpeg_1.binaryExists)('ffmpeg', ffmpegExecutable)) {
27
+ const getFfmpegFolderName = (remotionRoot) => {
28
+ return path_1.default.resolve(remotionRoot, 'node_modules/.ffmpeg');
29
+ };
30
+ const binaryPrefix = { ffmpeg: 'ffmpeg-', ffprobe: 'ffprobe-' };
31
+ const randomFfmpegRuntimeId = String(Math.random()).replace('0.', '');
32
+ const ffmpegInNodeModules = (remotionRoot, binary) => {
33
+ const folderName = getFfmpegFolderName(remotionRoot);
34
+ if (!fs_1.default.existsSync(folderName)) {
35
+ fs_1.default.mkdirSync(folderName);
36
+ }
37
+ // Check if a version of FFMPEG is already installed.
38
+ // To qualify, it must have the expected file size
39
+ // to avoid finding binaries that are still being downloaded
40
+ // A random ID is being assigned to the download to avoid conflicts when multiple Remotion processes are running
41
+ const ffmpegInstalled = fs_1.default.readdirSync(folderName).find((filename) => {
42
+ if (!filename.startsWith(binaryPrefix[binary])) {
43
+ return false;
44
+ }
45
+ const dlUrl = (0, exports.getBinaryDownloadUrl)(binary);
46
+ if (!dlUrl) {
47
+ return false;
48
+ }
49
+ const expectedLength = dlUrl.contentLength;
50
+ if (fs_1.default.statSync(path_1.default.join(folderName, filename)).size === expectedLength) {
51
+ return true;
52
+ }
24
53
  return false;
54
+ });
55
+ if (ffmpegInstalled) {
56
+ return path_1.default.join(folderName, ffmpegInstalled);
25
57
  }
26
- const config = await (0, exports.getFfmpegBuildInfo)({ ffmpegExecutable });
58
+ return null;
59
+ };
60
+ exports.ffmpegInNodeModules = ffmpegInNodeModules;
61
+ const getFfmpegAbsolutePath = (remotionRoot, binary) => {
62
+ const folderName = getFfmpegFolderName(remotionRoot);
63
+ if (!fs_1.default.existsSync(folderName)) {
64
+ fs_1.default.mkdirSync(folderName);
65
+ }
66
+ if (os_1.default.platform() === 'win32') {
67
+ return path_1.default.resolve(folderName, `${binaryPrefix[binary]}${randomFfmpegRuntimeId}.exe`);
68
+ }
69
+ return path_1.default.resolve(folderName, `${binaryPrefix[binary]}${randomFfmpegRuntimeId}`);
70
+ };
71
+ const ffmpegHasFeature = async ({ ffmpegExecutable, feature, remotionRoot, }) => {
72
+ if (ffmpegExecutable && !(0, validate_ffmpeg_1.customExecutableExists)(ffmpegExecutable)) {
73
+ return false;
74
+ }
75
+ if (!(0, validate_ffmpeg_1.binaryExists)('ffmpeg')) {
76
+ return false;
77
+ }
78
+ const config = await (0, exports.getFfmpegBuildInfo)({ ffmpegExecutable, remotionRoot });
27
79
  return config.includes(feature);
28
80
  };
29
81
  exports.ffmpegHasFeature = ffmpegHasFeature;
@@ -39,13 +91,122 @@ exports.parseFfmpegVersion = parseFfmpegVersion;
39
91
  const getFfmpegVersion = async (options) => {
40
92
  const buildInfo = await (0, exports.getFfmpegBuildInfo)({
41
93
  ffmpegExecutable: options.ffmpegExecutable,
94
+ remotionRoot: options.remotionRoot,
42
95
  });
43
96
  return (0, exports.parseFfmpegVersion)(buildInfo);
44
97
  };
45
98
  exports.getFfmpegVersion = getFfmpegVersion;
99
+ const waitForFfmpegToBeDownloaded = (url) => {
100
+ return new Promise((resolve) => {
101
+ if (!listeners[url]) {
102
+ listeners[url] = [];
103
+ }
104
+ listeners[url].push((src) => resolve(src));
105
+ });
106
+ };
107
+ const onProgress = (downloadedBytes, totalBytesToDownload, binary) => {
108
+ console.log('Downloading ', binary, `${toMegabytes(downloadedBytes)}/${toMegabytes(totalBytesToDownload)}`);
109
+ };
110
+ const downloadBinary = async (remotionRoot, url, binary) => {
111
+ const destinationPath = getFfmpegAbsolutePath(remotionRoot, binary);
112
+ const onProgressCallback = (downloadedBytes, _totalBytes) => {
113
+ onProgress(downloadedBytes, _totalBytes, binary);
114
+ };
115
+ isDownloading[url] = true;
116
+ const totalBytes = await (0, BrowserFetcher_1._downloadFile)(url, destinationPath, onProgressCallback);
117
+ onProgress(totalBytes, totalBytes, binary);
118
+ if (os_1.default.platform() !== 'win32') {
119
+ fs_1.default.chmodSync(destinationPath, '777');
120
+ }
121
+ isDownloading[url] = false;
122
+ if (!listeners[url]) {
123
+ listeners[url] = [];
124
+ }
125
+ listeners[url].forEach((listener) => listener(destinationPath));
126
+ listeners[url] = [];
127
+ return destinationPath;
128
+ };
129
+ exports.downloadBinary = downloadBinary;
130
+ exports.lambdaFfmpegPaths = {
131
+ ffmpeg: '/opt/bin/ffmpeg',
132
+ ffprobe: '/opt/bin/ffprobe',
133
+ };
134
+ const getExecutableBinary = (ffmpegExecutable, remotionRoot, binary) => {
135
+ if (fs_1.default.existsSync(exports.lambdaFfmpegPaths[binary])) {
136
+ return exports.lambdaFfmpegPaths[binary];
137
+ }
138
+ if (ffmpegExecutable && (0, validate_ffmpeg_1.customExecutableExists)(ffmpegExecutable)) {
139
+ return ffmpegExecutable;
140
+ }
141
+ if ((0, validate_ffmpeg_1.binaryExists)(binary)) {
142
+ return binary;
143
+ }
144
+ const dlUrl = (0, exports.getBinaryDownloadUrl)(binary);
145
+ if (dlUrl && isDownloading[dlUrl.url]) {
146
+ return waitForFfmpegToBeDownloaded(dlUrl.url);
147
+ }
148
+ const inNodeMod = (0, exports.ffmpegInNodeModules)(remotionRoot, binary);
149
+ if (inNodeMod) {
150
+ return inNodeMod;
151
+ }
152
+ if (!dlUrl) {
153
+ throw new Error(`${binary} could not be installed automatically. Your architecture and OS combination (os = ${os_1.default.platform()}, arch = ${process.arch}) is not supported. Please install ${binary} manually and add "${binary}" to your PATH.`);
154
+ }
155
+ return (0, exports.downloadBinary)(remotionRoot, dlUrl.url, binary);
156
+ };
157
+ exports.getExecutableBinary = getExecutableBinary;
158
+ function toMegabytes(bytes) {
159
+ const mb = bytes / 1024 / 1024;
160
+ return `${Math.round(mb * 10) / 10} Mb`;
161
+ }
162
+ const getBinaryDownloadUrl = (binary) => {
163
+ if (os_1.default.platform() === 'win32') {
164
+ return binary === 'ffmpeg'
165
+ ? {
166
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffmpeg-win-x86.exe',
167
+ contentLength: 127531008,
168
+ }
169
+ : {
170
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffprobe-win-x86.exe',
171
+ contentLength: 127425536,
172
+ };
173
+ }
174
+ if (os_1.default.platform() === 'darwin') {
175
+ if (process.arch === 'arm64') {
176
+ return binary === 'ffmpeg'
177
+ ? {
178
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffmpeg-macos-arm64',
179
+ contentLength: 42093320,
180
+ }
181
+ : {
182
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffprobe-macos-arm64',
183
+ contentLength: 46192536,
184
+ };
185
+ }
186
+ return binary === 'ffmpeg'
187
+ ? {
188
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffmpeg-macos-x86',
189
+ contentLength: 78380700,
190
+ }
191
+ : {
192
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffprobe-macos-x86',
193
+ contentLength: 77364284,
194
+ };
195
+ }
196
+ return binary === 'ffmpeg'
197
+ ? {
198
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffmpeg-linux-amd64',
199
+ contentLength: 78502560,
200
+ }
201
+ : {
202
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffprobe-linux-amd64',
203
+ contentLength: 78400704,
204
+ };
205
+ };
206
+ exports.getBinaryDownloadUrl = getBinaryDownloadUrl;
46
207
  const printMessage = (ffmpegVersion) => {
47
208
  console.warn('⚠️Old FFMPEG version detected: ' + ffmpegVersion.join('.'));
48
- console.warn(' For audio support, you need at least version 4.1.0.');
209
+ console.warn(' You need at least version 4.1.0.');
49
210
  console.warn(' Upgrade FFMPEG to get rid of this warning.');
50
211
  };
51
212
  const printBuildConfMessage = () => {
@@ -26,7 +26,7 @@ const getPageAndCleanupFn = async ({ passedInInstance, browserExecutable, chromi
26
26
  page: browserPage,
27
27
  cleanup: () => {
28
28
  // Close whole browser that was just created and don't wait for it to finish.
29
- browserInstance.close().catch((err) => {
29
+ browserInstance.close(true).catch((err) => {
30
30
  console.error('Was not able to close puppeteer page', err);
31
31
  });
32
32
  },