@remotion/renderer 4.0.0-oops.3 → 4.0.0-prefetch.10
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.
- package/dist/assets/calculate-asset-positions.d.ts +2 -2
- package/dist/assets/convert-assets-to-file-urls.d.ts +5 -4
- package/dist/assets/convert-assets-to-file-urls.js +2 -2
- package/dist/assets/download-and-map-assets-to-file.d.ts +16 -6
- package/dist/assets/download-and-map-assets-to-file.js +152 -45
- package/dist/assets/download-file.d.ts +10 -5
- package/dist/assets/download-file.js +20 -5
- package/dist/assets/download-map.d.ts +64 -0
- package/dist/assets/download-map.js +73 -0
- package/dist/assets/ffmpeg-volume-expression.d.ts +3 -3
- package/dist/assets/ffmpeg-volume-expression.js +16 -14
- package/dist/assets/flatten-volume-array.d.ts +1 -1
- package/dist/assets/get-audio-channels.d.ts +3 -4
- package/dist/assets/get-audio-channels.js +14 -4
- package/dist/assets/get-video-stream-duration.d.ts +4 -0
- package/dist/assets/get-video-stream-duration.js +59 -0
- package/dist/assets/read-file.js +4 -1
- package/dist/assets/types.d.ts +1 -1
- package/dist/browser/Browser.d.ts +60 -0
- package/dist/browser/Browser.js +218 -0
- package/dist/browser/BrowserConnector.d.ts +19 -0
- package/dist/browser/BrowserConnector.js +17 -0
- package/dist/browser/BrowserFetcher.d.ts +89 -0
- package/dist/browser/BrowserFetcher.js +510 -0
- package/dist/browser/BrowserPage.d.ts +74 -0
- package/dist/browser/BrowserPage.js +283 -0
- package/dist/browser/BrowserRunner.d.ts +39 -0
- package/dist/browser/BrowserRunner.js +308 -0
- package/dist/browser/Connection.d.ts +42 -0
- package/dist/browser/Connection.js +242 -0
- package/dist/browser/ConsoleMessage.d.ts +31 -0
- package/dist/browser/ConsoleMessage.js +48 -0
- package/dist/browser/DOMWorld.d.ts +52 -0
- package/dist/browser/DOMWorld.js +272 -0
- package/dist/browser/Errors.d.ts +25 -0
- package/dist/browser/Errors.js +35 -0
- package/dist/browser/EvalTypes.d.ts +27 -0
- package/dist/browser/EvalTypes.js +17 -0
- package/dist/browser/EventEmitter.d.ts +23 -0
- package/dist/browser/EventEmitter.js +53 -0
- package/dist/browser/ExecutionContext.d.ts +34 -0
- package/dist/browser/ExecutionContext.js +174 -0
- package/dist/browser/FrameManager.d.ts +93 -0
- package/dist/browser/FrameManager.js +496 -0
- package/dist/browser/HTTPRequest.d.ts +28 -0
- package/dist/browser/HTTPRequest.js +37 -0
- package/dist/browser/HTTPResponse.d.ts +21 -0
- package/dist/browser/HTTPResponse.js +41 -0
- package/dist/browser/JSHandle.d.ts +35 -0
- package/dist/browser/JSHandle.js +90 -0
- package/dist/browser/LaunchOptions.d.ts +37 -0
- package/dist/browser/LaunchOptions.js +17 -0
- package/dist/browser/Launcher.d.ts +9 -0
- package/dist/browser/Launcher.js +504 -0
- package/dist/browser/LifecycleWatcher.d.ts +29 -0
- package/dist/browser/LifecycleWatcher.js +180 -0
- package/dist/browser/NetworkEventManager.d.ts +33 -0
- package/dist/browser/NetworkEventManager.js +81 -0
- package/dist/browser/NetworkManager.d.ts +34 -0
- package/dist/browser/NetworkManager.js +231 -0
- package/dist/browser/NodeWebSocketTransport.d.ts +17 -0
- package/dist/browser/NodeWebSocketTransport.js +87 -0
- package/dist/browser/Product.d.ts +16 -0
- package/dist/browser/Product.js +17 -0
- package/dist/browser/PuppeteerNode.d.ts +40 -0
- package/dist/browser/PuppeteerNode.js +81 -0
- package/dist/browser/PuppeteerViewport.d.ts +5 -0
- package/dist/browser/PuppeteerViewport.js +2 -0
- package/dist/browser/ScreenshotOptions.d.ts +14 -0
- package/dist/browser/ScreenshotOptions.js +2 -0
- package/dist/browser/Target.d.ts +61 -0
- package/dist/browser/Target.js +146 -0
- package/dist/browser/TaskQueue.d.ts +20 -0
- package/dist/browser/TaskQueue.js +47 -0
- package/dist/browser/TimeoutSettings.d.ts +24 -0
- package/dist/browser/TimeoutSettings.js +62 -0
- package/dist/browser/assert.d.ts +1 -0
- package/dist/browser/assert.js +9 -0
- package/dist/browser/create-browser-fetcher.d.ts +17 -0
- package/dist/browser/create-browser-fetcher.js +119 -0
- package/dist/browser/devtools-commands.d.ts +270 -0
- package/dist/browser/devtools-commands.js +2 -0
- package/dist/browser/devtools-types.d.ts +1122 -0
- package/dist/browser/devtools-types.js +2 -0
- package/dist/browser/get-download-destination.d.ts +1 -0
- package/dist/browser/get-download-destination.js +38 -0
- package/dist/browser/mitt/index.d.ts +22 -0
- package/dist/browser/mitt/index.js +49 -0
- package/dist/browser/node.d.ts +2 -0
- package/dist/browser/node.js +9 -0
- package/dist/browser/revisions.d.ts +21 -0
- package/dist/browser/revisions.js +22 -0
- package/dist/browser/util.d.ts +47 -0
- package/dist/browser/util.js +169 -0
- package/dist/browser-executable.d.ts +1 -0
- package/dist/browser-executable.js +2 -0
- package/dist/browser-log.d.ts +1 -1
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +4 -0
- package/dist/calculate-ffmpeg-filters.d.ts +1 -1
- package/dist/calculate-ffmpeg-filters.js +2 -2
- package/dist/calculate-sar-dar-pixels.d.ts +9 -0
- package/dist/calculate-sar-dar-pixels.js +19 -0
- package/dist/can-use-parallel-encoding.d.ts +1 -1
- package/dist/can-use-parallel-encoding.js +2 -2
- package/dist/codec-supports-media.d.ts +8 -0
- package/dist/codec-supports-media.js +56 -0
- package/dist/codec.d.ts +4 -0
- package/dist/codec.js +16 -0
- package/dist/combine-videos.d.ts +4 -2
- package/dist/combine-videos.js +19 -5
- package/dist/compress-assets.d.ts +7 -0
- package/dist/compress-assets.js +25 -0
- package/dist/convert-number-of-gif-loops-to-ffmpeg.d.ts +1 -0
- package/dist/convert-number-of-gif-loops-to-ffmpeg.js +17 -0
- package/dist/convert-to-pcm.d.ts +1 -1
- package/dist/create-ffmpeg-complex-filter.d.ts +2 -1
- package/dist/create-ffmpeg-complex-filter.js +2 -11
- package/dist/create-ffmpeg-merge-filter.js +3 -3
- package/dist/create-silent-audio.d.ts +1 -1
- package/dist/crf.d.ts +5 -0
- package/dist/crf.js +64 -0
- package/dist/cycle-browser-tabs.d.ts +3 -2
- package/dist/cycle-browser-tabs.js +14 -2
- package/dist/delay-render-embedded-stack.d.ts +1 -1
- package/dist/ensure-frames-in-order.d.ts +1 -1
- package/dist/ensure-frames-in-order.js +3 -2
- package/dist/ensure-presentation-timestamp.d.ts +2 -0
- package/dist/ensure-presentation-timestamp.js +69 -0
- package/dist/error-handling/handle-javascript-exception.d.ts +2 -2
- package/dist/error-handling/handle-javascript-exception.js +3 -4
- package/dist/error-handling/symbolicate-error.d.ts +1 -1
- package/dist/error-handling/symbolicateable-error.d.ts +1 -1
- package/dist/extract-frame-from-video.d.ts +16 -0
- package/dist/extract-frame-from-video.js +277 -0
- package/dist/ffmpeg-executable.d.ts +1 -0
- package/dist/ffmpeg-executable.js +2 -0
- package/dist/ffmpeg-filter-file.d.ts +2 -1
- package/dist/ffmpeg-filter-file.js +4 -6
- package/dist/frame-range.d.ts +2 -0
- package/dist/frame-range.js +49 -0
- package/dist/frame-to-ffmpeg-timestamp.d.ts +1 -0
- package/dist/frame-to-ffmpeg-timestamp.js +8 -0
- package/dist/get-audio-codec-name.d.ts +1 -1
- package/dist/get-audio-codec-name.js +2 -2
- package/dist/get-browser-instance.d.ts +4 -3
- package/dist/get-browser-instance.js +2 -2
- package/dist/get-codec-name.d.ts +1 -1
- package/dist/get-codec-name.js +5 -2
- package/dist/get-compositions.d.ts +15 -5
- package/dist/get-compositions.js +35 -11
- package/dist/get-duration-from-frame-range.d.ts +1 -2
- package/dist/get-duration-from-frame-range.js +13 -9
- package/dist/get-extension-from-codec.d.ts +2 -2
- package/dist/get-extension-from-codec.js +5 -0
- package/dist/get-extension-of-filename.d.ts +1 -1
- package/dist/get-extension-of-filename.js +3 -0
- package/dist/get-frame-padded-index.d.ts +14 -0
- package/dist/get-frame-padded-index.js +33 -0
- package/dist/get-frame-to-render.d.ts +1 -1
- package/dist/get-local-browser-executable.d.ts +2 -1
- package/dist/get-local-browser-executable.js +7 -5
- package/dist/get-port.js +30 -37
- package/dist/get-prores-profile-name.d.ts +2 -1
- package/dist/get-video-info.d.ts +3 -0
- package/dist/get-video-info.js +49 -0
- package/dist/get-video-threads-flag.d.ts +1 -0
- package/dist/get-video-threads-flag.js +18 -0
- package/dist/guess-extension-for-media.d.ts +1 -0
- package/dist/guess-extension-for-media.js +27 -0
- package/dist/image-format.d.ts +6 -1
- package/dist/image-format.js +25 -1
- package/dist/index.d.ts +95 -20
- package/dist/index.js +93 -6
- package/dist/is-audio-codec.d.ts +2 -0
- package/dist/is-audio-codec.js +7 -0
- package/dist/is-beyond-last-frame.d.ts +3 -0
- package/dist/is-beyond-last-frame.js +12 -0
- package/dist/last-frame-from-video-cache.d.ts +17 -0
- package/dist/last-frame-from-video-cache.js +55 -0
- package/dist/log-level.d.ts +4 -0
- package/dist/log-level.js +15 -0
- package/dist/make-cancel-signal.d.ts +7 -0
- package/dist/make-cancel-signal.js +25 -0
- package/dist/merge-audio-track.d.ts +3 -1
- package/dist/merge-audio-track.js +14 -8
- package/dist/mime-db.d.ts +6 -0
- package/dist/mime-db.js +8636 -0
- package/dist/mime-types.d.ts +3 -0
- package/dist/mime-types.js +94 -0
- package/dist/offthread-video-server.d.ts +17 -0
- package/dist/offthread-video-server.js +86 -0
- package/dist/open-browser.d.ts +10 -7
- package/dist/open-browser.js +63 -20
- package/dist/overwrite.d.ts +1 -0
- package/dist/overwrite.js +4 -0
- package/dist/perf.d.ts +5 -0
- package/dist/perf.js +35 -0
- package/dist/pixel-format.d.ts +5 -0
- package/dist/pixel-format.js +26 -0
- package/dist/prepare-server.d.ts +14 -2
- package/dist/prepare-server.js +38 -5
- package/dist/preprocess-audio-track.d.ts +5 -2
- package/dist/preprocess-audio-track.js +3 -3
- package/dist/prespawn-ffmpeg.d.ts +7 -1
- package/dist/prespawn-ffmpeg.js +20 -16
- package/dist/prestitcher-memory-usage.d.ts +12 -0
- package/dist/prestitcher-memory-usage.js +30 -0
- package/dist/prores-profile.d.ts +5 -0
- package/dist/prores-profile.js +23 -0
- package/dist/provide-screenshot.d.ts +4 -4
- package/dist/provide-screenshot.js +1 -2
- package/dist/puppeteer-evaluate.d.ts +1 -1
- package/dist/puppeteer-evaluate.js +3 -4
- package/dist/puppeteer-screenshot.d.ts +3 -2
- package/dist/puppeteer-screenshot.js +7 -5
- package/dist/quality.d.ts +1 -0
- package/dist/quality.js +21 -0
- package/dist/render-frames.d.ts +24 -8
- package/dist/render-frames.js +153 -65
- package/dist/render-media.d.ts +36 -9
- package/dist/render-media.js +194 -70
- package/dist/render-still.d.ts +25 -7
- package/dist/render-still.js +91 -26
- package/dist/screenshot-dom-element.d.ts +6 -7
- package/dist/screenshot-dom-element.js +3 -6
- package/dist/screenshot-task.d.ts +3 -2
- package/dist/screenshot-task.js +36 -23
- package/dist/seek-to-frame.d.ts +2 -2
- package/dist/seek-to-frame.js +2 -2
- package/dist/serve-handler/index.d.ts +4 -0
- package/dist/serve-handler/index.js +204 -0
- package/dist/serve-handler/is-path-inside.d.ts +1 -0
- package/dist/serve-handler/is-path-inside.js +27 -0
- package/dist/serve-handler/range-parser.d.ts +13 -0
- package/dist/serve-handler/range-parser.js +57 -0
- package/dist/serve-static.d.ts +11 -3
- package/dist/serve-static.js +37 -7
- package/dist/set-props-and-env.d.ts +6 -2
- package/dist/set-props-and-env.js +65 -12
- package/dist/stitch-frames-to-video.d.ts +17 -5
- package/dist/stitch-frames-to-video.js +130 -46
- package/dist/stringify-ffmpeg-filter.d.ts +2 -2
- package/dist/stringify-ffmpeg-filter.js +12 -7
- package/dist/symbolicate-stacktrace.d.ts +1 -1
- package/dist/symbolicate-stacktrace.js +3 -3
- package/dist/tmp-dir.js +5 -1
- package/dist/truthy.d.ts +3 -0
- package/dist/truthy.js +7 -0
- package/dist/types.d.ts +1 -1
- package/dist/validate-concurrency.d.ts +1 -0
- package/dist/validate-concurrency.js +24 -0
- package/dist/validate-even-dimensions-with-codec.d.ts +1 -1
- package/dist/validate-even-dimensions-with-codec.js +2 -2
- package/dist/validate-every-nth-frame.d.ts +1 -0
- package/dist/validate-every-nth-frame.js +21 -0
- package/dist/validate-ffmpeg.js +2 -3
- package/dist/validate-frame.d.ts +1 -0
- package/dist/validate-frame.js +24 -0
- package/dist/validate-opengl-renderer.d.ts +5 -0
- package/dist/validate-opengl-renderer.js +15 -0
- package/dist/validate-output-filename.d.ts +1 -1
- package/dist/validate-output-filename.js +5 -0
- package/dist/wait-for-symbolication-error-to-be-done.d.ts +3 -0
- package/dist/wait-for-symbolication-error-to-be-done.js +34 -0
- package/dist/ws/ws-types.d.ts +14 -0
- package/dist/ws/ws-types.js +10 -0
- package/package.json +13 -16
- package/tsconfig.json +2 -2
- package/types/ws/index.d.ts +509 -0
- package/vitest.config.ts +8 -0
- package/dist/make-assets-download-dir.d.ts +0 -1
- package/dist/make-assets-download-dir.js +0 -8
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { TAsset } from 'remotion';
|
|
2
|
-
import { Assets } from './types';
|
|
1
|
+
import type { TAsset } from 'remotion';
|
|
2
|
+
import type { Assets } from './types';
|
|
3
3
|
export declare const calculateAssetPositions: (frames: TAsset[][]) => Assets;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { TAsset } from 'remotion';
|
|
2
|
-
import { RenderMediaOnDownload } from './download-and-map-assets-to-file';
|
|
3
|
-
|
|
1
|
+
import type { TAsset } from 'remotion';
|
|
2
|
+
import type { RenderMediaOnDownload } from './download-and-map-assets-to-file';
|
|
3
|
+
import type { DownloadMap } from './download-map';
|
|
4
|
+
export declare const convertAssetsToFileUrls: ({ assets, onDownload, downloadMap, }: {
|
|
4
5
|
assets: TAsset[][];
|
|
5
|
-
downloadDir: string;
|
|
6
6
|
onDownload: RenderMediaOnDownload;
|
|
7
|
+
downloadMap: DownloadMap;
|
|
7
8
|
}) => Promise<TAsset[][]>;
|
|
@@ -9,7 +9,7 @@ const chunk = (input, size) => {
|
|
|
9
9
|
: [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
|
|
10
10
|
}, []);
|
|
11
11
|
};
|
|
12
|
-
const convertAssetsToFileUrls = async ({ assets,
|
|
12
|
+
const convertAssetsToFileUrls = async ({ assets, onDownload, downloadMap, }) => {
|
|
13
13
|
const chunks = chunk(assets, 1000);
|
|
14
14
|
const results = [];
|
|
15
15
|
for (const ch of chunks) {
|
|
@@ -17,8 +17,8 @@ const convertAssetsToFileUrls = async ({ assets, downloadDir, onDownload, }) =>
|
|
|
17
17
|
return Promise.all(assetsForFrame.map((a) => {
|
|
18
18
|
return (0, download_and_map_assets_to_file_1.downloadAndMapAssetsToFileUrl)({
|
|
19
19
|
asset: a,
|
|
20
|
-
downloadDir,
|
|
21
20
|
onDownload,
|
|
21
|
+
downloadMap,
|
|
22
22
|
});
|
|
23
23
|
}));
|
|
24
24
|
}));
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { TAsset } from 'remotion';
|
|
1
|
+
import type { TAsset } from 'remotion';
|
|
2
|
+
import type { DownloadMap } from './download-map';
|
|
2
3
|
export declare type RenderMediaOnDownload = (src: string) => ((progress: {
|
|
3
|
-
percent: number;
|
|
4
|
+
percent: number | null;
|
|
5
|
+
downloaded: number;
|
|
6
|
+
totalSize: number | null;
|
|
4
7
|
}) => void) | undefined | void;
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
8
|
+
export declare const downloadAsset: ({ src, onDownload, downloadMap, }: {
|
|
9
|
+
src: string;
|
|
10
|
+
onDownload: RenderMediaOnDownload;
|
|
11
|
+
downloadMap: DownloadMap;
|
|
12
|
+
}) => Promise<string>;
|
|
13
|
+
export declare const markAllAssetsAsDownloaded: (downloadMap: DownloadMap) => void;
|
|
14
|
+
export declare const getSanitizedFilenameForAssetUrl: ({ src, downloadDir, contentDisposition, contentType, }: {
|
|
7
15
|
src: string;
|
|
8
16
|
downloadDir: string;
|
|
17
|
+
contentDisposition: string | null;
|
|
18
|
+
contentType: string | null;
|
|
9
19
|
}) => string;
|
|
10
|
-
export declare const downloadAndMapAssetsToFileUrl: ({ asset,
|
|
20
|
+
export declare const downloadAndMapAssetsToFileUrl: ({ asset, onDownload, downloadMap, }: {
|
|
11
21
|
asset: TAsset;
|
|
12
|
-
downloadDir: string;
|
|
13
22
|
onDownload: RenderMediaOnDownload;
|
|
23
|
+
downloadMap: DownloadMap;
|
|
14
24
|
}) => Promise<TAsset>;
|
|
@@ -1,33 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.downloadAndMapAssetsToFileUrl = exports.getSanitizedFilenameForAssetUrl = exports.markAllAssetsAsDownloaded = void 0;
|
|
29
|
+
exports.downloadAndMapAssetsToFileUrl = exports.getSanitizedFilenameForAssetUrl = exports.markAllAssetsAsDownloaded = exports.downloadAsset = void 0;
|
|
7
30
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 =
|
|
31
|
+
const path_1 = __importStar(require("path"));
|
|
9
32
|
const remotion_1 = require("remotion");
|
|
33
|
+
const compress_assets_1 = require("../compress-assets");
|
|
10
34
|
const ensure_output_directory_1 = require("../ensure-output-directory");
|
|
35
|
+
const mime_types_1 = require("../mime-types");
|
|
11
36
|
const download_file_1 = require("./download-file");
|
|
12
37
|
const sanitize_filepath_1 = require("./sanitize-filepath");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
38
|
+
const waitForAssetToBeDownloaded = ({ src, downloadDir, downloadMap, }) => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
if ((_a = downloadMap.hasBeenDownloadedMap[src]) === null || _a === void 0 ? void 0 : _a[downloadDir]) {
|
|
41
|
+
return Promise.resolve((_b = downloadMap.hasBeenDownloadedMap[src]) === null || _b === void 0 ? void 0 : _b[downloadDir]);
|
|
42
|
+
}
|
|
43
|
+
if (!downloadMap.listeners[src]) {
|
|
44
|
+
downloadMap.listeners[src] = {};
|
|
45
|
+
}
|
|
46
|
+
if (!downloadMap.listeners[src][downloadDir]) {
|
|
47
|
+
downloadMap.listeners[src][downloadDir] = [];
|
|
19
48
|
}
|
|
20
49
|
return new Promise((resolve) => {
|
|
21
|
-
listeners[src].push(() =>
|
|
50
|
+
downloadMap.listeners[src][downloadDir].push(() => {
|
|
51
|
+
const srcMap = downloadMap.hasBeenDownloadedMap[src];
|
|
52
|
+
if (!srcMap || !srcMap[downloadDir]) {
|
|
53
|
+
throw new Error('Expected file for ' + src + 'to be available in ' + downloadDir);
|
|
54
|
+
}
|
|
55
|
+
resolve(srcMap[downloadDir]);
|
|
56
|
+
});
|
|
22
57
|
});
|
|
23
58
|
};
|
|
24
|
-
const notifyAssetIsDownloaded = (src) => {
|
|
25
|
-
if (!listeners[src]) {
|
|
26
|
-
listeners[src] =
|
|
59
|
+
const notifyAssetIsDownloaded = ({ src, downloadDir, to, downloadMap, }) => {
|
|
60
|
+
if (!downloadMap.listeners[src]) {
|
|
61
|
+
downloadMap.listeners[src] = {};
|
|
62
|
+
}
|
|
63
|
+
if (!downloadMap.listeners[src][downloadDir]) {
|
|
64
|
+
downloadMap.listeners[src][downloadDir] = [];
|
|
27
65
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
66
|
+
if (!downloadMap.isDownloadingMap[src]) {
|
|
67
|
+
downloadMap.isDownloadingMap[src] = {};
|
|
68
|
+
}
|
|
69
|
+
downloadMap.isDownloadingMap[src][downloadDir] = false;
|
|
70
|
+
if (!downloadMap.hasBeenDownloadedMap[src]) {
|
|
71
|
+
downloadMap.hasBeenDownloadedMap[src] = {};
|
|
72
|
+
}
|
|
73
|
+
downloadMap.hasBeenDownloadedMap[src][downloadDir] = to;
|
|
74
|
+
downloadMap.listeners[src][downloadDir].forEach((fn) => fn());
|
|
31
75
|
};
|
|
32
76
|
const validateMimeType = (mimeType, src) => {
|
|
33
77
|
if (!mimeType.includes('/')) {
|
|
@@ -68,17 +112,42 @@ function validateBufferEncoding(potentialEncoding, dataUrl) {
|
|
|
68
112
|
throw new TypeError(errMessage);
|
|
69
113
|
}
|
|
70
114
|
}
|
|
71
|
-
const downloadAsset = async (src,
|
|
72
|
-
|
|
73
|
-
|
|
115
|
+
const downloadAsset = async ({ src, onDownload, downloadMap, }) => {
|
|
116
|
+
var _a, _b, _c;
|
|
117
|
+
if ((0, compress_assets_1.isAssetCompressed)(src)) {
|
|
118
|
+
return src;
|
|
119
|
+
}
|
|
120
|
+
const { downloadDir } = downloadMap;
|
|
121
|
+
if ((_a = downloadMap.hasBeenDownloadedMap[src]) === null || _a === void 0 ? void 0 : _a[downloadDir]) {
|
|
122
|
+
const claimedDownloadLocation = (_b = downloadMap.hasBeenDownloadedMap[src]) === null || _b === void 0 ? void 0 : _b[downloadDir];
|
|
123
|
+
// The OS might have deleted the file since even though we marked it as downloaded. In that case we reset the state and download it again
|
|
124
|
+
if (fs_1.default.existsSync(claimedDownloadLocation)) {
|
|
125
|
+
return claimedDownloadLocation;
|
|
126
|
+
}
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
128
|
+
downloadMap.hasBeenDownloadedMap[src][downloadDir] = null;
|
|
129
|
+
if (!downloadMap.isDownloadingMap[src]) {
|
|
130
|
+
downloadMap.isDownloadingMap[src] = {};
|
|
131
|
+
}
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
133
|
+
downloadMap.isDownloadingMap[src][downloadDir] = false;
|
|
74
134
|
}
|
|
75
|
-
if (isDownloadingMap[src]) {
|
|
76
|
-
return waitForAssetToBeDownloaded(src);
|
|
135
|
+
if ((_c = downloadMap.isDownloadingMap[src]) === null || _c === void 0 ? void 0 : _c[downloadDir]) {
|
|
136
|
+
return waitForAssetToBeDownloaded({ downloadMap, src, downloadDir });
|
|
77
137
|
}
|
|
78
|
-
isDownloadingMap[src]
|
|
138
|
+
if (!downloadMap.isDownloadingMap[src]) {
|
|
139
|
+
downloadMap.isDownloadingMap[src] = {};
|
|
140
|
+
}
|
|
141
|
+
downloadMap.isDownloadingMap[src][downloadDir] = true;
|
|
79
142
|
const onProgress = onDownload(src);
|
|
80
|
-
(0, ensure_output_directory_1.ensureOutputDirectory)(to);
|
|
81
143
|
if (src.startsWith('data:')) {
|
|
144
|
+
const output = (0, exports.getSanitizedFilenameForAssetUrl)({
|
|
145
|
+
contentDisposition: null,
|
|
146
|
+
downloadDir,
|
|
147
|
+
src,
|
|
148
|
+
contentType: null,
|
|
149
|
+
});
|
|
150
|
+
(0, ensure_output_directory_1.ensureOutputDirectory)(output);
|
|
82
151
|
const [assetDetails, assetData] = src.substring('data:'.length).split(',');
|
|
83
152
|
if (!assetDetails.includes(';')) {
|
|
84
153
|
const errMessage = [
|
|
@@ -93,47 +162,85 @@ const downloadAsset = async (src, to, onDownload) => {
|
|
|
93
162
|
validateMimeType(mimeType, src);
|
|
94
163
|
validateBufferEncoding(encoding, src);
|
|
95
164
|
const buff = Buffer.from(assetData, encoding);
|
|
96
|
-
await fs_1.default.promises.writeFile(
|
|
97
|
-
notifyAssetIsDownloaded(src);
|
|
98
|
-
return;
|
|
165
|
+
await fs_1.default.promises.writeFile(output, buff);
|
|
166
|
+
notifyAssetIsDownloaded({ src, downloadMap, downloadDir, to: output });
|
|
167
|
+
return output;
|
|
99
168
|
}
|
|
100
|
-
await (0, download_file_1.downloadFile)(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
169
|
+
const { to } = await (0, download_file_1.downloadFile)({
|
|
170
|
+
url: src,
|
|
171
|
+
onProgress: (progress) => {
|
|
172
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(progress);
|
|
173
|
+
},
|
|
174
|
+
to: (contentDisposition, contentType) => (0, exports.getSanitizedFilenameForAssetUrl)({
|
|
175
|
+
contentDisposition,
|
|
176
|
+
downloadDir,
|
|
177
|
+
src,
|
|
178
|
+
contentType,
|
|
179
|
+
}),
|
|
104
180
|
});
|
|
105
|
-
notifyAssetIsDownloaded(src);
|
|
181
|
+
notifyAssetIsDownloaded({ src, downloadMap, downloadDir, to });
|
|
182
|
+
return to;
|
|
106
183
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
184
|
+
exports.downloadAsset = downloadAsset;
|
|
185
|
+
const markAllAssetsAsDownloaded = (downloadMap) => {
|
|
186
|
+
Object.keys(downloadMap.hasBeenDownloadedMap).forEach((key) => {
|
|
187
|
+
delete downloadMap.hasBeenDownloadedMap[key];
|
|
110
188
|
});
|
|
111
|
-
Object.keys(isDownloadingMap).forEach((key) => {
|
|
112
|
-
delete isDownloadingMap[key];
|
|
189
|
+
Object.keys(downloadMap.isDownloadingMap).forEach((key) => {
|
|
190
|
+
delete downloadMap.isDownloadingMap[key];
|
|
113
191
|
});
|
|
114
192
|
};
|
|
115
193
|
exports.markAllAssetsAsDownloaded = markAllAssetsAsDownloaded;
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
194
|
+
const getFilename = ({ contentDisposition, src, contentType, }) => {
|
|
195
|
+
const filenameProbe = 'filename=';
|
|
196
|
+
if (contentDisposition === null || contentDisposition === void 0 ? void 0 : contentDisposition.includes(filenameProbe)) {
|
|
197
|
+
const start = contentDisposition.indexOf(filenameProbe);
|
|
198
|
+
const onlyFromFileName = contentDisposition.substring(start + filenameProbe.length);
|
|
199
|
+
const hasSemi = onlyFromFileName.indexOf(';');
|
|
200
|
+
if (hasSemi === -1) {
|
|
201
|
+
return { pathname: onlyFromFileName.trim(), search: '' };
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
search: '',
|
|
205
|
+
pathname: onlyFromFileName.substring(0, hasSemi).trim(),
|
|
206
|
+
};
|
|
119
207
|
}
|
|
120
208
|
const { pathname, search } = new URL(src);
|
|
209
|
+
const ext = (0, path_1.extname)(pathname);
|
|
210
|
+
// Has no file extension, check if we can derive it from contentType
|
|
211
|
+
if (!ext && contentType) {
|
|
212
|
+
const matchedExt = (0, mime_types_1.getExt)(contentType);
|
|
213
|
+
return {
|
|
214
|
+
pathname: `${pathname}.${matchedExt}`,
|
|
215
|
+
search,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return { pathname, search };
|
|
219
|
+
};
|
|
220
|
+
const getSanitizedFilenameForAssetUrl = ({ src, downloadDir, contentDisposition, contentType, }) => {
|
|
221
|
+
if ((0, compress_assets_1.isAssetCompressed)(src)) {
|
|
222
|
+
return src;
|
|
223
|
+
}
|
|
224
|
+
const { pathname, search } = getFilename({
|
|
225
|
+
contentDisposition,
|
|
226
|
+
contentType,
|
|
227
|
+
src,
|
|
228
|
+
});
|
|
121
229
|
const split = pathname.split('.');
|
|
122
230
|
const fileExtension = split.length > 1 && split[split.length - 1]
|
|
123
231
|
? `.${split[split.length - 1]}`
|
|
124
232
|
: '';
|
|
125
233
|
const hashedFileName = String((0, remotion_1.random)(`${pathname}${search}`)).replace('0.', '');
|
|
126
|
-
|
|
234
|
+
const filename = hashedFileName + fileExtension;
|
|
235
|
+
return path_1.default.join(downloadDir, (0, sanitize_filepath_1.sanitizeFilePath)(filename));
|
|
127
236
|
};
|
|
128
237
|
exports.getSanitizedFilenameForAssetUrl = getSanitizedFilenameForAssetUrl;
|
|
129
|
-
const downloadAndMapAssetsToFileUrl = async ({ asset,
|
|
130
|
-
const newSrc = (0, exports.
|
|
238
|
+
const downloadAndMapAssetsToFileUrl = async ({ asset, onDownload, downloadMap, }) => {
|
|
239
|
+
const newSrc = await (0, exports.downloadAsset)({
|
|
131
240
|
src: asset.src,
|
|
132
|
-
|
|
241
|
+
onDownload,
|
|
242
|
+
downloadMap,
|
|
133
243
|
});
|
|
134
|
-
if (!remotion_1.Internals.AssetCompression.isAssetCompressed(newSrc)) {
|
|
135
|
-
await downloadAsset(asset.src, newSrc, onDownload);
|
|
136
|
-
}
|
|
137
244
|
return {
|
|
138
245
|
...asset,
|
|
139
246
|
src: newSrc,
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
export declare const downloadFile: (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export declare const downloadFile: ({ onProgress, url, to: toFn, }: {
|
|
2
|
+
url: string;
|
|
3
|
+
to: (contentDisposition: string | null, contentType: string | null) => string;
|
|
4
|
+
onProgress: ((progress: {
|
|
5
|
+
percent: number | null;
|
|
6
|
+
downloaded: number;
|
|
7
|
+
totalSize: number | null;
|
|
8
|
+
}) => void) | undefined;
|
|
9
|
+
}) => Promise<{
|
|
6
10
|
sizeInBytes: number;
|
|
11
|
+
to: string;
|
|
7
12
|
}>;
|
|
@@ -2,25 +2,40 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.downloadFile = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
|
+
const ensure_output_directory_1 = require("../ensure-output-directory");
|
|
5
6
|
const read_file_1 = require("./read-file");
|
|
6
|
-
const downloadFile = (url, to,
|
|
7
|
+
const downloadFile = ({ onProgress, url, to: toFn, }) => {
|
|
7
8
|
return new Promise((resolve, reject) => {
|
|
8
9
|
(0, read_file_1.readFile)(url)
|
|
9
10
|
.then((res) => {
|
|
10
|
-
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const contentDisposition = (_a = res.headers['content-disposition']) !== null && _a !== void 0 ? _a : null;
|
|
13
|
+
const contentType = (_b = res.headers['content-type']) !== null && _b !== void 0 ? _b : null;
|
|
14
|
+
const to = toFn(contentDisposition, contentType);
|
|
15
|
+
(0, ensure_output_directory_1.ensureOutputDirectory)(to);
|
|
16
|
+
const sizeHeader = res.headers['content-length'];
|
|
17
|
+
const totalSize = typeof sizeHeader === 'undefined' ? null : Number(sizeHeader);
|
|
11
18
|
const writeStream = (0, fs_1.createWriteStream)(to);
|
|
19
|
+
let downloaded = 0;
|
|
12
20
|
// Listen to 'close' event instead of more
|
|
13
21
|
// concise method to avoid this problem
|
|
14
22
|
// https://github.com/remotion-dev/remotion/issues/384#issuecomment-844398183
|
|
15
|
-
writeStream.on('close', () =>
|
|
23
|
+
writeStream.on('close', () => {
|
|
24
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress({
|
|
25
|
+
downloaded,
|
|
26
|
+
percent: 1,
|
|
27
|
+
totalSize: downloaded,
|
|
28
|
+
});
|
|
29
|
+
return resolve({ sizeInBytes: downloaded, to });
|
|
30
|
+
});
|
|
16
31
|
writeStream.on('error', (err) => reject(err));
|
|
17
|
-
|
|
32
|
+
res.on('error', (err) => reject(err));
|
|
18
33
|
res.pipe(writeStream).on('error', (err) => reject(err));
|
|
19
34
|
res.on('data', (d) => {
|
|
20
35
|
downloaded += d.length;
|
|
21
36
|
onProgress === null || onProgress === void 0 ? void 0 : onProgress({
|
|
22
37
|
downloaded,
|
|
23
|
-
|
|
38
|
+
percent: totalSize === null ? null : downloaded / totalSize,
|
|
24
39
|
totalSize,
|
|
25
40
|
});
|
|
26
41
|
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { TAsset } from 'remotion';
|
|
3
|
+
declare type EncodingStatus = {
|
|
4
|
+
type: 'encoding';
|
|
5
|
+
} | {
|
|
6
|
+
type: 'done';
|
|
7
|
+
src: string;
|
|
8
|
+
} | undefined;
|
|
9
|
+
export declare type SpecialVCodecForTransparency = 'vp9' | 'vp8' | 'none';
|
|
10
|
+
export declare type Vp9Result = {
|
|
11
|
+
specialVcodec: SpecialVCodecForTransparency;
|
|
12
|
+
needsResize: [number, number] | null;
|
|
13
|
+
};
|
|
14
|
+
export declare type VideoDurationResult = {
|
|
15
|
+
duration: number | null;
|
|
16
|
+
fps: number | null;
|
|
17
|
+
};
|
|
18
|
+
export declare type AudioChannelsAndDurationResultCache = {
|
|
19
|
+
channels: number;
|
|
20
|
+
duration: number | null;
|
|
21
|
+
};
|
|
22
|
+
export declare type DownloadMap = {
|
|
23
|
+
id: string;
|
|
24
|
+
isDownloadingMap: {
|
|
25
|
+
[src: string]: {
|
|
26
|
+
[downloadDir: string]: boolean;
|
|
27
|
+
} | undefined;
|
|
28
|
+
};
|
|
29
|
+
hasBeenDownloadedMap: {
|
|
30
|
+
[src: string]: {
|
|
31
|
+
[downloadDir: string]: string | null;
|
|
32
|
+
} | undefined;
|
|
33
|
+
};
|
|
34
|
+
listeners: {
|
|
35
|
+
[key: string]: {
|
|
36
|
+
[downloadDir: string]: (() => void)[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
lastFrameMap: Record<string, {
|
|
40
|
+
lastAccessed: number;
|
|
41
|
+
data: Buffer;
|
|
42
|
+
}>;
|
|
43
|
+
isBeyondLastFrameMap: Record<string, number>;
|
|
44
|
+
isVp9VideoCache: Record<string, Vp9Result>;
|
|
45
|
+
ensureFileHasPresentationTimestamp: Record<string, EncodingStatus>;
|
|
46
|
+
videoDurationResultCache: Record<string, VideoDurationResult>;
|
|
47
|
+
durationOfAssetCache: Record<string, AudioChannelsAndDurationResultCache>;
|
|
48
|
+
downloadDir: string;
|
|
49
|
+
preEncode: string;
|
|
50
|
+
audioMixing: string;
|
|
51
|
+
complexFilter: string;
|
|
52
|
+
audioPreprocessing: string;
|
|
53
|
+
stitchFrames: string;
|
|
54
|
+
assetDir: string;
|
|
55
|
+
};
|
|
56
|
+
export declare type RenderAssetInfo = {
|
|
57
|
+
assets: TAsset[][];
|
|
58
|
+
imageSequenceName: string;
|
|
59
|
+
firstFrameIndex: number;
|
|
60
|
+
downloadMap: DownloadMap;
|
|
61
|
+
};
|
|
62
|
+
export declare const makeDownloadMap: () => DownloadMap;
|
|
63
|
+
export declare const cleanDownloadMap: (downloadMap: DownloadMap) => Promise<void>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.cleanDownloadMap = exports.makeDownloadMap = void 0;
|
|
30
|
+
const fs_1 = __importStar(require("fs"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const delete_directory_1 = require("../delete-directory");
|
|
33
|
+
const tmp_dir_1 = require("../tmp-dir");
|
|
34
|
+
const makeAndReturn = (dir, name) => {
|
|
35
|
+
const p = path_1.default.join(dir, name);
|
|
36
|
+
(0, fs_1.mkdirSync)(p);
|
|
37
|
+
return p;
|
|
38
|
+
};
|
|
39
|
+
const packageJsonPath = path_1.default.join(__dirname, '..', '..', 'package.json');
|
|
40
|
+
const packageJson = fs_1.default.existsSync(packageJsonPath)
|
|
41
|
+
? JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf-8'))
|
|
42
|
+
: null;
|
|
43
|
+
const makeDownloadMap = () => {
|
|
44
|
+
const dir = (0, tmp_dir_1.tmpDir)(packageJson
|
|
45
|
+
? `remotion-v${packageJson.version.replace(/\./g, '-')}-assets`
|
|
46
|
+
: 'remotion-assets');
|
|
47
|
+
return {
|
|
48
|
+
isDownloadingMap: {},
|
|
49
|
+
hasBeenDownloadedMap: {},
|
|
50
|
+
listeners: {},
|
|
51
|
+
lastFrameMap: {},
|
|
52
|
+
isBeyondLastFrameMap: {},
|
|
53
|
+
ensureFileHasPresentationTimestamp: {},
|
|
54
|
+
isVp9VideoCache: {},
|
|
55
|
+
videoDurationResultCache: {},
|
|
56
|
+
durationOfAssetCache: {},
|
|
57
|
+
id: String(Math.random()),
|
|
58
|
+
assetDir: dir,
|
|
59
|
+
downloadDir: makeAndReturn(dir, 'remotion-assets-dir'),
|
|
60
|
+
complexFilter: makeAndReturn(dir, 'remotion-complex-filter'),
|
|
61
|
+
preEncode: makeAndReturn(dir, 'pre-encode'),
|
|
62
|
+
audioMixing: makeAndReturn(dir, 'remotion-audio-mixing'),
|
|
63
|
+
audioPreprocessing: makeAndReturn(dir, 'remotion-audio-preprocessing'),
|
|
64
|
+
stitchFrames: makeAndReturn(dir, 'remotion-stitch-temp-dir'),
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
exports.makeDownloadMap = makeDownloadMap;
|
|
68
|
+
const cleanDownloadMap = async (downloadMap) => {
|
|
69
|
+
await (0, delete_directory_1.deleteDirectory)(downloadMap.downloadDir);
|
|
70
|
+
await (0, delete_directory_1.deleteDirectory)(downloadMap.complexFilter);
|
|
71
|
+
await (0, delete_directory_1.deleteDirectory)(downloadMap.assetDir);
|
|
72
|
+
};
|
|
73
|
+
exports.cleanDownloadMap = cleanDownloadMap;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { AssetVolume } from './types';
|
|
1
|
+
import type { AssetVolume } from './types';
|
|
2
2
|
declare type FfmpegEval = 'once' | 'frame';
|
|
3
3
|
declare type FfmpegVolumeExpression = {
|
|
4
4
|
eval: FfmpegEval;
|
|
5
5
|
value: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const ffmpegVolumeExpression: ({ volume,
|
|
7
|
+
export declare const ffmpegVolumeExpression: ({ volume, fps, trimLeft, }: {
|
|
8
8
|
volume: AssetVolume;
|
|
9
|
-
|
|
9
|
+
trimLeft: number;
|
|
10
10
|
fps: number;
|
|
11
11
|
}) => FfmpegVolumeExpression;
|
|
12
12
|
export {};
|
|
@@ -12,12 +12,12 @@ const FFMPEG_TIME_VARIABLE = 't';
|
|
|
12
12
|
const ffmpegIfOrElse = (condition, then, elseDo) => {
|
|
13
13
|
return `if(${condition},${then},${elseDo})`;
|
|
14
14
|
};
|
|
15
|
-
const ffmpegIsOneOfFrames = (frames, fps) => {
|
|
15
|
+
const ffmpegIsOneOfFrames = ({ frames, trimLeft, fps, }) => {
|
|
16
16
|
const consecutiveArrays = [];
|
|
17
17
|
for (let i = 0; i < frames.length; i++) {
|
|
18
18
|
const previousFrame = frames[i - 1];
|
|
19
19
|
const frame = frames[i];
|
|
20
|
-
if (
|
|
20
|
+
if (previousFrame === undefined || frame !== previousFrame + 1) {
|
|
21
21
|
consecutiveArrays.push([]);
|
|
22
22
|
}
|
|
23
23
|
consecutiveArrays[consecutiveArrays.length - 1].push(frame);
|
|
@@ -28,25 +28,22 @@ const ffmpegIsOneOfFrames = (frames, fps) => {
|
|
|
28
28
|
const lastFrame = f[f.length - 1];
|
|
29
29
|
const before = (firstFrame - 0.5) / fps;
|
|
30
30
|
const after = (lastFrame + 0.5) / fps;
|
|
31
|
-
return `between(${FFMPEG_TIME_VARIABLE},${before.toFixed(4)},${after.toFixed(4)})`;
|
|
31
|
+
return `between(${FFMPEG_TIME_VARIABLE},${(before + trimLeft).toFixed(4)},${(after + trimLeft).toFixed(4)})`;
|
|
32
32
|
})
|
|
33
33
|
.join('+');
|
|
34
34
|
};
|
|
35
|
-
const ffmpegBuildVolumeExpression = (arr, fps) => {
|
|
35
|
+
const ffmpegBuildVolumeExpression = (arr, delay, fps) => {
|
|
36
36
|
if (arr.length === 0) {
|
|
37
37
|
throw new Error('Volume array expression should never have length 0');
|
|
38
38
|
}
|
|
39
39
|
if (arr.length === 1) {
|
|
40
|
-
|
|
41
|
-
// where the audio actually plays.
|
|
42
|
-
// If this is the case, we just return volume 0 to clip it.
|
|
43
|
-
return ffmpegIfOrElse(ffmpegIsOneOfFrames(arr[0][1], fps), String(arr[0][0]), String(0));
|
|
40
|
+
return String(arr[0][0]);
|
|
44
41
|
}
|
|
45
42
|
const [first, ...rest] = arr;
|
|
46
43
|
const [volume, frames] = first;
|
|
47
|
-
return ffmpegIfOrElse(ffmpegIsOneOfFrames(frames, fps), String(volume), ffmpegBuildVolumeExpression(rest, fps));
|
|
44
|
+
return ffmpegIfOrElse(ffmpegIsOneOfFrames({ frames, trimLeft: delay, fps }), String(volume), ffmpegBuildVolumeExpression(rest, delay, fps));
|
|
48
45
|
};
|
|
49
|
-
const ffmpegVolumeExpression = ({ volume,
|
|
46
|
+
const ffmpegVolumeExpression = ({ volume, fps, trimLeft, }) => {
|
|
50
47
|
// If it's a static volume, we return it and tell
|
|
51
48
|
// FFMPEG it only has to evaluate it once
|
|
52
49
|
if (typeof volume === 'number') {
|
|
@@ -58,22 +55,27 @@ const ffmpegVolumeExpression = ({ volume, startInVideo, fps, }) => {
|
|
|
58
55
|
if ([...new Set(volume)].length === 1) {
|
|
59
56
|
return (0, exports.ffmpegVolumeExpression)({
|
|
60
57
|
volume: volume[0],
|
|
61
|
-
startInVideo,
|
|
62
58
|
fps,
|
|
59
|
+
trimLeft,
|
|
63
60
|
});
|
|
64
61
|
}
|
|
62
|
+
// A 1 sec video with frames 0-29 would mean that
|
|
63
|
+
// frame 29 corresponds to timestamp 0.966666...
|
|
64
|
+
// but the audio is actually 1 sec long. For that reason we pad the last
|
|
65
|
+
// timestamp.
|
|
66
|
+
const paddedVolume = [...volume, volume[volume.length - 1]];
|
|
65
67
|
// Otherwise, we construct an FFMPEG expression. First step:
|
|
66
68
|
// Make a map of all possible volumes
|
|
67
69
|
// {possibleVolume1} => [frame1, frame2]
|
|
68
70
|
// {possibleVolume2} => [frame3, frame4]
|
|
69
71
|
const volumeMap = {};
|
|
70
|
-
|
|
72
|
+
paddedVolume.forEach((baseVolume, frame) => {
|
|
71
73
|
// Adjust volume based on how many other tracks have not yet finished
|
|
72
74
|
const actualVolume = (0, round_volume_to_avoid_stack_overflow_1.roundVolumeToAvoidStackOverflow)(Math.min(1, baseVolume));
|
|
73
75
|
if (!volumeMap[actualVolume]) {
|
|
74
76
|
volumeMap[actualVolume] = [];
|
|
75
77
|
}
|
|
76
|
-
volumeMap[actualVolume].push(frame
|
|
78
|
+
volumeMap[actualVolume].push(frame);
|
|
77
79
|
});
|
|
78
80
|
// Sort the map so that the most common volume is last
|
|
79
81
|
// this is going to be the else statement so the expression is short
|
|
@@ -81,7 +83,7 @@ const ffmpegVolumeExpression = ({ volume, startInVideo, fps, }) => {
|
|
|
81
83
|
.map((key) => [Number(key), volumeMap[key]])
|
|
82
84
|
.sort((a, b) => a[1].length - b[1].length);
|
|
83
85
|
// Construct and tell FFMPEG it has to evaluate expression on each frame
|
|
84
|
-
const expression = ffmpegBuildVolumeExpression(volumeArray, fps);
|
|
86
|
+
const expression = ffmpegBuildVolumeExpression(volumeArray, trimLeft, fps);
|
|
85
87
|
return {
|
|
86
88
|
eval: 'frame',
|
|
87
89
|
value: `'${expression}'`,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AssetVolume, MediaAsset } from './types';
|
|
1
|
+
import type { AssetVolume, MediaAsset } from './types';
|
|
2
2
|
export declare const flattenVolumeArray: (volume: AssetVolume) => AssetVolume;
|
|
3
3
|
export declare const convertAssetToFlattenedVolume: (asset: MediaAsset) => MediaAsset;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}>;
|
|
1
|
+
import type { FfmpegExecutable } from '../ffmpeg-executable';
|
|
2
|
+
import type { AudioChannelsAndDurationResultCache, DownloadMap } from './download-map';
|
|
3
|
+
export declare const getAudioChannelsAndDuration: (downloadMap: DownloadMap, src: string, ffprobeExecutable: FfmpegExecutable) => Promise<AudioChannelsAndDurationResultCache>;
|