@alpha2-sh/editor 0.4.6 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/bridge.d.ts +15 -16
- package/dist/browser/bridge.js +393 -312
- package/dist/browser/extensions-worker.d.ts +12 -16
- package/dist/browser/extensions-worker.js +17 -24
- package/dist/browser/hash-worker.d.ts +4 -5
- package/dist/browser/hash-worker.js +7 -8
- package/dist/browser/jobs.d.ts +17 -19
- package/dist/browser/jobs.js +41 -28
- package/dist/browser/resources.d.ts +6 -11
- package/dist/browser/resources.js +5 -9
- package/dist/browser/runtime/assets.d.ts +52 -28
- package/dist/browser/runtime/assets.js +136 -45
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +102 -59
- package/dist/browser/runtime/budget.d.ts +4 -5
- package/dist/browser/runtime/budget.js +4 -5
- package/dist/browser/runtime/caption-fonts.d.ts +3 -7
- package/dist/browser/runtime/caption-fonts.js +4 -8
- package/dist/browser/runtime/engine.d.ts +44 -44
- package/dist/browser/runtime/engine.js +87 -64
- package/dist/browser/runtime/export-audio.d.ts +6 -6
- package/dist/browser/runtime/export-audio.js +8 -9
- package/dist/browser/runtime/exporter.d.ts +33 -66
- package/dist/browser/runtime/exporter.js +111 -137
- package/dist/browser/runtime/extension-import.d.ts +28 -35
- package/dist/browser/runtime/extension-import.js +36 -46
- package/dist/browser/runtime/fingerprint.d.ts +11 -14
- package/dist/browser/runtime/fingerprint.js +20 -24
- package/dist/browser/runtime/generators.d.ts +2 -3
- package/dist/browser/runtime/generators.js +5 -7
- package/dist/browser/runtime/locks.d.ts +5 -7
- package/dist/browser/runtime/locks.js +5 -7
- package/dist/browser/runtime/output.d.ts +7 -9
- package/dist/browser/runtime/output.js +17 -21
- package/dist/browser/runtime/preview-utils.js +10 -6
- package/dist/browser/runtime/proxies.d.ts +19 -19
- package/dist/browser/runtime/proxies.js +72 -51
- package/dist/browser/runtime/proxy-storage.d.ts +15 -19
- package/dist/browser/runtime/proxy-storage.js +20 -24
- package/dist/browser/runtime/sources.d.ts +23 -31
- package/dist/browser/runtime/sources.js +85 -103
- package/dist/browser/runtime/staging.d.ts +2 -6
- package/dist/browser/runtime/staging.js +7 -11
- package/dist/browser/runtime/still.d.ts +2 -6
- package/dist/browser/runtime/still.js +6 -12
- package/dist/browser/runtime/text.d.ts +14 -0
- package/dist/browser/runtime/text.js +27 -0
- package/dist/browser/runtime/wasm.d.ts +4 -5
- package/dist/browser/runtime/wasm.js +4 -5
- package/dist/browser/types.d.ts +244 -239
- package/dist/browser/worker.d.ts +10 -10
- package/dist/browser/worker.js +64 -22
- package/dist/core/captions.d.ts +8 -10
- package/dist/core/captions.js +10 -18
- package/dist/core/clip-time.d.ts +8 -10
- package/dist/core/clip-time.js +12 -15
- package/dist/core/commands.d.ts +46 -46
- package/dist/core/commands.js +38 -36
- package/dist/core/compositions.d.ts +78 -112
- package/dist/core/compositions.js +66 -94
- package/dist/core/document.d.ts +59 -92
- package/dist/core/document.js +65 -90
- package/dist/core/keyframes.d.ts +11 -12
- package/dist/core/keyframes.js +11 -13
- package/dist/core/presets.d.ts +14 -20
- package/dist/core/presets.js +12 -18
- package/dist/core/session.d.ts +26 -38
- package/dist/core/session.js +38 -53
- package/dist/core/text.d.ts +2 -3
- package/dist/core/text.js +2 -3
- package/dist/core/timeline-index.d.ts +2 -3
- package/dist/core/timeline-index.js +11 -7
- package/dist/core/transitions.js +4 -5
- package/dist/core/validated.d.ts +6 -7
- package/dist/core/validated.js +8 -11
- package/dist/native-client/index.d.ts +31 -32
- package/dist/native-client/index.js +40 -41
- package/dist/ports/index.d.ts +19 -20
- package/dist/react/index.d.ts +5 -6
- package/dist/react/index.js +5 -6
- package/package.json +4 -4
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What a video container holds, read by the demuxer: its picture (`video`: size, frame rate,
|
|
3
|
-
* declaration, and whether WebCodecs decodes it
|
|
4
|
-
*
|
|
2
|
+
* What a video container holds, read by the demuxer: its picture (`video`: size, frame rate, HDR
|
|
3
|
+
* declaration, and whether WebCodecs decodes it, or null without a video track) and whether it
|
|
4
|
+
* has audio. Null when the demuxer cannot read the container.
|
|
5
5
|
*/
|
|
6
6
|
export function probeVideo(file: any): Promise<{
|
|
7
|
+
audioStreams?: import("alpha2").AudioStreamFacts[] | undefined;
|
|
8
|
+
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
7
9
|
video: {
|
|
8
10
|
colorMetadata: import("alpha2/project").ColorMetadata | null;
|
|
9
11
|
width: number;
|
|
10
12
|
height: number;
|
|
11
13
|
frameRate: number;
|
|
12
14
|
decodable: boolean;
|
|
15
|
+
facts: import("alpha2/hdr-frames").TrackDecodeFacts;
|
|
13
16
|
} | null;
|
|
14
17
|
hasAudio: boolean;
|
|
15
18
|
audioDecodable: boolean;
|
|
16
19
|
} | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Why an import failed, in this editor's words. Browser error text (`MediaError`, decoder
|
|
22
|
+
* `DOMException`) exposes engine internals, so it is never shown and stays the error's cause.
|
|
23
|
+
* `facts` describe the video track when the probe read one.
|
|
24
|
+
*/
|
|
25
|
+
export function importFailureReason(error: any, kind: any, facts: any): string;
|
|
17
26
|
/**
|
|
18
27
|
* Streams a file's primary audio track into per-bucket peak magnitudes (`bucketsPerSecond`, capped
|
|
19
28
|
* at `maxBuckets`) with bounded memory. A bucket's peak is its loudest sample in any channel,
|
|
@@ -40,6 +49,15 @@ export const DEFAULT_TEXT: Readonly<{
|
|
|
40
49
|
readonly lineHeight: 1.15;
|
|
41
50
|
}>;
|
|
42
51
|
export class AssetLibrary {
|
|
52
|
+
/**
|
|
53
|
+
* `hdrWithoutPlanes` handles HDR video this browser decodes only to frames without planes and has
|
|
54
|
+
* no software decoder for: `"refuse"` (the default) refuses its import with `unsupported_media`;
|
|
55
|
+
* `"preview-degraded"` imports it with `planarDecode: "unavailable"` for a tone-mapped preview
|
|
56
|
+
* that the bridge refuses to export.
|
|
57
|
+
*/
|
|
58
|
+
constructor({ hdrWithoutPlanes }?: {
|
|
59
|
+
hdrWithoutPlanes?: string | undefined;
|
|
60
|
+
});
|
|
43
61
|
get map(): Map<any, any>;
|
|
44
62
|
get all(): any[];
|
|
45
63
|
get(id: any): any;
|
|
@@ -72,13 +90,13 @@ export class AssetLibrary {
|
|
|
72
90
|
name: any;
|
|
73
91
|
locator: any;
|
|
74
92
|
file: any;
|
|
75
|
-
text:
|
|
93
|
+
text: string;
|
|
76
94
|
}>;
|
|
77
95
|
usedBy(doc: any): Set<any>;
|
|
78
96
|
remove(id: any): void;
|
|
79
97
|
/**
|
|
80
|
-
* Imports browser files; each
|
|
81
|
-
*
|
|
98
|
+
* Imports browser files; each failure is reported with its name and reason (see {@link
|
|
99
|
+
* importFile}).
|
|
82
100
|
*/
|
|
83
101
|
importFiles(files: any, onProgress: any): Promise<{
|
|
84
102
|
imported: ({
|
|
@@ -93,6 +111,13 @@ export class AssetLibrary {
|
|
|
93
111
|
fit: string;
|
|
94
112
|
thumbnail: HTMLCanvasElement;
|
|
95
113
|
} | {
|
|
114
|
+
colorMetadata: any;
|
|
115
|
+
planarDecode: string;
|
|
116
|
+
fit: string;
|
|
117
|
+
thumbnail: null;
|
|
118
|
+
peaks: null;
|
|
119
|
+
audioStreams?: any;
|
|
120
|
+
audioDecodeFacts?: any;
|
|
96
121
|
id: any;
|
|
97
122
|
kind: string;
|
|
98
123
|
name: any;
|
|
@@ -106,11 +131,11 @@ export class AssetLibrary {
|
|
|
106
131
|
duration: number;
|
|
107
132
|
hasAudio: any;
|
|
108
133
|
audioDecodable: any;
|
|
109
|
-
colorMetadata: any;
|
|
110
|
-
fit: string;
|
|
111
|
-
thumbnail: null;
|
|
112
|
-
peaks: null;
|
|
113
134
|
} | {
|
|
135
|
+
peaks: null;
|
|
136
|
+
thumbnail: null;
|
|
137
|
+
audioStreams?: import("alpha2").AudioStreamFacts[] | undefined;
|
|
138
|
+
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
114
139
|
id: any;
|
|
115
140
|
kind: string;
|
|
116
141
|
name: any;
|
|
@@ -119,8 +144,6 @@ export class AssetLibrary {
|
|
|
119
144
|
duration: number;
|
|
120
145
|
hasAudio: boolean;
|
|
121
146
|
audioDecodable: boolean;
|
|
122
|
-
peaks: null;
|
|
123
|
-
thumbnail: null;
|
|
124
147
|
})[];
|
|
125
148
|
rejected: {
|
|
126
149
|
name: any;
|
|
@@ -130,10 +153,9 @@ export class AssetLibrary {
|
|
|
130
153
|
}>;
|
|
131
154
|
/**
|
|
132
155
|
* Imports one browser file as an image, video or audio asset. Rejects with an `EditorError`:
|
|
133
|
-
* `unsupported_media` for a file that is none of those, `unreadable_media`
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* reason once it aborts a decode.
|
|
156
|
+
* `unsupported_media` for a file that is none of those, `unreadable_media` when this browser
|
|
157
|
+
* cannot read it (with the decoder's or demuxer's reason as message and `cause`), or with
|
|
158
|
+
* `signal`'s reason once it aborts a decode.
|
|
137
159
|
*/
|
|
138
160
|
importFile(file: any, { signal }?: {}): Promise<{
|
|
139
161
|
id: any;
|
|
@@ -147,6 +169,13 @@ export class AssetLibrary {
|
|
|
147
169
|
fit: string;
|
|
148
170
|
thumbnail: HTMLCanvasElement;
|
|
149
171
|
} | {
|
|
172
|
+
colorMetadata: any;
|
|
173
|
+
planarDecode: string;
|
|
174
|
+
fit: string;
|
|
175
|
+
thumbnail: null;
|
|
176
|
+
peaks: null;
|
|
177
|
+
audioStreams?: any;
|
|
178
|
+
audioDecodeFacts?: any;
|
|
150
179
|
id: any;
|
|
151
180
|
kind: string;
|
|
152
181
|
name: any;
|
|
@@ -160,11 +189,11 @@ export class AssetLibrary {
|
|
|
160
189
|
duration: number;
|
|
161
190
|
hasAudio: any;
|
|
162
191
|
audioDecodable: any;
|
|
163
|
-
colorMetadata: any;
|
|
164
|
-
fit: string;
|
|
165
|
-
thumbnail: null;
|
|
166
|
-
peaks: null;
|
|
167
192
|
} | {
|
|
193
|
+
peaks: null;
|
|
194
|
+
thumbnail: null;
|
|
195
|
+
audioStreams?: import("alpha2").AudioStreamFacts[] | undefined;
|
|
196
|
+
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
168
197
|
id: any;
|
|
169
198
|
kind: string;
|
|
170
199
|
name: any;
|
|
@@ -173,8 +202,6 @@ export class AssetLibrary {
|
|
|
173
202
|
duration: number;
|
|
174
203
|
hasAudio: boolean;
|
|
175
204
|
audioDecodable: boolean;
|
|
176
|
-
peaks: null;
|
|
177
|
-
thumbnail: null;
|
|
178
205
|
}>;
|
|
179
206
|
/** Registers a project-rate audio buffer synthesized in the page rather than read from a file. */
|
|
180
207
|
addGeneratedAudio(name: any, audioBuffer: any): {
|
|
@@ -188,10 +215,7 @@ export class AssetLibrary {
|
|
|
188
215
|
peaks: Float32Array<ArrayBuffer>;
|
|
189
216
|
thumbnail: null;
|
|
190
217
|
};
|
|
191
|
-
/**
|
|
192
|
-
* Creates a text source rasterized by the packaged `OffscreenTextRasterizer`, the browser host
|
|
193
|
-
* for the engine's host-rasterized text contract.
|
|
194
|
-
*/
|
|
218
|
+
/** Creates a text source rasterized by the packaged `OffscreenTextRasterizer`. */
|
|
195
219
|
createText(style?: {}, { id }?: {
|
|
196
220
|
id?: string | undefined;
|
|
197
221
|
}): {
|
|
@@ -213,8 +237,8 @@ export class AssetLibrary {
|
|
|
213
237
|
thumbnail: null;
|
|
214
238
|
};
|
|
215
239
|
/**
|
|
216
|
-
* Creates a source the engine draws
|
|
217
|
-
*
|
|
240
|
+
* Creates a source the engine draws from `generator` (see `generators.js`), with no file or
|
|
241
|
+
* duration.
|
|
218
242
|
*/
|
|
219
243
|
createGenerated(generator: any, { id, name }?: {
|
|
220
244
|
id?: string | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Media library: import, probe, and keep browser-side resources for each source. The engine only
|
|
2
2
|
// learns that a source exists (`browser://<id>`); this module answers its per-frame requests.
|
|
3
|
-
import { colorMetadataFromVideoColorSpace } from "alpha2/hdr-frames";
|
|
4
|
-
import { MediabunnyVideoDecoder } from "alpha2/mediabunny";
|
|
3
|
+
import { codecName, colorMetadataFromVideoColorSpace, DecodeUnavailableError, decodeRefusalMessage, pictureDetails, PlanarDecodeUnavailableError, } from "alpha2/hdr-frames";
|
|
4
|
+
import { MediabunnyVideoDecoder, probeAudioSource, probeAudioStreams, probePlanarDecode, videoTrackFacts, } from "alpha2/mediabunny";
|
|
5
5
|
import { TICKS_PER_SECOND } from "alpha2/project";
|
|
6
6
|
import { OffscreenTextRasterizer } from "alpha2/text";
|
|
7
7
|
import { ALL_FORMATS, AudioSampleSink, BlobSource, Input } from "mediabunny";
|
|
@@ -9,6 +9,7 @@ const uid = (prefix) => `${prefix}-${crypto.randomUUID()}`;
|
|
|
9
9
|
import { drawGenerator, generatorLabel } from "./generators.js";
|
|
10
10
|
import { seekVideoFrame } from "./preview-utils.js";
|
|
11
11
|
import { decodeStill } from "./still.js";
|
|
12
|
+
import { readUserText } from "./text.js";
|
|
12
13
|
import { EditorError } from "../../core/document.js";
|
|
13
14
|
import { TEXT_DEFAULTS } from "../../core/text.js";
|
|
14
15
|
import { displaySize } from "./fingerprint.js";
|
|
@@ -44,9 +45,22 @@ export const ACCEPTED_TYPES = [
|
|
|
44
45
|
export const DEFAULT_TEXT = TEXT_DEFAULTS;
|
|
45
46
|
export class AssetLibrary {
|
|
46
47
|
#assets = new Map();
|
|
48
|
+
#hdrWithoutPlanes;
|
|
47
49
|
#urls = [];
|
|
48
50
|
#rasterizer = new OffscreenTextRasterizer();
|
|
49
51
|
#textVersion = 1n;
|
|
52
|
+
/**
|
|
53
|
+
* `hdrWithoutPlanes` handles HDR video this browser decodes only to frames without planes and has
|
|
54
|
+
* no software decoder for: `"refuse"` (the default) refuses its import with `unsupported_media`;
|
|
55
|
+
* `"preview-degraded"` imports it with `planarDecode: "unavailable"` for a tone-mapped preview
|
|
56
|
+
* that the bridge refuses to export.
|
|
57
|
+
*/
|
|
58
|
+
constructor({ hdrWithoutPlanes = "refuse" } = {}) {
|
|
59
|
+
if (hdrWithoutPlanes !== "refuse" &&
|
|
60
|
+
hdrWithoutPlanes !== "preview-degraded")
|
|
61
|
+
throw new RangeError('hdrWithoutPlanes must be "refuse" or "preview-degraded"');
|
|
62
|
+
this.#hdrWithoutPlanes = hdrWithoutPlanes;
|
|
63
|
+
}
|
|
50
64
|
get map() {
|
|
51
65
|
return this.#assets;
|
|
52
66
|
}
|
|
@@ -117,7 +131,7 @@ export class AssetLibrary {
|
|
|
117
131
|
name: reference?.name ?? file.name,
|
|
118
132
|
locator: reference?.locator ?? localLocator(file, file.name),
|
|
119
133
|
file,
|
|
120
|
-
text: await file
|
|
134
|
+
text: await readUserText(file),
|
|
121
135
|
};
|
|
122
136
|
this.#assets.set(asset.id, asset);
|
|
123
137
|
return asset;
|
|
@@ -133,8 +147,8 @@ export class AssetLibrary {
|
|
|
133
147
|
this.#assets.delete(id);
|
|
134
148
|
}
|
|
135
149
|
/**
|
|
136
|
-
* Imports browser files; each
|
|
137
|
-
*
|
|
150
|
+
* Imports browser files; each failure is reported with its name and reason (see {@link
|
|
151
|
+
* importFile}).
|
|
138
152
|
*/
|
|
139
153
|
async importFiles(files, onProgress) {
|
|
140
154
|
const imported = [];
|
|
@@ -157,10 +171,9 @@ export class AssetLibrary {
|
|
|
157
171
|
}
|
|
158
172
|
/**
|
|
159
173
|
* Imports one browser file as an image, video or audio asset. Rejects with an `EditorError`:
|
|
160
|
-
* `unsupported_media` for a file that is none of those, `unreadable_media`
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* reason once it aborts a decode.
|
|
174
|
+
* `unsupported_media` for a file that is none of those, `unreadable_media` when this browser
|
|
175
|
+
* cannot read it (with the decoder's or demuxer's reason as message and `cause`), or with
|
|
176
|
+
* `signal`'s reason once it aborts a decode.
|
|
164
177
|
*/
|
|
165
178
|
async importFile(file, { signal } = {}) {
|
|
166
179
|
return (await this.#import(file, signal)).asset;
|
|
@@ -170,9 +183,10 @@ export class AssetLibrary {
|
|
|
170
183
|
if (!kind)
|
|
171
184
|
throw new EditorError("unsupported_media", `Cannot import ${file.name}: not an image, video or audio file`, "import");
|
|
172
185
|
let as = kind;
|
|
186
|
+
let probe = null;
|
|
173
187
|
try {
|
|
174
188
|
// Probe the container first: browsers type by extension, so an audio-only .webm is `video/*`.
|
|
175
|
-
|
|
189
|
+
probe = kind === "video" ? await probeVideo(file) : null;
|
|
176
190
|
if (probe && !probe.video && probe.hasAudio)
|
|
177
191
|
as = "audio";
|
|
178
192
|
const reference = this.#matchingReference(file, as);
|
|
@@ -186,14 +200,12 @@ export class AssetLibrary {
|
|
|
186
200
|
catch (error) {
|
|
187
201
|
if (signal?.aborted)
|
|
188
202
|
throw signal.reason;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
: String(error ?? "");
|
|
193
|
-
throw new EditorError("unreadable_media", `Cannot read ${file.name} as ${as}: ${reason || "this browser could not decode it"}`, "import", undefined, true, { cause: error });
|
|
203
|
+
if (error instanceof EditorError)
|
|
204
|
+
throw error;
|
|
205
|
+
throw new EditorError("unreadable_media", `Cannot read ${file.name} as ${as}: ${importFailureReason(error, as, probe?.video?.facts)}`, "import", undefined, true, { cause: error });
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
|
-
/** A still keeps its file, size
|
|
208
|
+
/** A still keeps its file, size and thumbnail; `SourcePixels` decodes it again per frame. */
|
|
197
209
|
async #importImage(file, reference = null) {
|
|
198
210
|
const bitmap = await decodeStill(file);
|
|
199
211
|
let width, height, thumbnail;
|
|
@@ -220,13 +232,41 @@ export class AssetLibrary {
|
|
|
220
232
|
return asset;
|
|
221
233
|
}
|
|
222
234
|
/**
|
|
223
|
-
* `
|
|
224
|
-
*
|
|
225
|
-
*
|
|
235
|
+
* `"available"` when this browser hands `file`'s HDR frames over as planes, `"unavailable"` when
|
|
236
|
+
* it decodes them only without planes and the library previews such tracks degraded. Rejects with
|
|
237
|
+
* `unsupported_media` otherwise.
|
|
238
|
+
*/
|
|
239
|
+
async #planarDecode(file, probe) {
|
|
240
|
+
if (!probe?.video?.colorMetadata)
|
|
241
|
+
return "available";
|
|
242
|
+
try {
|
|
243
|
+
await probePlanarDecode(file, { declared: probe.video.colorMetadata });
|
|
244
|
+
return "available";
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
// Only a track the browser can decode (to frames without planes) can preview degraded.
|
|
248
|
+
if (error instanceof PlanarDecodeUnavailableError &&
|
|
249
|
+
error.facts.softwareDecoder !== undefined &&
|
|
250
|
+
this.#hdrWithoutPlanes === "preview-degraded")
|
|
251
|
+
return "unavailable";
|
|
252
|
+
if (error instanceof PlanarDecodeUnavailableError ||
|
|
253
|
+
error instanceof DecodeUnavailableError)
|
|
254
|
+
throw new EditorError("unsupported_media", decodeRefusalMessage(file.name, error.facts), "import", undefined, true, { cause: error });
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* `probe` is null when the container was unreadable; a file with no picture is refused. A file
|
|
260
|
+
* the media element cannot open still imports, with `video: null`, when the decoder can decode
|
|
261
|
+
* its picture.
|
|
226
262
|
*/
|
|
227
263
|
async #importVideo(file, reference = null, probe = null, signal) {
|
|
228
264
|
if (probe && !probe.video)
|
|
229
265
|
throw new Error("the file has neither a picture nor sound");
|
|
266
|
+
// An HDR source must reach the engine as planes, which some browsers never hand over (opaque
|
|
267
|
+
// hardware frames and no software decoder). Refuse it here by name rather than at its first
|
|
268
|
+
// frame, unless the library takes it for a degraded preview.
|
|
269
|
+
const planarDecode = await this.#planarDecode(file, probe);
|
|
230
270
|
const url = URL.createObjectURL(file);
|
|
231
271
|
this.#urls.push(url);
|
|
232
272
|
const video = document.createElement("video");
|
|
@@ -242,7 +282,7 @@ export class AssetLibrary {
|
|
|
242
282
|
video.onerror = () => resolve(video.error ?? new Error("video decode failed"));
|
|
243
283
|
});
|
|
244
284
|
// The element is a fallback reader, not the gate: Chrome's media pipeline refuses some files
|
|
245
|
-
// WebCodecs decodes (a stream copy cut inside an open GOP)
|
|
285
|
+
// WebCodecs decodes (a stream copy cut inside an open GOP).
|
|
246
286
|
if (failed) {
|
|
247
287
|
if (!probe?.video?.decodable)
|
|
248
288
|
throw failed;
|
|
@@ -273,10 +313,17 @@ export class AssetLibrary {
|
|
|
273
313
|
height: read.height,
|
|
274
314
|
frameRate: read.frameRate,
|
|
275
315
|
duration,
|
|
276
|
-
// Having audio is
|
|
316
|
+
// Having audio is a document fact; whether this browser decodes it is a session fact.
|
|
277
317
|
hasAudio: probe?.hasAudio ?? false,
|
|
278
318
|
audioDecodable: probe?.audioDecodable ?? false,
|
|
319
|
+
...(probe?.audioDecodeFacts
|
|
320
|
+
? { audioDecodeFacts: probe.audioDecodeFacts }
|
|
321
|
+
: {}),
|
|
322
|
+
...(probe?.audioStreams ? { audioStreams: probe.audioStreams } : {}),
|
|
279
323
|
colorMetadata: read.colorMetadata,
|
|
324
|
+
// Whether this browser hands frames over as planes (a session fact). "unavailable" previews
|
|
325
|
+
// degraded and is never exported here.
|
|
326
|
+
planarDecode,
|
|
280
327
|
fit: "contain",
|
|
281
328
|
thumbnail: null,
|
|
282
329
|
peaks: null,
|
|
@@ -288,14 +335,15 @@ export class AssetLibrary {
|
|
|
288
335
|
asset.thumbnail = await decodedThumbnail(asset, signal);
|
|
289
336
|
}
|
|
290
337
|
catch (error) {
|
|
291
|
-
throw new Error(
|
|
338
|
+
throw new Error("the media element could not open it, and decoding it with WebCodecs failed too", { cause: error });
|
|
292
339
|
}
|
|
293
340
|
}
|
|
294
341
|
this.#assets.set(asset.id, asset);
|
|
295
342
|
return asset;
|
|
296
343
|
}
|
|
297
344
|
async #importAudio(file, reference = null) {
|
|
298
|
-
const { duration, decodable } = await probeAudio(file);
|
|
345
|
+
const { duration, decodable, facts } = await probeAudio(file);
|
|
346
|
+
const audioStreams = await probeAudioStreams(file).catch(() => null);
|
|
299
347
|
const asset = {
|
|
300
348
|
id: reference?.id ?? uid("src"),
|
|
301
349
|
kind: "audio",
|
|
@@ -305,6 +353,8 @@ export class AssetLibrary {
|
|
|
305
353
|
duration,
|
|
306
354
|
hasAudio: true,
|
|
307
355
|
audioDecodable: decodable,
|
|
356
|
+
...(facts ? { audioDecodeFacts: facts } : {}),
|
|
357
|
+
...(audioStreams ? { audioStreams } : {}),
|
|
308
358
|
peaks: null,
|
|
309
359
|
thumbnail: null,
|
|
310
360
|
};
|
|
@@ -327,10 +377,7 @@ export class AssetLibrary {
|
|
|
327
377
|
this.#assets.set(asset.id, asset);
|
|
328
378
|
return asset;
|
|
329
379
|
}
|
|
330
|
-
/**
|
|
331
|
-
* Creates a text source rasterized by the packaged `OffscreenTextRasterizer`, the browser host
|
|
332
|
-
* for the engine's host-rasterized text contract.
|
|
333
|
-
*/
|
|
380
|
+
/** Creates a text source rasterized by the packaged `OffscreenTextRasterizer`. */
|
|
334
381
|
createText(style = {}, { id = uid("src") } = {}) {
|
|
335
382
|
const text = { ...DEFAULT_TEXT, ...style };
|
|
336
383
|
const asset = {
|
|
@@ -348,8 +395,8 @@ export class AssetLibrary {
|
|
|
348
395
|
return asset;
|
|
349
396
|
}
|
|
350
397
|
/**
|
|
351
|
-
* Creates a source the engine draws
|
|
352
|
-
*
|
|
398
|
+
* Creates a source the engine draws from `generator` (see `generators.js`), with no file or
|
|
399
|
+
* duration.
|
|
353
400
|
*/
|
|
354
401
|
createGenerated(generator, { id = uid("gen"), name = null } = {}) {
|
|
355
402
|
const asset = {
|
|
@@ -446,9 +493,9 @@ function mediaKindForFile(file) {
|
|
|
446
493
|
return null;
|
|
447
494
|
}
|
|
448
495
|
/**
|
|
449
|
-
* What a video container holds, read by the demuxer: its picture (`video`: size, frame rate,
|
|
450
|
-
* declaration, and whether WebCodecs decodes it
|
|
451
|
-
*
|
|
496
|
+
* What a video container holds, read by the demuxer: its picture (`video`: size, frame rate, HDR
|
|
497
|
+
* declaration, and whether WebCodecs decodes it, or null without a video track) and whether it
|
|
498
|
+
* has audio. Null when the demuxer cannot read the container.
|
|
452
499
|
*/
|
|
453
500
|
export async function probeVideo(file) {
|
|
454
501
|
const input = new Input({
|
|
@@ -464,7 +511,7 @@ export async function probeVideo(file) {
|
|
|
464
511
|
const space = await track.getColorSpace().catch(() => null);
|
|
465
512
|
const shown = await displaySize(track);
|
|
466
513
|
video = {
|
|
467
|
-
// Only an HDR declaration is recorded, so the project knows the source needs
|
|
514
|
+
// Only an HDR declaration is recorded, so the project knows the source needs tone mapping.
|
|
468
515
|
colorMetadata: space?.transfer === "pq" || space?.transfer === "hlg"
|
|
469
516
|
? colorMetadataFromVideoColorSpace(space)
|
|
470
517
|
: null,
|
|
@@ -472,12 +519,19 @@ export async function probeVideo(file) {
|
|
|
472
519
|
height: shown.height,
|
|
473
520
|
frameRate: stats?.averagePacketRate ?? 30,
|
|
474
521
|
decodable: await track.canDecode().catch(() => false),
|
|
522
|
+
facts: await videoTrackFacts(track),
|
|
475
523
|
};
|
|
476
524
|
}
|
|
525
|
+
const audioDecode = audio ? await audioDecoding(file) : null;
|
|
526
|
+
const audioStreams = audio
|
|
527
|
+
? await probeAudioStreams(file).catch(() => null)
|
|
528
|
+
: [];
|
|
477
529
|
return {
|
|
478
530
|
video,
|
|
479
531
|
hasAudio: audio !== null,
|
|
480
|
-
audioDecodable:
|
|
532
|
+
audioDecodable: audioDecode?.decodable ?? false,
|
|
533
|
+
...(audioDecode?.facts ? { audioDecodeFacts: audioDecode.facts } : {}),
|
|
534
|
+
...(audioStreams ? { audioStreams } : {}),
|
|
481
535
|
};
|
|
482
536
|
}
|
|
483
537
|
catch (error) {
|
|
@@ -488,6 +542,29 @@ export async function probeVideo(file) {
|
|
|
488
542
|
input.dispose();
|
|
489
543
|
}
|
|
490
544
|
}
|
|
545
|
+
/** `MediaError` codes: the source is in a format the element does not read, or did not decode. */
|
|
546
|
+
const MEDIA_ERR_DECODE = 3;
|
|
547
|
+
const MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
|
|
548
|
+
/**
|
|
549
|
+
* Why an import failed, in this editor's words. Browser error text (`MediaError`, decoder
|
|
550
|
+
* `DOMException`) exposes engine internals, so it is never shown and stays the error's cause.
|
|
551
|
+
* `facts` describe the video track when the probe read one.
|
|
552
|
+
*/
|
|
553
|
+
export function importFailureReason(error, kind, facts) {
|
|
554
|
+
const browserError = typeof DOMException !== "undefined" && error instanceof DOMException;
|
|
555
|
+
const mediaError = !(error instanceof Error) && typeof error?.code === "number";
|
|
556
|
+
if (!mediaError && !browserError && error instanceof Error)
|
|
557
|
+
return error.message;
|
|
558
|
+
const undecodable = browserError ||
|
|
559
|
+
error?.code === MEDIA_ERR_DECODE ||
|
|
560
|
+
error?.code === MEDIA_ERR_SRC_NOT_SUPPORTED;
|
|
561
|
+
if (!undecodable)
|
|
562
|
+
return `this browser could not read the ${kind}`;
|
|
563
|
+
if (kind !== "video" || !facts)
|
|
564
|
+
return `this browser cannot decode this ${kind}`;
|
|
565
|
+
const details = pictureDetails(facts);
|
|
566
|
+
return `this browser cannot decode ${codecName(facts.codec)} video${details.length > 0 ? ` (${details.join(", ")})` : ""}`;
|
|
567
|
+
}
|
|
491
568
|
/** A container's length in seconds, as its last packet ends; null when it cannot be read. */
|
|
492
569
|
async function containerDuration(file) {
|
|
493
570
|
const input = new Input({
|
|
@@ -506,9 +583,23 @@ async function containerDuration(file) {
|
|
|
506
583
|
}
|
|
507
584
|
}
|
|
508
585
|
/**
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
|
|
586
|
+
* Whether this browser decodes a file's primary audio, using the preview decoder's trial decode
|
|
587
|
+
* (`probeAudioSource`), and the refusal facts when not.
|
|
588
|
+
*/
|
|
589
|
+
async function audioDecoding(file) {
|
|
590
|
+
try {
|
|
591
|
+
await probeAudioSource(file.name, file);
|
|
592
|
+
return { decodable: true, facts: null };
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
if (error instanceof DecodeUnavailableError)
|
|
596
|
+
return { decodable: false, facts: error.facts };
|
|
597
|
+
throw error;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* An audio file's duration and whether this browser can decode it (with facts when not). Files it
|
|
602
|
+
* cannot decode still import; the document records the audio for native hosts and other browsers.
|
|
512
603
|
*/
|
|
513
604
|
async function probeAudio(file) {
|
|
514
605
|
const input = new Input({
|
|
@@ -519,10 +610,10 @@ async function probeAudio(file) {
|
|
|
519
610
|
const track = await input.getPrimaryAudioTrack();
|
|
520
611
|
if (!track)
|
|
521
612
|
throw new Error("media has no audio track");
|
|
522
|
-
const decodable = await
|
|
613
|
+
const { decodable, facts } = await audioDecoding(file);
|
|
523
614
|
const duration = (await track.getDurationFromMetadata().catch(() => null)) ??
|
|
524
615
|
(decodable ? await track.computeDuration() : 0);
|
|
525
|
-
return { duration, decodable };
|
|
616
|
+
return { duration, decodable, facts };
|
|
526
617
|
}
|
|
527
618
|
finally {
|
|
528
619
|
input.dispose();
|
|
@@ -598,8 +689,8 @@ export function computePeaks(buffer, buckets = 1_200) {
|
|
|
598
689
|
}
|
|
599
690
|
/**
|
|
600
691
|
* A thumbnail of `image` shown at `width` x `height`. With `orientation`, `image` is a decoded
|
|
601
|
-
* frame that
|
|
602
|
-
*
|
|
692
|
+
* frame that is mirrored left to right when `mirror` is set, then rotated `rotation` degrees
|
|
693
|
+
* clockwise to show upright.
|
|
603
694
|
*/
|
|
604
695
|
function thumbnailFrom(image, width, height, orientation = null) {
|
|
605
696
|
// Rendered once at import; the timeline re-reads `dataUrl` on every redraw.
|
|
@@ -644,14 +735,14 @@ async function videoThumbnail(video, width, height) {
|
|
|
644
735
|
}
|
|
645
736
|
}
|
|
646
737
|
/**
|
|
647
|
-
* A thumbnail of `asset
|
|
648
|
-
*
|
|
649
|
-
*
|
|
738
|
+
* A thumbnail of `asset` (a file the media element cannot open) from the preview decoder, whose
|
|
739
|
+
* stall limit bounds a decoder that never answers. Rejects when it decodes no picture, or with
|
|
740
|
+
* `signal`'s reason once it aborts.
|
|
650
741
|
*/
|
|
651
742
|
async function decodedThumbnail(asset, signal) {
|
|
652
743
|
const decoder = await MediabunnyVideoDecoder.open(asset.id, asset.file);
|
|
653
744
|
try {
|
|
654
|
-
// Requests before the
|
|
745
|
+
// Requests before the first frame present that frame, as preview shows it.
|
|
655
746
|
const seconds = Math.min(0.25 * (asset.duration || 1), 1);
|
|
656
747
|
const { frame, rotationDegrees, mirror } = await decoder.refill({
|
|
657
748
|
sourceId: asset.id,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Sources that contribute to the mix,
|
|
3
|
-
*
|
|
4
|
-
* A video file with a sound track counts: it declares `has_audio`, so its clip on a video track is
|
|
5
|
-
* mixed without a second clip on an audio lane.
|
|
2
|
+
* Sources that contribute to the mix, with their browser-side asset. A video file with a sound
|
|
3
|
+
* track declares `has_audio`, so its clip on a video track is mixed without a separate audio clip.
|
|
6
4
|
*/
|
|
7
5
|
export function audibleSources(project: any, library: any): {
|
|
8
6
|
id: any;
|
|
@@ -13,8 +11,8 @@ export function mixBlock(engine: any, startSample: any, frames: any, playing?: b
|
|
|
13
11
|
/** Sources the most recent mix could not read, as reported by the engine. */
|
|
14
12
|
export function missingAudioSources(engine: any): any;
|
|
15
13
|
/**
|
|
16
|
-
* The sample
|
|
17
|
-
*
|
|
14
|
+
* The first sample at or after `tick`. The audio clock reports the tick at or before the sample
|
|
15
|
+
* heard, so rounding to nearest could be heard a frame early.
|
|
18
16
|
*/
|
|
19
17
|
export function playbackStartSample(tick: any, sampleRate: any): number;
|
|
20
18
|
/**
|
|
@@ -35,19 +33,26 @@ export class AudioWindowSupplier {
|
|
|
35
33
|
* thread; the worklet applies no second master chain.
|
|
36
34
|
*/
|
|
37
35
|
export class EngineAudioMixer {
|
|
38
|
-
|
|
36
|
+
/**
|
|
37
|
+
* `onInterrupted` is called after the mixer stops because output stopped under playing audio
|
|
38
|
+
* (context suspended or interrupted by the system, as when another app takes the device).
|
|
39
|
+
*/
|
|
40
|
+
constructor(runtimeAssets?: {}, { enabled, onInterrupted }?: {
|
|
39
41
|
enabled?: boolean | undefined;
|
|
40
42
|
});
|
|
41
43
|
runtimeAssets: {};
|
|
42
44
|
get tick(): number | null;
|
|
45
|
+
/** Where the playing clock's output latency comes from (`AudioLatencySource`), else null. */
|
|
46
|
+
get latencySource(): any;
|
|
47
|
+
/** Sets the A/V offset in milliseconds (positive shows the picture later), playing or not. */
|
|
48
|
+
setLatencyOffset(ms: any): void;
|
|
43
49
|
volume: number;
|
|
44
50
|
get supported(): boolean;
|
|
45
51
|
get context(): null;
|
|
46
52
|
/**
|
|
47
|
-
* Associates a loaded project with the preview mixer. Safe to call again.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* AudioWorkletProcessor until a user gesture.
|
|
53
|
+
* Associates a loaded project with the preview mixer. Safe to call again. Worklet creation waits
|
|
54
|
+
* for `resume()`, since a suspended AudioContext may not construct an AudioWorkletProcessor
|
|
55
|
+
* before a user gesture.
|
|
51
56
|
*/
|
|
52
57
|
attach(engine: any, project: any, supplier: any, onUnderrun: any, onError: any): Promise<boolean>;
|
|
53
58
|
setMasterVolume(value: any): void;
|