@remotion/renderer 4.0.21 → 4.0.23

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 (117) hide show
  1. package/.prettierignore +2 -0
  2. package/dist/assets/get-video-stream-duration.d.ts +9 -0
  3. package/dist/assets/get-video-stream-duration.js +71 -0
  4. package/dist/audio-codec.d.ts +3 -3
  5. package/dist/browser/Product.d.ts +16 -0
  6. package/dist/browser/Product.js +17 -0
  7. package/dist/browser/create-browser-fetcher.d.ts +17 -0
  8. package/dist/browser/create-browser-fetcher.js +58 -0
  9. package/dist/browser/revisions.d.ts +20 -0
  10. package/dist/browser/revisions.js +21 -0
  11. package/dist/calculate-sar-dar-pixels.d.ts +9 -0
  12. package/dist/calculate-sar-dar-pixels.js +19 -0
  13. package/dist/client.d.ts +155 -8
  14. package/dist/client.js +6 -0
  15. package/dist/codec.d.ts +1 -1
  16. package/dist/compositor/compositor.d.ts +2 -2
  17. package/dist/compositor/compositor.js +22 -19
  18. package/dist/compositor/payloads.d.ts +2 -2
  19. package/dist/copy-to-clipboard.js +1 -1
  20. package/dist/create-ffmpeg-complex-filter.d.ts +4 -1
  21. package/dist/determine-resize-params.d.ts +4 -0
  22. package/dist/determine-resize-params.js +10 -0
  23. package/dist/determine-vcodec-ffmpeg-flags.d.ts +2 -0
  24. package/dist/determine-vcodec-ffmpeg-flags.js +13 -0
  25. package/dist/ensure-ffmpeg.d.ts +18 -0
  26. package/dist/ensure-ffmpeg.js +58 -0
  27. package/dist/ensure-presentation-timestamp.d.ts +15 -0
  28. package/dist/ensure-presentation-timestamp.js +88 -0
  29. package/dist/extract-frame-from-video.d.ts +16 -0
  30. package/dist/extract-frame-from-video.js +191 -0
  31. package/dist/ffmpeg-executable.d.ts +1 -0
  32. package/dist/ffmpeg-executable.js +2 -0
  33. package/dist/ffmpeg-flags.d.ts +31 -0
  34. package/dist/ffmpeg-flags.js +245 -0
  35. package/dist/file-extensions.d.ts +1 -1
  36. package/dist/format-logs.js +3 -1
  37. package/dist/frame-to-ffmpeg-timestamp.d.ts +1 -0
  38. package/dist/frame-to-ffmpeg-timestamp.js +8 -0
  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 +5 -2
  42. package/dist/get-compositions.js +4 -1
  43. package/dist/get-extension-from-codec.js +1 -2
  44. package/dist/get-frame-of-video-slow.d.ts +17 -0
  45. package/dist/get-frame-of-video-slow.js +72 -0
  46. package/dist/get-silent-parts.d.ts +1 -1
  47. package/dist/get-silent-parts.js +1 -1
  48. package/dist/get-video-info.d.ts +8 -0
  49. package/dist/get-video-info.js +59 -0
  50. package/dist/get-video-metadata.js +1 -1
  51. package/dist/image-format.d.ts +2 -2
  52. package/dist/index.d.ts +54 -29
  53. package/dist/is-beyond-last-frame.d.ts +3 -0
  54. package/dist/is-beyond-last-frame.js +12 -0
  55. package/dist/last-frame-from-video-cache.d.ts +17 -0
  56. package/dist/last-frame-from-video-cache.js +55 -0
  57. package/dist/legacy-webpack-config.d.ts +9 -0
  58. package/dist/legacy-webpack-config.js +13 -0
  59. package/dist/log-level.d.ts +1 -1
  60. package/dist/logger.d.ts +1 -1
  61. package/dist/offthread-video-server.d.ts +2 -1
  62. package/dist/offthread-video-server.js +7 -2
  63. package/dist/open-browser.d.ts +1 -1
  64. package/dist/options/audio-bitrate.d.ts +8 -2
  65. package/dist/options/audio-bitrate.js +1 -0
  66. package/dist/options/crf.d.ts +8 -2
  67. package/dist/options/crf.js +1 -0
  68. package/dist/options/enforce-audio.d.ts +8 -2
  69. package/dist/options/enforce-audio.js +1 -0
  70. package/dist/options/jpeg-quality.d.ts +8 -2
  71. package/dist/options/jpeg-quality.js +1 -0
  72. package/dist/options/mute.d.ts +8 -2
  73. package/dist/options/mute.js +1 -0
  74. package/dist/options/offthreadvideo-cache-size.d.ts +9 -0
  75. package/dist/options/offthreadvideo-cache-size.js +33 -0
  76. package/dist/options/option.d.ts +7 -2
  77. package/dist/options/options-map.d.ts +82 -0
  78. package/dist/options/options-map.js +16 -0
  79. package/dist/options/scale.d.ts +8 -2
  80. package/dist/options/scale.js +1 -0
  81. package/dist/options/video-bitrate.d.ts +8 -2
  82. package/dist/options/video-bitrate.js +1 -0
  83. package/dist/options/video-codec.d.ts +8 -2
  84. package/dist/options/video-codec.js +1 -0
  85. package/dist/pixel-format.d.ts +1 -1
  86. package/dist/prepare-server.d.ts +2 -1
  87. package/dist/prepare-server.js +3 -1
  88. package/dist/prores-profile.d.ts +1 -1
  89. package/dist/provide-screenshot.d.ts +0 -1
  90. package/dist/puppeteer-screenshot.d.ts +0 -1
  91. package/dist/quality.d.ts +1 -0
  92. package/dist/quality.js +21 -0
  93. package/dist/render-frames.d.ts +5 -2
  94. package/dist/render-frames.js +4 -2
  95. package/dist/render-media.d.ts +9 -3
  96. package/dist/render-media.js +12 -2
  97. package/dist/render-still.d.ts +5 -1
  98. package/dist/render-still.js +3 -1
  99. package/dist/screenshot-dom-element.d.ts +0 -1
  100. package/dist/screenshot-task.d.ts +0 -1
  101. package/dist/select-composition.d.ts +4 -1
  102. package/dist/select-composition.js +5 -1
  103. package/dist/serve-static.d.ts +1 -0
  104. package/dist/serve-static.js +1 -0
  105. package/dist/stitch-frames-to-video.d.ts +4 -2
  106. package/dist/stitch-frames-to-video.js +4 -2
  107. package/dist/take-frame-and-compose.d.ts +0 -1
  108. package/dist/try-to-extract-frame-of-video-fast.d.ts +12 -0
  109. package/dist/try-to-extract-frame-of-video-fast.js +55 -0
  110. package/dist/validate-ffmpeg.d.ts +7 -0
  111. package/dist/validate-ffmpeg.js +77 -0
  112. package/dist/validate-opengl-renderer.d.ts +1 -1
  113. package/dist/warn-about-ffmpeg-version.d.ts +5 -0
  114. package/dist/warn-about-ffmpeg-version.js +37 -0
  115. package/dist/x264-preset.d.ts +7 -0
  116. package/dist/x264-preset.js +29 -0
  117. package/package.json +11 -12
@@ -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;
@@ -5,7 +5,7 @@ export declare const defaultFileExtensionMap: {
5
5
  [key in Codec]: {
6
6
  default: FileExtension;
7
7
  forAudioCodec: {
8
- [k in typeof supportedAudioCodecs[key][number]]: {
8
+ [k in (typeof supportedAudioCodecs)[key][number]]: {
9
9
  possible: FileExtension[];
10
10
  default: FileExtension;
11
11
  };
@@ -49,7 +49,9 @@ const formatObjectPreview = (preview) => {
49
49
  });
50
50
  if (preview.subtype === 'array') {
51
51
  if (preview.overflow) {
52
- return chalk_1.chalk.reset(`[ ${preview.properties.map((p) => formatProperty(p)).join(', ')}, …]`);
52
+ return chalk_1.chalk.reset(`[ ${preview.properties
53
+ .map((p) => formatProperty(p))
54
+ .join(', ')}, …]`);
53
55
  }
54
56
  return chalk_1.chalk.reset(`[ ${preview.properties.map((p) => formatProperty(p)).join(', ')} ]`);
55
57
  }
@@ -0,0 +1 @@
1
+ export declare const frameToFfmpegTimestamp: (time: number) => string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.frameToFfmpegTimestamp = void 0;
4
+ const frameToFfmpegTimestamp = (time) => {
5
+ // We ceil because FFMPEG seeks to the closest frame BEFORE the position
6
+ return (Math.ceil(time * 1000000) / 1000).toFixed(3) + 'ms';
7
+ };
8
+ exports.frameToFfmpegTimestamp = frameToFfmpegTimestamp;
@@ -0,0 +1,14 @@
1
+ import type { FfmpegExecutable } from './ffmpeg-executable';
2
+ export declare const ACCEPTABLE_OFFSET_THRESHOLD = 50;
3
+ /**
4
+ * @description Probes whether frames of a video can be efficiently extracted when using <OffthreadVideo>.
5
+ * @see [Documentation](https://www.remotion.dev/docs/renderer/get-can-extract-frames-fast)
6
+ */
7
+ export declare const getCanExtractFramesFast: ({ src, ffmpegExecutable, ffprobeExecutable, }: {
8
+ src: string;
9
+ ffmpegExecutable?: FfmpegExecutable | undefined;
10
+ ffprobeExecutable?: FfmpegExecutable | undefined;
11
+ }) => Promise<{
12
+ canExtractFramesFast: boolean;
13
+ shouldReencode: boolean;
14
+ }>;
@@ -0,0 +1,71 @@
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.getCanExtractFramesFast = exports.ACCEPTABLE_OFFSET_THRESHOLD = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const get_video_stream_duration_1 = require("./assets/get-video-stream-duration");
9
+ const ensure_presentation_timestamp_1 = require("./ensure-presentation-timestamp");
10
+ const find_closest_package_json_1 = require("./find-closest-package-json");
11
+ const get_video_info_1 = require("./get-video-info");
12
+ const try_to_extract_frame_of_video_fast_1 = require("./try-to-extract-frame-of-video-fast");
13
+ exports.ACCEPTABLE_OFFSET_THRESHOLD = 50;
14
+ /**
15
+ * @description Probes whether frames of a video can be efficiently extracted when using <OffthreadVideo>.
16
+ * @see [Documentation](https://www.remotion.dev/docs/renderer/get-can-extract-frames-fast)
17
+ */
18
+ const getCanExtractFramesFast = async ({ src, ffmpegExecutable, ffprobeExecutable, }) => {
19
+ const remotionRoot = (0, find_closest_package_json_1.findRemotionRoot)();
20
+ const out = await (0, ensure_presentation_timestamp_1.ensurePresentationTimestampWithoutCache)({
21
+ ffmpegExecutable: ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : null,
22
+ ffprobeExecutable: ffprobeExecutable !== null && ffprobeExecutable !== void 0 ? ffprobeExecutable : null,
23
+ remotionRoot,
24
+ src,
25
+ });
26
+ const { specialVcodecForTransparency: specialVcodec } = await (0, get_video_info_1.getVideoInfoUncached)({
27
+ src: out,
28
+ ffprobeExecutable: ffprobeExecutable !== null && ffprobeExecutable !== void 0 ? ffprobeExecutable : null,
29
+ remotionRoot,
30
+ });
31
+ if (specialVcodec === 'vp8') {
32
+ fs_1.default.unlinkSync(out);
33
+ return {
34
+ canExtractFramesFast: false,
35
+ shouldReencode: false,
36
+ };
37
+ }
38
+ const { duration } = await (0, get_video_stream_duration_1.getVideoStreamDurationwithoutCache)({
39
+ ffprobeExecutable: ffprobeExecutable !== null && ffprobeExecutable !== void 0 ? ffprobeExecutable : null,
40
+ remotionRoot,
41
+ src: out,
42
+ });
43
+ if (duration === null) {
44
+ fs_1.default.unlinkSync(out);
45
+ throw new Error(`Could not determine the duration of ${src} using FFMPEG. The file is not supported.`);
46
+ }
47
+ const actualOffset = `${duration * 1000 - exports.ACCEPTABLE_OFFSET_THRESHOLD}ms`;
48
+ const [stdErr] = await (0, try_to_extract_frame_of_video_fast_1.tryToExtractFrameOfVideoFast)({
49
+ actualOffset,
50
+ ffmpegExecutable: ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : null,
51
+ imageFormat: 'jpeg',
52
+ // Intentionally leaving needsResize as null, because we don't need to resize
53
+ needsResize: null,
54
+ remotionRoot,
55
+ specialVCodecForTransparency: specialVcodec,
56
+ src: out,
57
+ });
58
+ fs_1.default.unlinkSync(out);
59
+ const isEmpty = stdErr.includes('Output file is empty');
60
+ if (isEmpty) {
61
+ return {
62
+ canExtractFramesFast: false,
63
+ shouldReencode: true,
64
+ };
65
+ }
66
+ return {
67
+ canExtractFramesFast: true,
68
+ shouldReencode: false,
69
+ };
70
+ };
71
+ exports.getCanExtractFramesFast = getCanExtractFramesFast;
@@ -4,6 +4,8 @@ import type { BrowserLog } from './browser-log';
4
4
  import type { HeadlessBrowser } from './browser/Browser';
5
5
  import { type LogLevel } from './log-level';
6
6
  import type { ChromiumOptions } from './open-browser';
7
+ import type { ToOptions } from './options/option';
8
+ import type { optionsMap } from './options/options-map';
7
9
  import type { RemotionServer } from './prepare-server';
8
10
  type InternalGetCompositionsOptions = {
9
11
  serializedInputPropsWithCustomSchema: string;
@@ -18,7 +20,7 @@ type InternalGetCompositionsOptions = {
18
20
  indent: boolean;
19
21
  logLevel: LogLevel;
20
22
  serveUrlOrWebpackUrl: string;
21
- };
23
+ } & ToOptions<typeof optionsMap.getCompositions>;
22
24
  export type GetCompositionsOptions = {
23
25
  inputProps?: Record<string, unknown> | null;
24
26
  envVariables?: Record<string, string>;
@@ -29,8 +31,9 @@ export type GetCompositionsOptions = {
29
31
  chromiumOptions?: ChromiumOptions;
30
32
  port?: number | null;
31
33
  logLevel?: LogLevel;
34
+ offthreadVideoCacheSizeInBytes?: number | null;
32
35
  };
33
- export declare const internalGetCompositions: ({ browserExecutable, chromiumOptions, envVariables, indent, serializedInputPropsWithCustomSchema, onBrowserLog, port, puppeteerInstance, serveUrlOrWebpackUrl, server, timeoutInMilliseconds, logLevel, }: InternalGetCompositionsOptions) => Promise<VideoConfig[]>;
36
+ export declare const internalGetCompositions: ({ browserExecutable, chromiumOptions, envVariables, indent, serializedInputPropsWithCustomSchema, onBrowserLog, port, puppeteerInstance, serveUrlOrWebpackUrl, server, timeoutInMilliseconds, logLevel, offthreadVideoCacheSizeInBytes, }: InternalGetCompositionsOptions) => Promise<VideoConfig[]>;
34
37
  /**
35
38
  * @description Gets the compositions defined in a Remotion project based on a Webpack bundle.
36
39
  * @see [Documentation](https://www.remotion.dev/docs/renderer/get-compositions)
@@ -70,7 +70,7 @@ const innerGetCompositions = async ({ envVariables, serializedInputPropsWithCust
70
70
  };
71
71
  });
72
72
  };
73
- const internalGetCompositions = async ({ browserExecutable, chromiumOptions, envVariables, indent, serializedInputPropsWithCustomSchema, onBrowserLog, port, puppeteerInstance, serveUrlOrWebpackUrl, server, timeoutInMilliseconds, logLevel, }) => {
73
+ const internalGetCompositions = async ({ browserExecutable, chromiumOptions, envVariables, indent, serializedInputPropsWithCustomSchema, onBrowserLog, port, puppeteerInstance, serveUrlOrWebpackUrl, server, timeoutInMilliseconds, logLevel, offthreadVideoCacheSizeInBytes, }) => {
74
74
  const { page, cleanup: cleanupPage } = await (0, get_browser_instance_1.getPageAndCleanupFn)({
75
75
  passedInInstance: puppeteerInstance,
76
76
  browserExecutable,
@@ -95,6 +95,7 @@ const internalGetCompositions = async ({ browserExecutable, chromiumOptions, env
95
95
  concurrency: 1,
96
96
  logLevel,
97
97
  indent,
98
+ offthreadVideoCacheSizeInBytes,
98
99
  }, {
99
100
  onDownload: () => undefined,
100
101
  onError,
@@ -133,6 +134,7 @@ exports.internalGetCompositions = internalGetCompositions;
133
134
  * @see [Documentation](https://www.remotion.dev/docs/renderer/get-compositions)
134
135
  */
135
136
  const getCompositions = (serveUrlOrWebpackUrl, config) => {
137
+ var _a;
136
138
  const { browserExecutable, chromiumOptions, envVariables, inputProps, onBrowserLog, port, puppeteerInstance, timeoutInMilliseconds, logLevel, } = config !== null && config !== void 0 ? config : {};
137
139
  return (0, exports.internalGetCompositions)({
138
140
  browserExecutable: browserExecutable !== null && browserExecutable !== void 0 ? browserExecutable : null,
@@ -151,6 +153,7 @@ const getCompositions = (serveUrlOrWebpackUrl, config) => {
151
153
  server: undefined,
152
154
  timeoutInMilliseconds: timeoutInMilliseconds !== null && timeoutInMilliseconds !== void 0 ? timeoutInMilliseconds : TimeoutSettings_1.DEFAULT_TIMEOUT,
153
155
  logLevel: logLevel !== null && logLevel !== void 0 ? logLevel : (0, logger_1.getLogLevel)(),
156
+ offthreadVideoCacheSizeInBytes: (_a = config === null || config === void 0 ? void 0 : config.offthreadVideoCacheSizeInBytes) !== null && _a !== void 0 ? _a : null,
154
157
  });
155
158
  };
156
159
  exports.getCompositions = getCompositions;
@@ -15,8 +15,7 @@ const getFileExtensionFromCodec = (codec, audioCodec) => {
15
15
  if (!(typedAudioCodec in map.forAudioCodec)) {
16
16
  throw new Error(`Audio codec ${typedAudioCodec} is not supported for codec ${codec}`);
17
17
  }
18
- return map.forAudioCodec[audioCodec]
19
- .default;
18
+ return map.forAudioCodec[audioCodec].default;
20
19
  };
21
20
  exports.getFileExtensionFromCodec = getFileExtensionFromCodec;
22
21
  const makeFileExtensionMap = () => {
@@ -0,0 +1,17 @@
1
+ import type { OffthreadVideoImageFormat } from 'remotion';
2
+ import type { SpecialVCodecForTransparency } from './assets/download-map';
3
+ import type { FfmpegExecutable } from './ffmpeg-executable';
4
+ export declare const getFrameOfVideoSlow: ({ src, duration, ffmpegExecutable, imageFormat, specialVCodecForTransparency, needsResize, offset, fps, remotionRoot, }: {
5
+ ffmpegExecutable: FfmpegExecutable;
6
+ src: string;
7
+ duration: number;
8
+ imageFormat: OffthreadVideoImageFormat;
9
+ specialVCodecForTransparency: SpecialVCodecForTransparency;
10
+ needsResize: [
11
+ number,
12
+ number
13
+ ] | null;
14
+ offset: number;
15
+ fps: number | null;
16
+ remotionRoot: string;
17
+ }) => Promise<Buffer>;
@@ -0,0 +1,72 @@
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.getFrameOfVideoSlow = void 0;
7
+ // Uses no seeking, therefore the whole video has to be decoded. This is a last resort and should only happen
8
+ // if the video is corrupted
9
+ const execa_1 = __importDefault(require("execa"));
10
+ const determine_resize_params_1 = require("./determine-resize-params");
11
+ const determine_vcodec_ffmpeg_flags_1 = require("./determine-vcodec-ffmpeg-flags");
12
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
13
+ const truthy_1 = require("./truthy");
14
+ const getFrameOfVideoSlow = async ({ src, duration, ffmpegExecutable, imageFormat, specialVCodecForTransparency, needsResize, offset, fps, remotionRoot, }) => {
15
+ 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`);
16
+ const actualOffset = `-${duration * 1000 - offset}ms`;
17
+ const command = [
18
+ '-itsoffset',
19
+ actualOffset,
20
+ ...(0, determine_vcodec_ffmpeg_flags_1.determineVcodecFfmpegFlags)(specialVCodecForTransparency),
21
+ '-i',
22
+ src,
23
+ '-frames:v',
24
+ '1',
25
+ '-c:v',
26
+ imageFormat === 'jpeg' ? 'mjpeg' : 'png',
27
+ '-f',
28
+ 'image2pipe',
29
+ ...(0, determine_resize_params_1.determineResizeParams)(needsResize),
30
+ '-',
31
+ ].filter(truthy_1.truthy);
32
+ const { stdout, stderr } = (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffmpegExecutable, remotionRoot, 'ffmpeg'), command);
33
+ if (!stderr) {
34
+ throw new Error('unexpectedly did not get stderr');
35
+ }
36
+ if (!stdout) {
37
+ throw new Error('unexpectedly did not get stdout');
38
+ }
39
+ const stderrChunks = [];
40
+ const stdoutChunks = [];
41
+ const stdErrString = new Promise((resolve, reject) => {
42
+ stderr.on('data', (d) => stderrChunks.push(d));
43
+ stderr.on('error', (err) => reject(err));
44
+ stderr.on('end', () => resolve(Buffer.concat(stderrChunks).toString('utf-8')));
45
+ });
46
+ const stdoutChunk = new Promise((resolve, reject) => {
47
+ stdout.on('data', (d) => stdoutChunks.push(d));
48
+ stdout.on('error', (err) => reject(err));
49
+ stdout.on('end', () => resolve(Buffer.concat(stdoutChunks)));
50
+ });
51
+ const [stdErr, stdoutBuffer] = await Promise.all([stdErrString, stdoutChunk]);
52
+ const isEmpty = stdErr.includes('Output file is empty');
53
+ if (isEmpty) {
54
+ if (offset > 70) {
55
+ throw new Error(`Could not get last frame of ${src}. Tried to seek to the end using the command "ffmpeg ${command.join(' ')}" but got no frame. Most likely this video is corrupted.`);
56
+ }
57
+ return (0, exports.getFrameOfVideoSlow)({
58
+ ffmpegExecutable,
59
+ duration,
60
+ // Decrement in 10ms increments, or 1 frame (e.g. fps = 25 --> 40ms)
61
+ offset: offset + (fps === null ? 10 : 1000 / fps),
62
+ src,
63
+ imageFormat,
64
+ specialVCodecForTransparency,
65
+ needsResize,
66
+ fps,
67
+ remotionRoot,
68
+ });
69
+ }
70
+ return stdoutBuffer;
71
+ };
72
+ exports.getFrameOfVideoSlow = getFrameOfVideoSlow;
@@ -3,6 +3,6 @@ import type { LogLevel } from './log-level';
3
3
  export declare const getSilentParts: ({ src, noiseThresholdInDecibels: passedNoiseThresholdInDecibels, minDurationInSeconds: passedMinDuration, logLevel, }: {
4
4
  src: string;
5
5
  minDurationInSeconds?: number | undefined;
6
- logLevel?: "error" | "verbose" | "info" | "warn" | undefined;
6
+ logLevel?: "verbose" | "info" | "warn" | "error" | undefined;
7
7
  noiseThresholdInDecibels?: number | undefined;
8
8
  }) => Promise<GetSilentPartsResponse>;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSilentParts = void 0;
4
4
  const compositor_1 = require("./compositor/compositor");
5
5
  const getSilentParts = async ({ src, noiseThresholdInDecibels: passedNoiseThresholdInDecibels, minDurationInSeconds: passedMinDuration, logLevel, }) => {
6
- const compositor = (0, compositor_1.startLongRunningCompositor)((0, compositor_1.getIdealMaximumFrameCacheItems)(), logLevel !== null && logLevel !== void 0 ? logLevel : 'info', false);
6
+ const compositor = (0, compositor_1.startLongRunningCompositor)((0, compositor_1.getIdealMaximumFrameCacheSizeInBytes)(), logLevel !== null && logLevel !== void 0 ? logLevel : 'info', false);
7
7
  const minDurationInSeconds = passedMinDuration !== null && passedMinDuration !== void 0 ? passedMinDuration : 1;
8
8
  if (typeof minDurationInSeconds !== 'number') {
9
9
  throw new Error(`minDurationInSeconds must be a number, but was ${minDurationInSeconds}`);
@@ -0,0 +1,8 @@
1
+ import type { DownloadMap, Vp9Result } from './assets/download-map';
2
+ import type { FfmpegExecutable } from './ffmpeg-executable';
3
+ export declare function getVideoInfoUncached({ src, ffprobeExecutable, remotionRoot, }: {
4
+ src: string;
5
+ ffprobeExecutable: FfmpegExecutable;
6
+ remotionRoot: string;
7
+ }): Promise<Vp9Result>;
8
+ export declare const getVideoInfo: (downloadMap: DownloadMap, src: string, ffprobeExecutable: FfmpegExecutable, remotionRoot: string) => Promise<Vp9Result>;
@@ -0,0 +1,59 @@
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.getVideoInfo = exports.getVideoInfoUncached = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const calculate_sar_dar_pixels_1 = require("./calculate-sar-dar-pixels");
9
+ const ffmpeg_flags_1 = require("./ffmpeg-flags");
10
+ const p_limit_1 = require("./p-limit");
11
+ const limit = (0, p_limit_1.pLimit)(1);
12
+ async function getVideoInfoUncached({ src, ffprobeExecutable, remotionRoot, }) {
13
+ var _a;
14
+ const task = await (0, execa_1.default)(await (0, ffmpeg_flags_1.getExecutableBinary)(ffprobeExecutable, remotionRoot, 'ffprobe'), [src]);
15
+ const isVp9 = task.stderr.includes('Video: vp9');
16
+ const isVp8 = task.stderr.includes('Video: vp8');
17
+ const dimensions = (_a = task.stderr
18
+ .split('\n')
19
+ .find((n) => n.trim().startsWith('Stream #'))) === null || _a === void 0 ? void 0 : _a.match(/([0-9]{2,6})x([0-9]{2,6})/);
20
+ const dar = task.stderr.match(/DAR\s([0-9]+):([0-9]+)/);
21
+ let needsResize = null;
22
+ if (dimensions && dar) {
23
+ const width = parseInt(dimensions[1], 10);
24
+ const height = parseInt(dimensions[2], 10);
25
+ const darWidth = parseInt(dar[1], 10);
26
+ const darHeight = parseInt(dar[2], 10);
27
+ const { width: actualWidth, height: actualHeight } = (0, calculate_sar_dar_pixels_1.calculateDisplayVideoSize)({
28
+ darX: darWidth,
29
+ darY: darHeight,
30
+ x: width,
31
+ y: height,
32
+ });
33
+ if (actualWidth !== width || actualHeight !== height) {
34
+ needsResize = [actualWidth, actualHeight];
35
+ }
36
+ }
37
+ const result = {
38
+ specialVcodecForTransparency: isVp9 ? 'vp9' : isVp8 ? 'vp8' : 'none',
39
+ needsResize,
40
+ };
41
+ return result;
42
+ }
43
+ exports.getVideoInfoUncached = getVideoInfoUncached;
44
+ async function getVideoInfoUnlimited(downloadMap, src, ffprobeExecutable, remotionRoot) {
45
+ if (typeof downloadMap.isVp9VideoCache[src] !== 'undefined') {
46
+ return downloadMap.isVp9VideoCache[src];
47
+ }
48
+ const result = await getVideoInfoUncached({
49
+ ffprobeExecutable,
50
+ remotionRoot,
51
+ src,
52
+ });
53
+ downloadMap.isVp9VideoCache[src] = result;
54
+ return downloadMap.isVp9VideoCache[src];
55
+ }
56
+ const getVideoInfo = (downloadMap, src, ffprobeExecutable, remotionRoot) => {
57
+ return limit(() => getVideoInfoUnlimited(downloadMap, src, ffprobeExecutable, remotionRoot));
58
+ };
59
+ exports.getVideoInfo = getVideoInfo;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getVideoMetadata = void 0;
4
4
  const compositor_1 = require("./compositor/compositor");
5
5
  const getVideoMetadata = async (videoSource) => {
6
- const compositor = (0, compositor_1.startLongRunningCompositor)((0, compositor_1.getIdealMaximumFrameCacheItems)(), 'info', false);
6
+ const compositor = (0, compositor_1.startLongRunningCompositor)((0, compositor_1.getIdealMaximumFrameCacheSizeInBytes)(), 'info', false);
7
7
  const metadataResponse = await compositor.executeCommand('GetVideoMetadata', {
8
8
  src: videoSource,
9
9
  });
@@ -1,8 +1,8 @@
1
1
  import type { PixelFormat } from './pixel-format';
2
2
  export declare const validVideoImageFormats: readonly ["png", "jpeg", "none"];
3
3
  export declare const validStillImageFormats: readonly ["png", "jpeg", "pdf", "webp"];
4
- export type VideoImageFormat = typeof validVideoImageFormats[number];
5
- export type StillImageFormat = typeof validStillImageFormats[number];
4
+ export type VideoImageFormat = (typeof validVideoImageFormats)[number];
5
+ export type StillImageFormat = (typeof validStillImageFormats)[number];
6
6
  /**
7
7
  * @deprecated Use VideoImageFormat or StillImageFormat instead
8
8
  */