@remotion/renderer 4.1.0-alpha2 → 4.1.0-alpha4

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 (87) hide show
  1. package/dist/assets/get-video-stream-duration.d.ts +9 -0
  2. package/dist/assets/get-video-stream-duration.js +71 -0
  3. package/dist/browser/Browser.d.ts +7 -6
  4. package/dist/browser/Browser.js +12 -12
  5. package/dist/browser/BrowserPage.d.ts +13 -2
  6. package/dist/browser/BrowserPage.js +15 -8
  7. package/dist/browser/BrowserRunner.js +2 -2
  8. package/dist/browser/LaunchOptions.d.ts +2 -0
  9. package/dist/browser/Launcher.js +2 -1
  10. package/dist/browser/Target.d.ts +2 -1
  11. package/dist/browser/Target.js +3 -1
  12. package/dist/browser/should-log-message.js +8 -0
  13. package/dist/calculate-sar-dar-pixels.d.ts +9 -0
  14. package/dist/calculate-sar-dar-pixels.js +19 -0
  15. package/dist/compositor/compositor.d.ts +3 -2
  16. package/dist/compositor/compositor.js +6 -5
  17. package/dist/cycle-browser-tabs.d.ts +2 -1
  18. package/dist/cycle-browser-tabs.js +2 -2
  19. package/dist/determine-resize-params.d.ts +4 -0
  20. package/dist/determine-resize-params.js +10 -0
  21. package/dist/determine-vcodec-ffmpeg-flags.d.ts +2 -0
  22. package/dist/determine-vcodec-ffmpeg-flags.js +13 -0
  23. package/dist/ensure-ffmpeg.d.ts +18 -0
  24. package/dist/ensure-ffmpeg.js +58 -0
  25. package/dist/ensure-presentation-timestamp.d.ts +15 -0
  26. package/dist/ensure-presentation-timestamp.js +88 -0
  27. package/dist/extract-frame-from-video.d.ts +16 -0
  28. package/dist/extract-frame-from-video.js +191 -0
  29. package/dist/ffmpeg-executable.d.ts +1 -0
  30. package/dist/ffmpeg-executable.js +2 -0
  31. package/dist/ffmpeg-flags.d.ts +31 -0
  32. package/dist/ffmpeg-flags.js +245 -0
  33. package/dist/format-logs.d.ts +3 -0
  34. package/dist/format-logs.js +201 -0
  35. package/dist/frame-to-ffmpeg-timestamp.d.ts +1 -0
  36. package/dist/frame-to-ffmpeg-timestamp.js +8 -0
  37. package/dist/get-browser-instance.d.ts +3 -2
  38. package/dist/get-browser-instance.js +5 -5
  39. package/dist/get-can-extract-frames-fast.d.ts +14 -0
  40. package/dist/get-can-extract-frames-fast.js +71 -0
  41. package/dist/get-compositions.d.ts +4 -3
  42. package/dist/get-compositions.js +6 -5
  43. package/dist/get-frame-of-video-slow.d.ts +17 -0
  44. package/dist/get-frame-of-video-slow.js +72 -0
  45. package/dist/get-video-info.d.ts +8 -0
  46. package/dist/get-video-info.js +59 -0
  47. package/dist/index.d.ts +23 -25
  48. package/dist/is-beyond-last-frame.d.ts +3 -0
  49. package/dist/is-beyond-last-frame.js +12 -0
  50. package/dist/last-frame-from-video-cache.d.ts +17 -0
  51. package/dist/last-frame-from-video-cache.js +55 -0
  52. package/dist/legacy-webpack-config.d.ts +9 -0
  53. package/dist/legacy-webpack-config.js +13 -0
  54. package/dist/logger.d.ts +1 -2
  55. package/dist/logger.js +5 -10
  56. package/dist/offthread-video-server.d.ts +3 -2
  57. package/dist/offthread-video-server.js +4 -3
  58. package/dist/open-browser.d.ts +3 -2
  59. package/dist/open-browser.js +7 -5
  60. package/dist/perf.js +4 -2
  61. package/dist/prepare-server.d.ts +3 -2
  62. package/dist/prepare-server.js +4 -4
  63. package/dist/prespawn-ffmpeg.d.ts +2 -1
  64. package/dist/prespawn-ffmpeg.js +2 -30
  65. package/dist/quality.d.ts +1 -0
  66. package/dist/quality.js +21 -0
  67. package/dist/render-frames.d.ts +11 -4
  68. package/dist/render-frames.js +15 -11
  69. package/dist/render-media.d.ts +11 -4
  70. package/dist/render-media.js +12 -14
  71. package/dist/render-still.d.ts +8 -2
  72. package/dist/render-still.js +8 -8
  73. package/dist/replace-browser.d.ts +2 -1
  74. package/dist/replace-browser.js +2 -2
  75. package/dist/select-composition.d.ts +2 -1
  76. package/dist/select-composition.js +8 -8
  77. package/dist/serve-static.d.ts +2 -1
  78. package/dist/serve-static.js +1 -1
  79. package/dist/stitch-frames-to-video.d.ts +2 -1
  80. package/dist/stitch-frames-to-video.js +12 -22
  81. package/dist/try-to-extract-frame-of-video-fast.d.ts +12 -0
  82. package/dist/try-to-extract-frame-of-video-fast.js +55 -0
  83. package/dist/validate-ffmpeg.d.ts +7 -0
  84. package/dist/validate-ffmpeg.js +77 -0
  85. package/dist/warn-about-ffmpeg-version.d.ts +5 -0
  86. package/dist/warn-about-ffmpeg-version.js +37 -0
  87. package/package.json +9 -9
@@ -0,0 +1,88 @@
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.ensurePresentationTimestamps = exports.ensurePresentationTimestampWithoutCache = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
10
+ const guess_extension_for_media_1 = require("./guess-extension-for-media");
11
+ const truthy_1 = require("./truthy");
12
+ let callbacks = [];
13
+ const getTemporaryOutputName = async ({ src, remotionRoot, ffprobeBinary, }) => {
14
+ const parts = src.split(path_1.default.sep);
15
+ // If there is no file extension for the video, then we need to temporarily add an extension
16
+ const lastPart = parts[parts.length - 1];
17
+ const extraExtension = lastPart.includes('.')
18
+ ? null
19
+ : await (0, guess_extension_for_media_1.guessExtensionForVideo)({
20
+ src,
21
+ remotionRoot,
22
+ ffprobeBinary,
23
+ });
24
+ return parts
25
+ .map((p, i) => {
26
+ if (i === parts.length - 1) {
27
+ return [`pts-${p}`, extraExtension].filter(truthy_1.truthy).join('.');
28
+ }
29
+ return p;
30
+ })
31
+ .join(path_1.default.sep);
32
+ };
33
+ const ensurePresentationTimestampWithoutCache = async ({ src, remotionRoot, ffmpegExecutable, ffprobeExecutable, }) => {
34
+ // If there is no file extension for the video, then we need to tempoa
35
+ const output = await getTemporaryOutputName({
36
+ src,
37
+ remotionRoot,
38
+ ffprobeBinary: ffprobeExecutable,
39
+ });
40
+ await (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), [
41
+ '-i',
42
+ src,
43
+ '-fflags',
44
+ '+genpts+igndts',
45
+ '-vcodec',
46
+ 'copy',
47
+ '-acodec',
48
+ 'copy',
49
+ output,
50
+ '-y',
51
+ ]);
52
+ return output;
53
+ };
54
+ exports.ensurePresentationTimestampWithoutCache = ensurePresentationTimestampWithoutCache;
55
+ const ensurePresentationTimestamps = async ({ downloadMap, src, remotionRoot, ffmpegExecutable, ffprobeExecutable, }) => {
56
+ const elem = downloadMap.ensureFileHasPresentationTimestamp[src];
57
+ if ((elem === null || elem === void 0 ? void 0 : elem.type) === 'encoding') {
58
+ return new Promise((resolve) => {
59
+ callbacks.push({
60
+ src,
61
+ fn: (newSrc) => resolve(newSrc),
62
+ });
63
+ });
64
+ }
65
+ if ((elem === null || elem === void 0 ? void 0 : elem.type) === 'done') {
66
+ return elem.src;
67
+ }
68
+ downloadMap.ensureFileHasPresentationTimestamp[src] = { type: 'encoding' };
69
+ const output = await (0, exports.ensurePresentationTimestampWithoutCache)({
70
+ ffmpegExecutable,
71
+ ffprobeExecutable,
72
+ remotionRoot,
73
+ src,
74
+ });
75
+ callbacks = callbacks.filter((c) => {
76
+ if (c.src === src) {
77
+ c.fn(output);
78
+ return false;
79
+ }
80
+ return true;
81
+ });
82
+ downloadMap.ensureFileHasPresentationTimestamp[src] = {
83
+ type: 'done',
84
+ src: output,
85
+ };
86
+ return output;
87
+ };
88
+ exports.ensurePresentationTimestamps = ensurePresentationTimestamps;
@@ -0,0 +1,16 @@
1
+ import type { OffthreadVideoImageFormat } from 'remotion';
2
+ import type { DownloadMap } from './assets/download-map';
3
+ import type { FfmpegExecutable } from './ffmpeg-executable';
4
+ import type { LastFrameOptions } from './last-frame-from-video-cache';
5
+ export declare const getLastFrameOfVideo: (options: LastFrameOptions) => Promise<Buffer>;
6
+ type Options = {
7
+ time: number;
8
+ src: string;
9
+ ffmpegExecutable: FfmpegExecutable;
10
+ ffprobeExecutable: FfmpegExecutable;
11
+ imageFormat: OffthreadVideoImageFormat;
12
+ downloadMap: DownloadMap;
13
+ remotionRoot: string;
14
+ };
15
+ export declare const extractFrameFromVideo: (options: Options) => Promise<Buffer>;
16
+ export {};
@@ -0,0 +1,191 @@
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.extractFrameFromVideo = exports.getLastFrameOfVideo = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const get_video_stream_duration_1 = require("./assets/get-video-stream-duration");
9
+ const determine_resize_params_1 = require("./determine-resize-params");
10
+ const determine_vcodec_ffmpeg_flags_1 = require("./determine-vcodec-ffmpeg-flags");
11
+ const ensure_presentation_timestamp_1 = require("./ensure-presentation-timestamp");
12
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
13
+ const frame_to_ffmpeg_timestamp_1 = require("./frame-to-ffmpeg-timestamp");
14
+ const get_can_extract_frames_fast_1 = require("./get-can-extract-frames-fast");
15
+ const get_frame_of_video_slow_1 = require("./get-frame-of-video-slow");
16
+ const get_video_info_1 = require("./get-video-info");
17
+ const is_beyond_last_frame_1 = require("./is-beyond-last-frame");
18
+ const last_frame_from_video_cache_1 = require("./last-frame-from-video-cache");
19
+ const p_limit_1 = require("./p-limit");
20
+ const perf_1 = require("./perf");
21
+ const truthy_1 = require("./truthy");
22
+ const try_to_extract_frame_of_video_fast_1 = require("./try-to-extract-frame-of-video-fast");
23
+ const lastFrameLimit = (0, p_limit_1.pLimit)(1);
24
+ const mainLimit = (0, p_limit_1.pLimit)(5);
25
+ const getLastFrameOfVideoFastUnlimited = async (options) => {
26
+ const { ffmpegExecutable, ffprobeExecutable, offset, src, downloadMap } = options;
27
+ const fromCache = (0, last_frame_from_video_cache_1.getLastFrameFromCache)({ ...options, offset: 0 });
28
+ if (fromCache) {
29
+ return fromCache;
30
+ }
31
+ const { duration, fps } = await (0, get_video_stream_duration_1.getVideoStreamDuration)(downloadMap, src, ffprobeExecutable, options.remotionRoot);
32
+ if (duration === null) {
33
+ throw new Error(`Could not determine the duration of ${src} using FFMPEG. The file is not supported.`);
34
+ }
35
+ if (options.specialVCodecForTransparency === 'vp8' ||
36
+ offset > get_can_extract_frames_fast_1.ACCEPTABLE_OFFSET_THRESHOLD) {
37
+ const last = await (0, get_frame_of_video_slow_1.getFrameOfVideoSlow)({
38
+ duration,
39
+ ffmpegExecutable,
40
+ src,
41
+ imageFormat: options.imageFormat,
42
+ specialVCodecForTransparency: options.specialVCodecForTransparency,
43
+ needsResize: options.needsResize,
44
+ offset: offset - 1000 / (fps === null ? 10 : fps),
45
+ fps,
46
+ remotionRoot: options.remotionRoot,
47
+ });
48
+ return last;
49
+ }
50
+ const actualOffset = `${duration * 1000 - offset}ms`;
51
+ const [stdErr, stdoutBuffer] = await (0, try_to_extract_frame_of_video_fast_1.tryToExtractFrameOfVideoFast)({
52
+ actualOffset,
53
+ ffmpegExecutable,
54
+ imageFormat: options.imageFormat,
55
+ needsResize: options.needsResize,
56
+ remotionRoot: options.remotionRoot,
57
+ specialVCodecForTransparency: options.specialVCodecForTransparency,
58
+ src,
59
+ });
60
+ const isEmpty = stdErr.includes('Output file is empty');
61
+ if (isEmpty) {
62
+ const unlimited = await getLastFrameOfVideoFastUnlimited({
63
+ ffmpegExecutable,
64
+ // Decrement in 10ms increments, or 1 frame (e.g. fps = 25 --> 40ms)
65
+ offset: offset + (fps === null ? 10 : 1000 / fps),
66
+ src,
67
+ ffprobeExecutable,
68
+ imageFormat: options.imageFormat,
69
+ specialVCodecForTransparency: options.specialVCodecForTransparency,
70
+ needsResize: options.needsResize,
71
+ downloadMap: options.downloadMap,
72
+ remotionRoot: options.remotionRoot,
73
+ });
74
+ return unlimited;
75
+ }
76
+ return stdoutBuffer;
77
+ };
78
+ const getLastFrameOfVideo = async (options) => {
79
+ const result = await lastFrameLimit(getLastFrameOfVideoFastUnlimited, options);
80
+ (0, last_frame_from_video_cache_1.setLastFrameInCache)(options, result);
81
+ return result;
82
+ };
83
+ exports.getLastFrameOfVideo = getLastFrameOfVideo;
84
+ const extractFrameFromVideoFn = async ({ time, ffmpegExecutable, ffprobeExecutable, imageFormat, downloadMap, remotionRoot, ...options }) => {
85
+ // We make a new copy of the video only for video because the conversion may affect
86
+ // audio rendering, so we work with 2 different files
87
+ const src = await (0, ensure_presentation_timestamp_1.ensurePresentationTimestamps)({
88
+ downloadMap,
89
+ src: options.src,
90
+ remotionRoot,
91
+ ffmpegExecutable,
92
+ ffprobeExecutable,
93
+ });
94
+ const { specialVcodecForTransparency: specialVcodec, needsResize } = await (0, get_video_info_1.getVideoInfo)(downloadMap, src, ffprobeExecutable, remotionRoot);
95
+ if (specialVcodec === 'vp8') {
96
+ const { fps } = await (0, get_video_stream_duration_1.getVideoStreamDuration)(downloadMap, src, ffprobeExecutable, remotionRoot);
97
+ return (0, get_frame_of_video_slow_1.getFrameOfVideoSlow)({
98
+ ffmpegExecutable,
99
+ imageFormat,
100
+ specialVCodecForTransparency: specialVcodec,
101
+ src,
102
+ duration: time,
103
+ needsResize,
104
+ offset: 0,
105
+ fps,
106
+ remotionRoot,
107
+ });
108
+ }
109
+ if ((0, is_beyond_last_frame_1.isBeyondLastFrame)(downloadMap, src, time)) {
110
+ const lastFrame = await (0, exports.getLastFrameOfVideo)({
111
+ ffmpegExecutable,
112
+ ffprobeExecutable,
113
+ offset: 0,
114
+ src,
115
+ imageFormat,
116
+ specialVCodecForTransparency: specialVcodec,
117
+ needsResize,
118
+ downloadMap,
119
+ remotionRoot,
120
+ });
121
+ return lastFrame;
122
+ }
123
+ const ffmpegTimestamp = (0, frame_to_ffmpeg_timestamp_1.frameToFfmpegTimestamp)(time);
124
+ const { stdout, stderr } = (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), [
125
+ '-ss',
126
+ ffmpegTimestamp,
127
+ ...(0, determine_vcodec_ffmpeg_flags_1.determineVcodecFfmpegFlags)(specialVcodec),
128
+ '-i',
129
+ src,
130
+ '-frames:v',
131
+ '1',
132
+ '-f',
133
+ 'image2pipe',
134
+ '-vcodec',
135
+ imageFormat === 'jpeg' ? 'mjpeg' : 'png',
136
+ ...(0, determine_resize_params_1.determineResizeParams)(needsResize),
137
+ '-',
138
+ ].filter(truthy_1.truthy), {
139
+ buffer: false,
140
+ });
141
+ if (!stderr) {
142
+ throw new Error('unexpectedly did not get stderr');
143
+ }
144
+ if (!stdout) {
145
+ throw new Error('unexpectedly did not get stdout');
146
+ }
147
+ const stdoutChunks = [];
148
+ const stderrChunks = [];
149
+ const stderrStringProm = new Promise((resolve, reject) => {
150
+ stderr.on('data', (d) => stderrChunks.push(d));
151
+ stderr.on('error', (err) => reject(err));
152
+ stderr.on('end', () => resolve(Buffer.concat(stderrChunks).toString('utf8')));
153
+ });
154
+ const stdoutBuffer = new Promise((resolve, reject) => {
155
+ stdout.on('data', (d) => stdoutChunks.push(d));
156
+ stdout.on('error', (err) => reject(err));
157
+ stdout.on('end', () => resolve(Buffer.concat(stdoutChunks)));
158
+ });
159
+ const [stderrStr, stdOut] = await Promise.all([
160
+ stderrStringProm,
161
+ stdoutBuffer,
162
+ ]);
163
+ if (stderrStr.includes('Output file is empty')) {
164
+ (0, is_beyond_last_frame_1.markAsBeyondLastFrame)(downloadMap, src, time);
165
+ const last = await (0, exports.getLastFrameOfVideo)({
166
+ ffmpegExecutable,
167
+ ffprobeExecutable,
168
+ offset: 0,
169
+ src,
170
+ imageFormat,
171
+ specialVCodecForTransparency: specialVcodec,
172
+ needsResize,
173
+ downloadMap,
174
+ remotionRoot,
175
+ });
176
+ return last;
177
+ }
178
+ if (stdOut.length === 0) {
179
+ console.log('FFMPEG Logs:');
180
+ console.log(stderrStr);
181
+ throw new Error("Couldn't extract frame from video - FFMPEG did not return any data. Check logs to see more information");
182
+ }
183
+ return stdOut;
184
+ };
185
+ const extractFrameFromVideo = async (options) => {
186
+ const perf = (0, perf_1.startPerfMeasure)('extract-frame');
187
+ const res = await mainLimit(extractFrameFromVideoFn, options);
188
+ (0, perf_1.stopPerfMeasure)(perf);
189
+ return res;
190
+ };
191
+ exports.extractFrameFromVideo = extractFrameFromVideo;
@@ -0,0 +1 @@
1
+ export type FfmpegExecutable = string | null;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ import type { FfmpegExecutable } from './ffmpeg-executable';
2
+ export type FfmpegVersion = [number, number, number] | null;
3
+ export declare const getFfmpegBuildInfo: (options: {
4
+ ffmpegExecutable: string | null;
5
+ remotionRoot: string;
6
+ }) => Promise<string>;
7
+ export declare const ffmpegInNodeModules: (remotionRoot: string, binary: 'ffmpeg' | 'ffprobe') => string | null;
8
+ export declare const ffmpegHasFeature: ({ ffmpegExecutable, feature, remotionRoot, }: {
9
+ ffmpegExecutable: string | null;
10
+ feature: 'enable-gpl' | 'enable-libx265' | 'enable-libvpx';
11
+ remotionRoot: string;
12
+ }) => Promise<boolean>;
13
+ export declare const parseFfmpegVersion: (buildconf: string) => FfmpegVersion;
14
+ export declare const getFfmpegVersion: (options: {
15
+ ffmpegExecutable: string | null;
16
+ remotionRoot: string;
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;
28
+ export declare const warnAboutFfmpegVersion: ({ ffmpegVersion, buildConf, }: {
29
+ ffmpegVersion: FfmpegVersion;
30
+ buildConf: string | null;
31
+ }) => null | undefined;
@@ -0,0 +1,245 @@
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.warnAboutFfmpegVersion = exports.getBinaryDownloadUrl = exports.getExecutableBinary = exports.lambdaFfmpegPaths = exports.downloadBinary = exports.getFfmpegVersion = exports.parseFfmpegVersion = exports.ffmpegHasFeature = exports.ffmpegInNodeModules = exports.getFfmpegBuildInfo = void 0;
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");
12
+ const validate_ffmpeg_1 = require("./validate-ffmpeg");
13
+ let buildConfig = null;
14
+ const listeners = {};
15
+ const isDownloading = {};
16
+ const getFfmpegBuildInfo = async (options) => {
17
+ if (buildConfig !== null) {
18
+ return buildConfig;
19
+ }
20
+ const data = await (0, execa_1.default)(await (0, exports.getExecutableBinary)(options.ffmpegExecutable, options.remotionRoot, 'ffmpeg'), ['-buildconf'], {
21
+ reject: false,
22
+ });
23
+ buildConfig = data.stderr;
24
+ return buildConfig;
25
+ };
26
+ exports.getFfmpegBuildInfo = getFfmpegBuildInfo;
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
+ recursive: true,
37
+ });
38
+ }
39
+ // Check if a version of FFMPEG is already installed.
40
+ // To qualify, it must have the expected file size
41
+ // to avoid finding binaries that are still being downloaded
42
+ // A random ID is being assigned to the download to avoid conflicts when multiple Remotion processes are running
43
+ const ffmpegInstalled = fs_1.default.readdirSync(folderName).find((filename) => {
44
+ if (!filename.startsWith(binaryPrefix[binary])) {
45
+ return false;
46
+ }
47
+ const dlUrl = (0, exports.getBinaryDownloadUrl)(binary);
48
+ if (!dlUrl) {
49
+ return false;
50
+ }
51
+ const expectedLength = dlUrl.contentLength;
52
+ if (fs_1.default.statSync(path_1.default.join(folderName, filename)).size === expectedLength) {
53
+ return true;
54
+ }
55
+ return false;
56
+ });
57
+ if (ffmpegInstalled) {
58
+ return path_1.default.join(folderName, ffmpegInstalled);
59
+ }
60
+ return null;
61
+ };
62
+ exports.ffmpegInNodeModules = ffmpegInNodeModules;
63
+ const getFfmpegAbsolutePath = (remotionRoot, binary) => {
64
+ const folderName = getFfmpegFolderName(remotionRoot);
65
+ if (!fs_1.default.existsSync(folderName)) {
66
+ fs_1.default.mkdirSync(folderName);
67
+ }
68
+ if (os_1.default.platform() === 'win32') {
69
+ return path_1.default.resolve(folderName, `${binaryPrefix[binary]}${randomFfmpegRuntimeId}.exe`);
70
+ }
71
+ return path_1.default.resolve(folderName, `${binaryPrefix[binary]}${randomFfmpegRuntimeId}`);
72
+ };
73
+ const ffmpegHasFeature = async ({ ffmpegExecutable, feature, remotionRoot, }) => {
74
+ if (ffmpegExecutable && !(0, validate_ffmpeg_1.customExecutableExists)(ffmpegExecutable)) {
75
+ return false;
76
+ }
77
+ if (!(0, validate_ffmpeg_1.binaryExists)('ffmpeg')) {
78
+ return false;
79
+ }
80
+ const config = await (0, exports.getFfmpegBuildInfo)({ ffmpegExecutable, remotionRoot });
81
+ return config.includes(feature);
82
+ };
83
+ exports.ffmpegHasFeature = ffmpegHasFeature;
84
+ const parseFfmpegVersion = (buildconf) => {
85
+ var _a;
86
+ const match = buildconf.match(/ffmpeg version ([0-9]+).([0-9]+)(?:.([0-9]+))?/);
87
+ if (!match) {
88
+ return null;
89
+ }
90
+ return [Number(match[1]), Number(match[2]), Number((_a = match[3]) !== null && _a !== void 0 ? _a : 0)];
91
+ };
92
+ exports.parseFfmpegVersion = parseFfmpegVersion;
93
+ const getFfmpegVersion = async (options) => {
94
+ const buildInfo = await (0, exports.getFfmpegBuildInfo)({
95
+ ffmpegExecutable: options.ffmpegExecutable,
96
+ remotionRoot: options.remotionRoot,
97
+ });
98
+ return (0, exports.parseFfmpegVersion)(buildInfo);
99
+ };
100
+ exports.getFfmpegVersion = getFfmpegVersion;
101
+ const waitForFfmpegToBeDownloaded = (url) => {
102
+ return new Promise((resolve) => {
103
+ if (!listeners[url]) {
104
+ listeners[url] = [];
105
+ }
106
+ listeners[url].push((src) => resolve(src));
107
+ });
108
+ };
109
+ const onProgress = (downloadedBytes, totalBytesToDownload, binary) => {
110
+ console.log('Downloading ', binary, `${toMegabytes(downloadedBytes)}/${toMegabytes(totalBytesToDownload)}`);
111
+ };
112
+ const downloadBinary = async (remotionRoot, url, binary) => {
113
+ const destinationPath = getFfmpegAbsolutePath(remotionRoot, binary);
114
+ const onProgressCallback = (downloadedBytes, _totalBytes) => {
115
+ onProgress(downloadedBytes, _totalBytes, binary);
116
+ };
117
+ isDownloading[url] = true;
118
+ const totalBytes = await (0, BrowserFetcher_1._downloadFile)(url, destinationPath, onProgressCallback);
119
+ onProgress(totalBytes, totalBytes, binary);
120
+ if (os_1.default.platform() !== 'win32') {
121
+ fs_1.default.chmodSync(destinationPath, '777');
122
+ }
123
+ isDownloading[url] = false;
124
+ if (!listeners[url]) {
125
+ listeners[url] = [];
126
+ }
127
+ listeners[url].forEach((listener) => listener(destinationPath));
128
+ listeners[url] = [];
129
+ return destinationPath;
130
+ };
131
+ exports.downloadBinary = downloadBinary;
132
+ exports.lambdaFfmpegPaths = {
133
+ ffmpeg: '/opt/bin/ffmpeg',
134
+ ffprobe: '/opt/bin/ffprobe',
135
+ };
136
+ const getExecutableBinary = (ffmpegExecutable, remotionRoot, binary) => {
137
+ if (fs_1.default.existsSync(exports.lambdaFfmpegPaths[binary])) {
138
+ return exports.lambdaFfmpegPaths[binary];
139
+ }
140
+ if (ffmpegExecutable && (0, validate_ffmpeg_1.customExecutableExists)(ffmpegExecutable)) {
141
+ return ffmpegExecutable;
142
+ }
143
+ if ((0, validate_ffmpeg_1.binaryExists)(binary)) {
144
+ return binary;
145
+ }
146
+ const dlUrl = (0, exports.getBinaryDownloadUrl)(binary);
147
+ if (dlUrl && isDownloading[dlUrl.url]) {
148
+ return waitForFfmpegToBeDownloaded(dlUrl.url);
149
+ }
150
+ const inNodeMod = (0, exports.ffmpegInNodeModules)(remotionRoot, binary);
151
+ if (inNodeMod) {
152
+ return inNodeMod;
153
+ }
154
+ if (!dlUrl) {
155
+ 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.`);
156
+ }
157
+ return (0, exports.downloadBinary)(remotionRoot, dlUrl.url, binary);
158
+ };
159
+ exports.getExecutableBinary = getExecutableBinary;
160
+ function toMegabytes(bytes) {
161
+ const mb = bytes / 1024 / 1024;
162
+ return `${Math.round(mb * 10) / 10} Mb`;
163
+ }
164
+ const getBinaryDownloadUrl = (binary) => {
165
+ if (os_1.default.platform() === 'win32' && process.arch === 'x64') {
166
+ return binary === 'ffmpeg'
167
+ ? {
168
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffmpeg-win-x86.exe',
169
+ contentLength: 127531008,
170
+ }
171
+ : {
172
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffprobe-win-x86.exe',
173
+ contentLength: 127425536,
174
+ };
175
+ }
176
+ if (os_1.default.platform() === 'darwin' && process.arch === 'arm64') {
177
+ return binary === 'ffmpeg'
178
+ ? {
179
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffmpeg-macos-arm64',
180
+ contentLength: 42093320,
181
+ }
182
+ : {
183
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffprobe-macos-arm64-v2',
184
+ contentLength: 46690008,
185
+ };
186
+ }
187
+ if (os_1.default.platform() === 'darwin' && process.arch === 'x64') {
188
+ return binary === 'ffmpeg'
189
+ ? {
190
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffmpeg-macos-x86',
191
+ contentLength: 78380700,
192
+ }
193
+ : {
194
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffprobe-macos-x86',
195
+ contentLength: 77364284,
196
+ };
197
+ }
198
+ if (os_1.default.platform() === 'linux' && process.arch === 'x64') {
199
+ return binary === 'ffmpeg'
200
+ ? {
201
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffmpeg-linux-amd64',
202
+ contentLength: 78502560,
203
+ }
204
+ : {
205
+ url: 'https://remotion-ffmpeg-binaries.s3.eu-central-1.amazonaws.com/ffprobe-linux-amd64',
206
+ contentLength: 78400704,
207
+ };
208
+ }
209
+ return null;
210
+ };
211
+ exports.getBinaryDownloadUrl = getBinaryDownloadUrl;
212
+ const printMessage = (ffmpegVersion) => {
213
+ console.warn('⚠️Old FFMPEG version detected: ' + ffmpegVersion.join('.'));
214
+ console.warn(' You need at least version 4.1.0.');
215
+ console.warn(' Upgrade FFMPEG to get rid of this warning.');
216
+ };
217
+ const printBuildConfMessage = () => {
218
+ console.error('⚠️ Unsupported FFMPEG version detected.');
219
+ console.error(" Your version doesn't support the -buildconf flag");
220
+ console.error(' Audio will not be supported and you may experience other issues.');
221
+ console.error(' Upgrade FFMPEG to at least v4.1.0 to get rid of this warning.');
222
+ };
223
+ const warnAboutFfmpegVersion = ({ ffmpegVersion, buildConf, }) => {
224
+ if (buildConf === null) {
225
+ printBuildConfMessage();
226
+ return;
227
+ }
228
+ if (ffmpegVersion === null) {
229
+ return null;
230
+ }
231
+ const [major, minor] = ffmpegVersion;
232
+ // 3.x and below definitely is too old
233
+ if (major < 4) {
234
+ printMessage(ffmpegVersion);
235
+ return;
236
+ }
237
+ // 5.x will be all good
238
+ if (major > 4) {
239
+ return;
240
+ }
241
+ if (minor < 1) {
242
+ printMessage(ffmpegVersion);
243
+ }
244
+ };
245
+ exports.warnAboutFfmpegVersion = warnAboutFfmpegVersion;
@@ -0,0 +1,3 @@
1
+ import type { DevtoolsRemoteObject, ObjectPreview } from './browser/devtools-types';
2
+ export declare const formatRemoteObject: (remoteObject: DevtoolsRemoteObject) => string;
3
+ export declare const formatObjectPreview: (preview: ObjectPreview) => string;