@remotion/renderer 3.0.19 → 3.0.22

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 (102) hide show
  1. package/dist/assets/get-audio-channels.d.ts +4 -2
  2. package/dist/assets/get-audio-channels.js +14 -3
  3. package/dist/browser/Browser.d.ts +209 -0
  4. package/dist/browser/Browser.js +402 -0
  5. package/dist/browser/BrowserConnector.d.ts +19 -0
  6. package/dist/browser/BrowserConnector.js +17 -0
  7. package/dist/browser/BrowserFetcher.d.ts +89 -0
  8. package/dist/browser/BrowserFetcher.js +492 -0
  9. package/dist/browser/BrowserRunner.d.ts +39 -0
  10. package/dist/browser/BrowserRunner.js +308 -0
  11. package/dist/browser/Connection.d.ts +49 -0
  12. package/dist/browser/Connection.js +262 -0
  13. package/dist/browser/ConnectionTransport.d.ts +21 -0
  14. package/dist/browser/ConnectionTransport.js +17 -0
  15. package/dist/browser/ConsoleMessage.d.ts +31 -0
  16. package/dist/browser/ConsoleMessage.js +48 -0
  17. package/dist/browser/DOMWorld.d.ts +50 -0
  18. package/dist/browser/DOMWorld.js +280 -0
  19. package/dist/browser/EmulationManager.d.ts +7 -0
  20. package/dist/browser/EmulationManager.js +40 -0
  21. package/dist/browser/Errors.d.ts +25 -0
  22. package/dist/browser/Errors.js +35 -0
  23. package/dist/browser/EvalTypes.d.ts +27 -0
  24. package/dist/browser/EvalTypes.js +17 -0
  25. package/dist/browser/EventEmitter.d.ts +70 -0
  26. package/dist/browser/EventEmitter.js +102 -0
  27. package/dist/browser/ExecutionContext.d.ts +33 -0
  28. package/dist/browser/ExecutionContext.js +174 -0
  29. package/dist/browser/FrameManager.d.ts +96 -0
  30. package/dist/browser/FrameManager.js +512 -0
  31. package/dist/browser/HTTPRequest.d.ts +28 -0
  32. package/dist/browser/HTTPRequest.js +37 -0
  33. package/dist/browser/HTTPResponse.d.ts +22 -0
  34. package/dist/browser/HTTPResponse.js +33 -0
  35. package/dist/browser/JSHandle.d.ts +36 -0
  36. package/dist/browser/JSHandle.js +93 -0
  37. package/dist/browser/LaunchOptions.d.ts +117 -0
  38. package/dist/browser/LaunchOptions.js +17 -0
  39. package/dist/browser/Launcher.d.ts +9 -0
  40. package/dist/browser/Launcher.js +602 -0
  41. package/dist/browser/LifecycleWatcher.d.ts +29 -0
  42. package/dist/browser/LifecycleWatcher.js +193 -0
  43. package/dist/browser/NetworkEventManager.d.ts +35 -0
  44. package/dist/browser/NetworkEventManager.js +128 -0
  45. package/dist/browser/NetworkManager.d.ts +36 -0
  46. package/dist/browser/NetworkManager.js +280 -0
  47. package/dist/browser/NodeWebSocketTransport.d.ts +17 -0
  48. package/dist/browser/NodeWebSocketTransport.js +90 -0
  49. package/dist/browser/Page.d.ts +74 -0
  50. package/dist/browser/Page.js +282 -0
  51. package/dist/browser/Product.d.ts +16 -0
  52. package/dist/browser/Product.js +17 -0
  53. package/dist/browser/PuppeteerNode.d.ts +89 -0
  54. package/dist/browser/PuppeteerNode.js +135 -0
  55. package/dist/browser/PuppeteerViewport.d.ts +5 -0
  56. package/dist/browser/PuppeteerViewport.js +2 -0
  57. package/dist/browser/ScreenshotOptions.d.ts +14 -0
  58. package/dist/browser/ScreenshotOptions.js +2 -0
  59. package/dist/browser/Target.d.ts +61 -0
  60. package/dist/browser/Target.js +146 -0
  61. package/dist/browser/TaskQueue.d.ts +20 -0
  62. package/dist/browser/TaskQueue.js +47 -0
  63. package/dist/browser/TimeoutSettings.d.ts +23 -0
  64. package/dist/browser/TimeoutSettings.js +62 -0
  65. package/dist/browser/assert.d.ts +21 -0
  66. package/dist/browser/assert.js +29 -0
  67. package/dist/browser/compat.d.ts +2 -0
  68. package/dist/browser/compat.js +17 -0
  69. package/dist/browser/create-browser-fetcher.d.ts +17 -0
  70. package/dist/browser/create-browser-fetcher.js +127 -0
  71. package/dist/browser/environment.d.ts +16 -0
  72. package/dist/browser/environment.js +19 -0
  73. package/dist/browser/get-download-destination.d.ts +1 -0
  74. package/dist/browser/get-download-destination.js +38 -0
  75. package/dist/browser/mitt/index.d.ts +22 -0
  76. package/dist/browser/mitt/index.js +49 -0
  77. package/dist/browser/node.d.ts +2 -0
  78. package/dist/browser/node.js +9 -0
  79. package/dist/browser/revisions.d.ts +21 -0
  80. package/dist/browser/revisions.js +22 -0
  81. package/dist/browser/util.d.ts +46 -0
  82. package/dist/browser/util.js +161 -0
  83. package/dist/ensure-presentation-timestamp.d.ts +1 -0
  84. package/dist/ensure-presentation-timestamp.js +57 -0
  85. package/dist/extract-frame-from-video.d.ts +4 -5
  86. package/dist/extract-frame-from-video.js +58 -27
  87. package/dist/index.d.ts +24 -0
  88. package/dist/index.js +11 -0
  89. package/dist/is-vp9-video.d.ts +3 -0
  90. package/dist/is-vp9-video.js +24 -0
  91. package/dist/last-frame-from-video-cache.d.ts +4 -3
  92. package/dist/last-frame-from-video-cache.js +9 -6
  93. package/dist/offthread-video-server.d.ts +2 -1
  94. package/dist/offthread-video-server.js +14 -3
  95. package/dist/open-browser.js +1 -2
  96. package/dist/prepare-server.js +11 -0
  97. package/dist/serve-handler/index.js +1 -8
  98. package/dist/should-use-vp9-decoder.d.ts +0 -0
  99. package/dist/should-use-vp9-decoder.js +1 -0
  100. package/dist/validate-offthreadvideo-image-format.d.ts +1 -0
  101. package/dist/validate-offthreadvideo-image-format.js +15 -0
  102. package/package.json +3 -3
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Mitt: Tiny (~200b) functional event emitter / pubsub.
5
+ * @name mitt
6
+ * @returns {Mitt}
7
+ */
8
+ function mitt(all) {
9
+ all = all || new Map();
10
+ return {
11
+ /**
12
+ * A Map of event names to registered handler functions.
13
+ */
14
+ all,
15
+ /**
16
+ * Register an event handler for the given type.
17
+ * @param {string|symbol} type Type of event to listen for, or `"*"` for all events
18
+ * @param {Function} handler Function to call in response to given event
19
+ * @memberOf mitt
20
+ */
21
+ on(type, handler) {
22
+ const handlers = all === null || all === void 0 ? void 0 : all.get(type);
23
+ const added = handlers === null || handlers === void 0 ? void 0 : handlers.push(handler);
24
+ if (!added) {
25
+ all === null || all === void 0 ? void 0 : all.set(type, [handler]);
26
+ }
27
+ },
28
+ off(type, handler) {
29
+ const handlers = all === null || all === void 0 ? void 0 : all.get(type);
30
+ if (handlers) {
31
+ // eslint-disable-next-line no-bitwise
32
+ handlers.splice(handlers.indexOf(handler) >>> 0, 1);
33
+ }
34
+ },
35
+ emit(type, evt) {
36
+ ((all === null || all === void 0 ? void 0 : all.get(type)) || [])
37
+ .slice()
38
+ .forEach((handler) => {
39
+ handler(evt);
40
+ });
41
+ ((all === null || all === void 0 ? void 0 : all.get('*')) || [])
42
+ .slice()
43
+ .forEach((handler) => {
44
+ handler(type, evt);
45
+ });
46
+ },
47
+ };
48
+ }
49
+ exports.default = mitt;
@@ -0,0 +1,2 @@
1
+ import { PuppeteerNode } from './PuppeteerNode';
2
+ export declare const puppeteer: PuppeteerNode;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.puppeteer = void 0;
4
+ const PuppeteerNode_1 = require("./PuppeteerNode");
5
+ const revisions_1 = require("./revisions");
6
+ exports.puppeteer = new PuppeteerNode_1.PuppeteerNode({
7
+ preferredRevision: revisions_1.PUPPETEER_REVISIONS.chromium,
8
+ productName: undefined,
9
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright 2020 Google Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ declare type Revisions = Readonly<{
17
+ readonly chromium: string;
18
+ readonly firefox: string;
19
+ }>;
20
+ export declare const PUPPETEER_REVISIONS: Revisions;
21
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2020 Google Inc. All rights reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.PUPPETEER_REVISIONS = void 0;
19
+ exports.PUPPETEER_REVISIONS = {
20
+ chromium: '1002410',
21
+ firefox: 'latest',
22
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Copyright 2017 Google Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /// <reference types="node" />
17
+ import type { Protocol } from 'devtools-protocol';
18
+ import { CDPSession } from './Connection';
19
+ import { CommonEventEmitter } from './EventEmitter';
20
+ export declare function getExceptionMessage(exceptionDetails: Protocol.Runtime.ExceptionDetails): string;
21
+ export declare function valueFromRemoteObject(remoteObject: Protocol.Runtime.RemoteObject): any;
22
+ export declare function releaseObject(client: CDPSession, remoteObject: Protocol.Runtime.RemoteObject): Promise<void>;
23
+ export interface PuppeteerEventListener {
24
+ emitter: CommonEventEmitter;
25
+ eventName: string | symbol;
26
+ handler: (...args: any[]) => void;
27
+ }
28
+ export declare function addEventListener(emitter: CommonEventEmitter, eventName: string | symbol, handler: (...args: any[]) => void): PuppeteerEventListener;
29
+ export declare function removeEventListeners(listeners: Array<{
30
+ emitter: CommonEventEmitter;
31
+ eventName: string | symbol;
32
+ handler: (...args: any[]) => void;
33
+ }>): void;
34
+ export declare const isString: (obj: unknown) => obj is string;
35
+ export declare function evaluationString(fun: Function | string, ...args: unknown[]): string;
36
+ export declare function pageBindingDeliverResultString(name: string, seq: number, result: unknown): string;
37
+ export declare function pageBindingDeliverErrorString(name: string, seq: number, message: string, stack?: string): string;
38
+ export declare function pageBindingDeliverErrorValueString(name: string, seq: number, value: unknown): string;
39
+ export declare function waitWithTimeout<T>(promise: Promise<T>, taskName: string, timeout: number): Promise<T>;
40
+ interface ErrorLike extends Error {
41
+ name: string;
42
+ message: string;
43
+ }
44
+ export declare function isErrorLike(obj: unknown): obj is ErrorLike;
45
+ export declare function isErrnoException(obj: unknown): obj is NodeJS.ErrnoException;
46
+ export {};
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2017 Google Inc. All rights reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.isErrnoException = exports.isErrorLike = exports.waitWithTimeout = exports.pageBindingDeliverErrorValueString = exports.pageBindingDeliverErrorString = exports.pageBindingDeliverResultString = exports.evaluationString = exports.isString = exports.removeEventListeners = exports.addEventListener = exports.releaseObject = exports.valueFromRemoteObject = exports.getExceptionMessage = void 0;
19
+ const assert_1 = require("./assert");
20
+ const Errors_1 = require("./Errors");
21
+ function getExceptionMessage(exceptionDetails) {
22
+ if (exceptionDetails.exception) {
23
+ return (exceptionDetails.exception.description || exceptionDetails.exception.value);
24
+ }
25
+ let message = exceptionDetails.text;
26
+ if (exceptionDetails.stackTrace) {
27
+ for (const callframe of exceptionDetails.stackTrace.callFrames) {
28
+ const location = callframe.url +
29
+ ':' +
30
+ callframe.lineNumber +
31
+ ':' +
32
+ callframe.columnNumber;
33
+ const functionName = callframe.functionName || '<anonymous>';
34
+ message += `\n at ${functionName} (${location})`;
35
+ }
36
+ }
37
+ return message;
38
+ }
39
+ exports.getExceptionMessage = getExceptionMessage;
40
+ function valueFromRemoteObject(remoteObject) {
41
+ (0, assert_1.assert)(!remoteObject.objectId, 'Cannot extract value when objectId is given');
42
+ if (remoteObject.unserializableValue) {
43
+ if (remoteObject.type === 'bigint' && typeof BigInt !== 'undefined') {
44
+ return BigInt(remoteObject.unserializableValue.replace('n', ''));
45
+ }
46
+ switch (remoteObject.unserializableValue) {
47
+ case '-0':
48
+ return -0;
49
+ case 'NaN':
50
+ return NaN;
51
+ case 'Infinity':
52
+ return Infinity;
53
+ case '-Infinity':
54
+ return -Infinity;
55
+ default:
56
+ throw new Error('Unsupported unserializable value: ' +
57
+ remoteObject.unserializableValue);
58
+ }
59
+ }
60
+ return remoteObject.value;
61
+ }
62
+ exports.valueFromRemoteObject = valueFromRemoteObject;
63
+ async function releaseObject(client, remoteObject) {
64
+ if (!remoteObject.objectId) {
65
+ return;
66
+ }
67
+ await client
68
+ .send('Runtime.releaseObject', { objectId: remoteObject.objectId })
69
+ .catch(() => {
70
+ // Exceptions might happen in case of a page been navigated or closed.
71
+ // Swallow these since they are harmless and we don't leak anything in this case.
72
+ });
73
+ }
74
+ exports.releaseObject = releaseObject;
75
+ function addEventListener(emitter, eventName, handler) {
76
+ emitter.on(eventName, handler);
77
+ return { emitter, eventName, handler };
78
+ }
79
+ exports.addEventListener = addEventListener;
80
+ function removeEventListeners(listeners) {
81
+ for (const listener of listeners) {
82
+ listener.emitter.removeListener(listener.eventName, listener.handler);
83
+ }
84
+ listeners.length = 0;
85
+ }
86
+ exports.removeEventListeners = removeEventListeners;
87
+ const isString = (obj) => {
88
+ return typeof obj === 'string' || obj instanceof String;
89
+ };
90
+ exports.isString = isString;
91
+ function evaluationString(fun, ...args) {
92
+ if ((0, exports.isString)(fun)) {
93
+ (0, assert_1.assert)(args.length === 0, 'Cannot evaluate a string with arguments');
94
+ return fun;
95
+ }
96
+ function serializeArgument(arg) {
97
+ if (Object.is(arg, undefined)) {
98
+ return 'undefined';
99
+ }
100
+ return JSON.stringify(arg);
101
+ }
102
+ return `(${fun})(${args.map(serializeArgument).join(',')})`;
103
+ }
104
+ exports.evaluationString = evaluationString;
105
+ function pageBindingDeliverResultString(name, seq, result) {
106
+ function deliverResult(_name, _seq, _result) {
107
+ window[_name].callbacks.get(_seq).resolve(_result);
108
+ window[_name].callbacks.delete(_seq);
109
+ }
110
+ return evaluationString(deliverResult, name, seq, result);
111
+ }
112
+ exports.pageBindingDeliverResultString = pageBindingDeliverResultString;
113
+ function pageBindingDeliverErrorString(name, seq, message, stack) {
114
+ function deliverError(_name, _seq, _message, _stack) {
115
+ const error = new Error(_message);
116
+ error.stack = _stack;
117
+ window[_name].callbacks.get(_seq).reject(error);
118
+ window[_name].callbacks.delete(_seq);
119
+ }
120
+ return evaluationString(deliverError, name, seq, message, stack);
121
+ }
122
+ exports.pageBindingDeliverErrorString = pageBindingDeliverErrorString;
123
+ function pageBindingDeliverErrorValueString(name, seq, value) {
124
+ function deliverErrorValue(_name, _seq, _value) {
125
+ window[_name].callbacks.get(_seq).reject(_value);
126
+ window[_name].callbacks.delete(_seq);
127
+ }
128
+ return evaluationString(deliverErrorValue, name, seq, value);
129
+ }
130
+ exports.pageBindingDeliverErrorValueString = pageBindingDeliverErrorValueString;
131
+ async function waitWithTimeout(promise, taskName, timeout) {
132
+ let reject;
133
+ const timeoutError = new Errors_1.TimeoutError(`waiting for ${taskName} failed: timeout ${timeout}ms exceeded`);
134
+ const timeoutPromise = new Promise((_res, rej) => {
135
+ reject = rej;
136
+ });
137
+ let timeoutTimer = null;
138
+ if (timeout) {
139
+ timeoutTimer = setTimeout(() => {
140
+ return reject(timeoutError);
141
+ }, timeout);
142
+ }
143
+ try {
144
+ return await Promise.race([promise, timeoutPromise]);
145
+ }
146
+ finally {
147
+ if (timeoutTimer) {
148
+ clearTimeout(timeoutTimer);
149
+ }
150
+ }
151
+ }
152
+ exports.waitWithTimeout = waitWithTimeout;
153
+ function isErrorLike(obj) {
154
+ return (typeof obj === 'object' && obj !== null && 'name' in obj && 'message' in obj);
155
+ }
156
+ exports.isErrorLike = isErrorLike;
157
+ function isErrnoException(obj) {
158
+ return (isErrorLike(obj) &&
159
+ ('errno' in obj || 'code' in obj || 'path' in obj || 'syscall' in obj));
160
+ }
161
+ exports.isErrnoException = isErrnoException;
@@ -0,0 +1 @@
1
+ export declare const ensurePresentationTimestamps: (src: string) => Promise<unknown>;
@@ -0,0 +1,57 @@
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 = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const promises_1 = require("fs/promises");
9
+ const path_1 = __importDefault(require("path"));
10
+ const ensureFileHasPresentationTimestamp = {};
11
+ let callbacks = [];
12
+ const ensurePresentationTimestamps = async (src) => {
13
+ if (ensureFileHasPresentationTimestamp[src] === 'encoding') {
14
+ return new Promise((resolve) => {
15
+ callbacks.push({
16
+ src,
17
+ fn: () => resolve,
18
+ });
19
+ });
20
+ }
21
+ if (ensureFileHasPresentationTimestamp[src] === 'done') {
22
+ return;
23
+ }
24
+ ensureFileHasPresentationTimestamp[src] = 'encoding';
25
+ const parts = src.split(path_1.default.sep);
26
+ const output = parts
27
+ .map((p, i) => {
28
+ if (i === parts.length - 1) {
29
+ return `pts-${p}`;
30
+ }
31
+ return p;
32
+ })
33
+ .join(path_1.default.sep);
34
+ await (0, execa_1.default)('ffmpeg', [
35
+ '-i',
36
+ src,
37
+ '-fflags',
38
+ '+genpts+igndts',
39
+ '-vcodec',
40
+ 'copy',
41
+ '-acodec',
42
+ 'copy',
43
+ output,
44
+ '-y',
45
+ ]);
46
+ await (0, promises_1.unlink)(src);
47
+ await (0, promises_1.rename)(output, src);
48
+ callbacks = callbacks.filter((c) => {
49
+ if (c.src === src) {
50
+ c.fn();
51
+ return false;
52
+ }
53
+ return true;
54
+ });
55
+ ensureFileHasPresentationTimestamp[src] = 'done';
56
+ };
57
+ exports.ensurePresentationTimestamps = ensurePresentationTimestamps;
@@ -1,16 +1,15 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { FfmpegExecutable } from 'remotion';
4
- import { Readable } from 'stream';
2
+ import { FfmpegExecutable, OffthreadVideoImageFormat } from 'remotion';
3
+ import { SpecialVCodecForTransparency } from './is-vp9-video';
5
4
  import { LastFrameOptions } from './last-frame-from-video-cache';
6
- export declare function streamToString(stream: Readable): Promise<string>;
5
+ export declare const determineVcodecFfmepgFlags: (vcodecFlag: SpecialVCodecForTransparency) => string[];
7
6
  export declare const getLastFrameOfVideo: (options: LastFrameOptions) => Promise<Buffer>;
8
7
  declare type Options = {
9
8
  time: number;
10
9
  src: string;
11
10
  ffmpegExecutable: FfmpegExecutable;
12
11
  ffprobeExecutable: FfmpegExecutable;
12
+ imageFormat: OffthreadVideoImageFormat;
13
13
  };
14
- export declare const extractFrameFromVideoFn: ({ time, src, ffmpegExecutable, ffprobeExecutable, }: Options) => Promise<Buffer>;
15
14
  export declare const extractFrameFromVideo: (options: Options) => Promise<Buffer>;
16
15
  export {};
@@ -3,41 +3,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extractFrameFromVideo = exports.extractFrameFromVideoFn = exports.getLastFrameOfVideo = exports.streamToString = void 0;
6
+ exports.extractFrameFromVideo = exports.getLastFrameOfVideo = exports.determineVcodecFfmepgFlags = void 0;
7
7
  const execa_1 = __importDefault(require("execa"));
8
8
  const remotion_1 = require("remotion");
9
+ const get_audio_channels_1 = require("./assets/get-audio-channels");
10
+ const ensure_presentation_timestamp_1 = require("./ensure-presentation-timestamp");
9
11
  const frame_to_ffmpeg_timestamp_1 = require("./frame-to-ffmpeg-timestamp");
10
- const get_duration_of_asset_1 = require("./get-duration-of-asset");
11
12
  const is_beyond_last_frame_1 = require("./is-beyond-last-frame");
13
+ const is_vp9_video_1 = require("./is-vp9-video");
12
14
  const last_frame_from_video_cache_1 = require("./last-frame-from-video-cache");
13
15
  const p_limit_1 = require("./p-limit");
14
- function streamToString(stream) {
15
- const chunks = [];
16
- return new Promise((resolve, reject) => {
17
- stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
18
- stream.on('error', (err) => reject(err));
19
- stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
20
- });
21
- }
22
- exports.streamToString = streamToString;
23
16
  const lastFrameLimit = (0, p_limit_1.pLimit)(1);
24
17
  const mainLimit = (0, p_limit_1.pLimit)(5);
18
+ const determineVcodecFfmepgFlags = (vcodecFlag) => {
19
+ return [
20
+ vcodecFlag === 'vp9' ? '-vcodec' : null,
21
+ vcodecFlag === 'vp9' ? 'libvpx-vp9' : null,
22
+ vcodecFlag === 'vp8' ? '-vcodec' : null,
23
+ vcodecFlag === 'vp8' ? 'libvpx' : null,
24
+ ].filter(remotion_1.Internals.truthy);
25
+ };
26
+ exports.determineVcodecFfmepgFlags = determineVcodecFfmepgFlags;
25
27
  // Uses no seeking, therefore the whole video has to be decoded. This is a last resort and should only happen
26
28
  // if the video is corrupted
27
- const getLastFrameOfVideoSlow = async ({ src, duration, ffmpegExecutable, }) => {
28
- console.warn(`\nUsing a slow method to determine the last frame of ${src}. The render can be sped up by re-encoding the video properly.`);
29
- const actualOffset = `-${duration * 1000}ms`;
29
+ const getFrameOfVideoSlow = async ({ src, timestamp, ffmpegExecutable, imageFormat, specialVCodecForTransparency, }) => {
30
+ console.warn(`\nUsing a slow method to extract the frame at ${timestamp}ms of ${src}. See https://remotion.dev/docs/slow-method-to-extract-frame for advice`);
31
+ const actualOffset = `-${timestamp * 1000}ms`;
30
32
  const command = [
31
33
  '-itsoffset',
32
34
  actualOffset,
35
+ ...(0, exports.determineVcodecFfmepgFlags)(specialVCodecForTransparency),
33
36
  '-i',
34
37
  src,
35
38
  '-frames:v',
36
39
  '1',
40
+ '-c:v',
41
+ imageFormat === 'jpeg' ? 'mjpeg' : 'png',
37
42
  '-f',
38
43
  'image2pipe',
39
44
  '-',
40
- ];
45
+ ].filter(remotion_1.Internals.truthy);
41
46
  const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', command);
42
47
  if (!stderr) {
43
48
  throw new Error('unexpectedly did not get stderr');
@@ -70,15 +75,17 @@ const getLastFrameOfVideoFastUnlimited = async (options) => {
70
75
  if (fromCache) {
71
76
  return fromCache;
72
77
  }
73
- const duration = await (0, get_duration_of_asset_1.getDurationOfAsset)({
74
- src,
75
- ffprobeExecutable,
76
- });
77
- if (offset > 40) {
78
- const last = await getLastFrameOfVideoSlow({
79
- duration,
78
+ const { duration } = await (0, get_audio_channels_1.getAudioChannelsAndDuration)(src, ffprobeExecutable);
79
+ if (duration === null) {
80
+ throw new Error(`Could not determine the duration of ${src} using FFMPEG. The file is not supported.`);
81
+ }
82
+ if (options.specialVCodecForTransparency === 'vp8' || offset > 40) {
83
+ const last = await getFrameOfVideoSlow({
84
+ timestamp: duration,
80
85
  ffmpegExecutable,
81
86
  src,
87
+ imageFormat: options.imageFormat,
88
+ specialVCodecForTransparency: options.specialVCodecForTransparency,
82
89
  });
83
90
  return last;
84
91
  }
@@ -86,14 +93,17 @@ const getLastFrameOfVideoFastUnlimited = async (options) => {
86
93
  const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
87
94
  '-ss',
88
95
  actualOffset,
96
+ ...(0, exports.determineVcodecFfmepgFlags)(options.specialVCodecForTransparency),
89
97
  '-i',
90
98
  src,
91
99
  '-frames:v',
92
100
  '1',
101
+ '-c:v',
102
+ options.imageFormat === 'jpeg' ? 'mjpeg' : 'png',
93
103
  '-f',
94
104
  'image2pipe',
95
105
  '-',
96
- ]);
106
+ ].filter(remotion_1.Internals.truthy));
97
107
  if (!stderr) {
98
108
  throw new Error('unexpectedly did not get stderr');
99
109
  }
@@ -126,6 +136,8 @@ const getLastFrameOfVideoFastUnlimited = async (options) => {
126
136
  offset: offset + 10,
127
137
  src,
128
138
  ffprobeExecutable,
139
+ imageFormat: options.imageFormat,
140
+ specialVCodecForTransparency: options.specialVCodecForTransparency,
129
141
  });
130
142
  return unlimited;
131
143
  }
@@ -137,13 +149,28 @@ const getLastFrameOfVideo = async (options) => {
137
149
  return result;
138
150
  };
139
151
  exports.getLastFrameOfVideo = getLastFrameOfVideo;
140
- const extractFrameFromVideoFn = async ({ time, src, ffmpegExecutable, ffprobeExecutable, }) => {
152
+ const extractFrameFromVideoFn = async ({ time, src, ffmpegExecutable, ffprobeExecutable, imageFormat, }) => {
153
+ await (0, ensure_presentation_timestamp_1.ensurePresentationTimestamps)(src);
154
+ const specialVCodecForTransparency = imageFormat === 'jpeg'
155
+ ? 'none'
156
+ : await (0, is_vp9_video_1.getSpecialVCodecForTransparency)(src, ffprobeExecutable);
157
+ if (specialVCodecForTransparency === 'vp8') {
158
+ return getFrameOfVideoSlow({
159
+ ffmpegExecutable,
160
+ imageFormat,
161
+ specialVCodecForTransparency,
162
+ src,
163
+ timestamp: time,
164
+ });
165
+ }
141
166
  if ((0, is_beyond_last_frame_1.isBeyondLastFrame)(src, time)) {
142
167
  const lastFrame = await (0, exports.getLastFrameOfVideo)({
143
168
  ffmpegExecutable,
144
169
  ffprobeExecutable,
145
170
  offset: 0,
146
171
  src,
172
+ imageFormat,
173
+ specialVCodecForTransparency,
147
174
  });
148
175
  return lastFrame;
149
176
  }
@@ -151,14 +178,17 @@ const extractFrameFromVideoFn = async ({ time, src, ffmpegExecutable, ffprobeExe
151
178
  const { stdout, stderr } = (0, execa_1.default)(ffmpegExecutable !== null && ffmpegExecutable !== void 0 ? ffmpegExecutable : 'ffmpeg', [
152
179
  '-ss',
153
180
  ffmpegTimestamp,
181
+ ...(0, exports.determineVcodecFfmepgFlags)(specialVCodecForTransparency),
154
182
  '-i',
155
183
  src,
156
184
  '-frames:v',
157
185
  '1',
158
186
  '-f',
159
187
  'image2pipe',
188
+ '-vcodec',
189
+ imageFormat === 'jpeg' ? 'mjpeg' : 'png',
160
190
  '-',
161
- ], {
191
+ ].filter(remotion_1.Internals.truthy), {
162
192
  buffer: false,
163
193
  });
164
194
  if (!stderr) {
@@ -190,15 +220,16 @@ const extractFrameFromVideoFn = async ({ time, src, ffmpegExecutable, ffprobeExe
190
220
  ffprobeExecutable,
191
221
  offset: 0,
192
222
  src,
223
+ imageFormat,
224
+ specialVCodecForTransparency,
193
225
  });
194
226
  return last;
195
227
  }
196
228
  return stdOut;
197
229
  };
198
- exports.extractFrameFromVideoFn = extractFrameFromVideoFn;
199
230
  const extractFrameFromVideo = async (options) => {
200
231
  const perf = remotion_1.Internals.perf.startPerfMeasure('extract-frame');
201
- const res = await mainLimit(exports.extractFrameFromVideoFn, options);
232
+ const res = await mainLimit(extractFrameFromVideoFn, options);
202
233
  remotion_1.Internals.perf.stopPerfMeasure(perf);
203
234
  return res;
204
235
  };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /// <reference types="node" />
2
+ import execa from 'execa';
3
+ import mime from 'mime-types';
1
4
  import { SymbolicateableError } from './error-handling/symbolicateable-error';
2
5
  export type { RenderMediaOnDownload } from './assets/download-and-map-assets-to-file';
3
6
  export { BrowserLog } from './browser-log';
@@ -73,4 +76,25 @@ export declare const RenderInternals: {
73
76
  SymbolicateableError: typeof SymbolicateableError;
74
77
  getDurationFromFrameRange: (frameRange: import("remotion").FrameRange | null, durationInFrames: number) => number;
75
78
  getExtensionOfFilename: (filename: string) => string | null;
79
+ getDesiredPort: (desiredPort: number | undefined, from: number, to: number) => Promise<number>;
80
+ mime: typeof mime;
81
+ isPathInside: (thePath: string, potentialParent: string) => boolean;
82
+ execa: {
83
+ (file: string, arguments?: readonly string[] | undefined, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
84
+ (file: string, arguments?: readonly string[] | undefined, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
85
+ (file: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
86
+ (file: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
87
+ sync(file: string, arguments?: readonly string[] | undefined, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
88
+ sync(file: string, arguments?: readonly string[] | undefined, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
89
+ sync(file: string, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
90
+ sync(file: string, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
91
+ command(command: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
92
+ command(command: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
93
+ commandSync(command: string, options?: execa.SyncOptions<string> | undefined): execa.ExecaSyncReturnValue<string>;
94
+ commandSync(command: string, options?: execa.SyncOptions<null> | undefined): execa.ExecaSyncReturnValue<Buffer>;
95
+ node(scriptPath: string, arguments?: readonly string[] | undefined, options?: execa.NodeOptions<string> | undefined): execa.ExecaChildProcess<string>;
96
+ node(scriptPath: string, arguments?: readonly string[] | undefined, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
97
+ node(scriptPath: string, options?: execa.Options<string> | undefined): execa.ExecaChildProcess<string>;
98
+ node(scriptPath: string, options?: execa.Options<null> | undefined): execa.ExecaChildProcess<Buffer>;
99
+ };
76
100
  };
package/dist/index.js CHANGED
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.RenderInternals = exports.stitchFramesToVideo = exports.renderStill = exports.renderMedia = exports.renderFrames = exports.openBrowser = exports.makeCancelSignal = exports.getCompositions = exports.ErrorWithStackFrame = exports.combineVideos = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const mime_types_1 = __importDefault(require("mime-types"));
4
9
  const download_file_1 = require("./assets/download-file");
5
10
  const delete_directory_1 = require("./delete-directory");
6
11
  const ensure_output_directory_1 = require("./ensure-output-directory");
@@ -13,10 +18,12 @@ const get_extension_from_codec_1 = require("./get-extension-from-codec");
13
18
  const get_extension_of_filename_1 = require("./get-extension-of-filename");
14
19
  const get_frame_to_render_1 = require("./get-frame-to-render");
15
20
  const get_local_browser_executable_1 = require("./get-local-browser-executable");
21
+ const get_port_1 = require("./get-port");
16
22
  const is_serve_url_1 = require("./is-serve-url");
17
23
  const normalize_serve_url_1 = require("./normalize-serve-url");
18
24
  const open_browser_1 = require("./open-browser");
19
25
  const parse_browser_error_stack_1 = require("./parse-browser-error-stack");
26
+ const is_path_inside_1 = require("./serve-handler/is-path-inside");
20
27
  const serve_static_1 = require("./serve-static");
21
28
  const stitch_frames_to_video_1 = require("./stitch-frames-to-video");
22
29
  const tmp_dir_1 = require("./tmp-dir");
@@ -69,4 +76,8 @@ exports.RenderInternals = {
69
76
  SymbolicateableError: symbolicateable_error_1.SymbolicateableError,
70
77
  getDurationFromFrameRange: get_duration_from_frame_range_1.getDurationFromFrameRange,
71
78
  getExtensionOfFilename: get_extension_of_filename_1.getExtensionOfFilename,
79
+ getDesiredPort: get_port_1.getDesiredPort,
80
+ mime: mime_types_1.default,
81
+ isPathInside: is_path_inside_1.isPathInside,
82
+ execa: execa_1.default,
72
83
  };
@@ -0,0 +1,3 @@
1
+ import { FfmpegExecutable } from 'remotion';
2
+ export declare type SpecialVCodecForTransparency = 'vp9' | 'vp8' | 'none';
3
+ export declare const getSpecialVCodecForTransparency: (src: string, ffprobeExecutable: FfmpegExecutable) => Promise<SpecialVCodecForTransparency>;