@alpha2-sh/editor 0.4.6 → 0.5.0
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 +396 -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 +47 -28
- package/dist/browser/runtime/assets.js +129 -45
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +58 -31
- 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 +39 -44
- package/dist/browser/runtime/engine.js +78 -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 +10 -17
- package/dist/browser/runtime/proxies.js +33 -45
- 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 +233 -238
- package/dist/browser/worker.d.ts +8 -9
- package/dist/browser/worker.js +50 -21
- 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 +64 -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,27 @@
|
|
|
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
|
+
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
7
8
|
video: {
|
|
8
9
|
colorMetadata: import("alpha2/project").ColorMetadata | null;
|
|
9
10
|
width: number;
|
|
10
11
|
height: number;
|
|
11
12
|
frameRate: number;
|
|
12
13
|
decodable: boolean;
|
|
14
|
+
facts: import("alpha2/hdr-frames").TrackDecodeFacts;
|
|
13
15
|
} | null;
|
|
14
16
|
hasAudio: boolean;
|
|
15
17
|
audioDecodable: boolean;
|
|
16
18
|
} | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Why an import failed, in this editor's words. Browser error text (`MediaError`, decoder
|
|
21
|
+
* `DOMException`) exposes engine internals, so it is never shown and stays the error's cause.
|
|
22
|
+
* `facts` describe the video track when the probe read one.
|
|
23
|
+
*/
|
|
24
|
+
export function importFailureReason(error: any, kind: any, facts: any): string;
|
|
17
25
|
/**
|
|
18
26
|
* Streams a file's primary audio track into per-bucket peak magnitudes (`bucketsPerSecond`, capped
|
|
19
27
|
* at `maxBuckets`) with bounded memory. A bucket's peak is its loudest sample in any channel,
|
|
@@ -40,6 +48,15 @@ export const DEFAULT_TEXT: Readonly<{
|
|
|
40
48
|
readonly lineHeight: 1.15;
|
|
41
49
|
}>;
|
|
42
50
|
export class AssetLibrary {
|
|
51
|
+
/**
|
|
52
|
+
* `hdrWithoutPlanes` handles HDR video this browser decodes only to frames without planes and has
|
|
53
|
+
* no software decoder for: `"refuse"` (the default) refuses its import with `unsupported_media`;
|
|
54
|
+
* `"preview-degraded"` imports it with `planarDecode: "unavailable"` for a tone-mapped preview
|
|
55
|
+
* that the bridge refuses to export.
|
|
56
|
+
*/
|
|
57
|
+
constructor({ hdrWithoutPlanes }?: {
|
|
58
|
+
hdrWithoutPlanes?: string | undefined;
|
|
59
|
+
});
|
|
43
60
|
get map(): Map<any, any>;
|
|
44
61
|
get all(): any[];
|
|
45
62
|
get(id: any): any;
|
|
@@ -72,13 +89,13 @@ export class AssetLibrary {
|
|
|
72
89
|
name: any;
|
|
73
90
|
locator: any;
|
|
74
91
|
file: any;
|
|
75
|
-
text:
|
|
92
|
+
text: string;
|
|
76
93
|
}>;
|
|
77
94
|
usedBy(doc: any): Set<any>;
|
|
78
95
|
remove(id: any): void;
|
|
79
96
|
/**
|
|
80
|
-
* Imports browser files; each
|
|
81
|
-
*
|
|
97
|
+
* Imports browser files; each failure is reported with its name and reason (see {@link
|
|
98
|
+
* importFile}).
|
|
82
99
|
*/
|
|
83
100
|
importFiles(files: any, onProgress: any): Promise<{
|
|
84
101
|
imported: ({
|
|
@@ -93,6 +110,12 @@ export class AssetLibrary {
|
|
|
93
110
|
fit: string;
|
|
94
111
|
thumbnail: HTMLCanvasElement;
|
|
95
112
|
} | {
|
|
113
|
+
colorMetadata: any;
|
|
114
|
+
planarDecode: string;
|
|
115
|
+
fit: string;
|
|
116
|
+
thumbnail: null;
|
|
117
|
+
peaks: null;
|
|
118
|
+
audioDecodeFacts?: any;
|
|
96
119
|
id: any;
|
|
97
120
|
kind: string;
|
|
98
121
|
name: any;
|
|
@@ -106,11 +129,10 @@ export class AssetLibrary {
|
|
|
106
129
|
duration: number;
|
|
107
130
|
hasAudio: any;
|
|
108
131
|
audioDecodable: any;
|
|
109
|
-
colorMetadata: any;
|
|
110
|
-
fit: string;
|
|
111
|
-
thumbnail: null;
|
|
112
|
-
peaks: null;
|
|
113
132
|
} | {
|
|
133
|
+
peaks: null;
|
|
134
|
+
thumbnail: null;
|
|
135
|
+
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
114
136
|
id: any;
|
|
115
137
|
kind: string;
|
|
116
138
|
name: any;
|
|
@@ -119,8 +141,6 @@ export class AssetLibrary {
|
|
|
119
141
|
duration: number;
|
|
120
142
|
hasAudio: boolean;
|
|
121
143
|
audioDecodable: boolean;
|
|
122
|
-
peaks: null;
|
|
123
|
-
thumbnail: null;
|
|
124
144
|
})[];
|
|
125
145
|
rejected: {
|
|
126
146
|
name: any;
|
|
@@ -130,10 +150,9 @@ export class AssetLibrary {
|
|
|
130
150
|
}>;
|
|
131
151
|
/**
|
|
132
152
|
* 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.
|
|
153
|
+
* `unsupported_media` for a file that is none of those, `unreadable_media` when this browser
|
|
154
|
+
* cannot read it (with the decoder's or demuxer's reason as message and `cause`), or with
|
|
155
|
+
* `signal`'s reason once it aborts a decode.
|
|
137
156
|
*/
|
|
138
157
|
importFile(file: any, { signal }?: {}): Promise<{
|
|
139
158
|
id: any;
|
|
@@ -147,6 +166,12 @@ export class AssetLibrary {
|
|
|
147
166
|
fit: string;
|
|
148
167
|
thumbnail: HTMLCanvasElement;
|
|
149
168
|
} | {
|
|
169
|
+
colorMetadata: any;
|
|
170
|
+
planarDecode: string;
|
|
171
|
+
fit: string;
|
|
172
|
+
thumbnail: null;
|
|
173
|
+
peaks: null;
|
|
174
|
+
audioDecodeFacts?: any;
|
|
150
175
|
id: any;
|
|
151
176
|
kind: string;
|
|
152
177
|
name: any;
|
|
@@ -160,11 +185,10 @@ export class AssetLibrary {
|
|
|
160
185
|
duration: number;
|
|
161
186
|
hasAudio: any;
|
|
162
187
|
audioDecodable: any;
|
|
163
|
-
colorMetadata: any;
|
|
164
|
-
fit: string;
|
|
165
|
-
thumbnail: null;
|
|
166
|
-
peaks: null;
|
|
167
188
|
} | {
|
|
189
|
+
peaks: null;
|
|
190
|
+
thumbnail: null;
|
|
191
|
+
audioDecodeFacts?: import("alpha2/hdr-frames").TrackDecodeFacts | undefined;
|
|
168
192
|
id: any;
|
|
169
193
|
kind: string;
|
|
170
194
|
name: any;
|
|
@@ -173,8 +197,6 @@ export class AssetLibrary {
|
|
|
173
197
|
duration: number;
|
|
174
198
|
hasAudio: boolean;
|
|
175
199
|
audioDecodable: boolean;
|
|
176
|
-
peaks: null;
|
|
177
|
-
thumbnail: null;
|
|
178
200
|
}>;
|
|
179
201
|
/** Registers a project-rate audio buffer synthesized in the page rather than read from a file. */
|
|
180
202
|
addGeneratedAudio(name: any, audioBuffer: any): {
|
|
@@ -188,10 +210,7 @@ export class AssetLibrary {
|
|
|
188
210
|
peaks: Float32Array<ArrayBuffer>;
|
|
189
211
|
thumbnail: null;
|
|
190
212
|
};
|
|
191
|
-
/**
|
|
192
|
-
* Creates a text source rasterized by the packaged `OffscreenTextRasterizer`, the browser host
|
|
193
|
-
* for the engine's host-rasterized text contract.
|
|
194
|
-
*/
|
|
213
|
+
/** Creates a text source rasterized by the packaged `OffscreenTextRasterizer`. */
|
|
195
214
|
createText(style?: {}, { id }?: {
|
|
196
215
|
id?: string | undefined;
|
|
197
216
|
}): {
|
|
@@ -213,8 +232,8 @@ export class AssetLibrary {
|
|
|
213
232
|
thumbnail: null;
|
|
214
233
|
};
|
|
215
234
|
/**
|
|
216
|
-
* Creates a source the engine draws
|
|
217
|
-
*
|
|
235
|
+
* Creates a source the engine draws from `generator` (see `generators.js`), with no file or
|
|
236
|
+
* duration.
|
|
218
237
|
*/
|
|
219
238
|
createGenerated(generator: any, { id, name }?: {
|
|
220
239
|
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, 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,16 @@ 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
|
+
: {}),
|
|
279
322
|
colorMetadata: read.colorMetadata,
|
|
323
|
+
// Whether this browser hands frames over as planes (a session fact). "unavailable" previews
|
|
324
|
+
// degraded and is never exported here.
|
|
325
|
+
planarDecode,
|
|
280
326
|
fit: "contain",
|
|
281
327
|
thumbnail: null,
|
|
282
328
|
peaks: null,
|
|
@@ -288,14 +334,14 @@ export class AssetLibrary {
|
|
|
288
334
|
asset.thumbnail = await decodedThumbnail(asset, signal);
|
|
289
335
|
}
|
|
290
336
|
catch (error) {
|
|
291
|
-
throw new Error(
|
|
337
|
+
throw new Error("the media element could not open it, and decoding it with WebCodecs failed too", { cause: error });
|
|
292
338
|
}
|
|
293
339
|
}
|
|
294
340
|
this.#assets.set(asset.id, asset);
|
|
295
341
|
return asset;
|
|
296
342
|
}
|
|
297
343
|
async #importAudio(file, reference = null) {
|
|
298
|
-
const { duration, decodable } = await probeAudio(file);
|
|
344
|
+
const { duration, decodable, facts } = await probeAudio(file);
|
|
299
345
|
const asset = {
|
|
300
346
|
id: reference?.id ?? uid("src"),
|
|
301
347
|
kind: "audio",
|
|
@@ -305,6 +351,7 @@ export class AssetLibrary {
|
|
|
305
351
|
duration,
|
|
306
352
|
hasAudio: true,
|
|
307
353
|
audioDecodable: decodable,
|
|
354
|
+
...(facts ? { audioDecodeFacts: facts } : {}),
|
|
308
355
|
peaks: null,
|
|
309
356
|
thumbnail: null,
|
|
310
357
|
};
|
|
@@ -327,10 +374,7 @@ export class AssetLibrary {
|
|
|
327
374
|
this.#assets.set(asset.id, asset);
|
|
328
375
|
return asset;
|
|
329
376
|
}
|
|
330
|
-
/**
|
|
331
|
-
* Creates a text source rasterized by the packaged `OffscreenTextRasterizer`, the browser host
|
|
332
|
-
* for the engine's host-rasterized text contract.
|
|
333
|
-
*/
|
|
377
|
+
/** Creates a text source rasterized by the packaged `OffscreenTextRasterizer`. */
|
|
334
378
|
createText(style = {}, { id = uid("src") } = {}) {
|
|
335
379
|
const text = { ...DEFAULT_TEXT, ...style };
|
|
336
380
|
const asset = {
|
|
@@ -348,8 +392,8 @@ export class AssetLibrary {
|
|
|
348
392
|
return asset;
|
|
349
393
|
}
|
|
350
394
|
/**
|
|
351
|
-
* Creates a source the engine draws
|
|
352
|
-
*
|
|
395
|
+
* Creates a source the engine draws from `generator` (see `generators.js`), with no file or
|
|
396
|
+
* duration.
|
|
353
397
|
*/
|
|
354
398
|
createGenerated(generator, { id = uid("gen"), name = null } = {}) {
|
|
355
399
|
const asset = {
|
|
@@ -446,9 +490,9 @@ function mediaKindForFile(file) {
|
|
|
446
490
|
return null;
|
|
447
491
|
}
|
|
448
492
|
/**
|
|
449
|
-
* What a video container holds, read by the demuxer: its picture (`video`: size, frame rate,
|
|
450
|
-
* declaration, and whether WebCodecs decodes it
|
|
451
|
-
*
|
|
493
|
+
* What a video container holds, read by the demuxer: its picture (`video`: size, frame rate, HDR
|
|
494
|
+
* declaration, and whether WebCodecs decodes it, or null without a video track) and whether it
|
|
495
|
+
* has audio. Null when the demuxer cannot read the container.
|
|
452
496
|
*/
|
|
453
497
|
export async function probeVideo(file) {
|
|
454
498
|
const input = new Input({
|
|
@@ -464,7 +508,7 @@ export async function probeVideo(file) {
|
|
|
464
508
|
const space = await track.getColorSpace().catch(() => null);
|
|
465
509
|
const shown = await displaySize(track);
|
|
466
510
|
video = {
|
|
467
|
-
// Only an HDR declaration is recorded, so the project knows the source needs
|
|
511
|
+
// Only an HDR declaration is recorded, so the project knows the source needs tone mapping.
|
|
468
512
|
colorMetadata: space?.transfer === "pq" || space?.transfer === "hlg"
|
|
469
513
|
? colorMetadataFromVideoColorSpace(space)
|
|
470
514
|
: null,
|
|
@@ -472,12 +516,15 @@ export async function probeVideo(file) {
|
|
|
472
516
|
height: shown.height,
|
|
473
517
|
frameRate: stats?.averagePacketRate ?? 30,
|
|
474
518
|
decodable: await track.canDecode().catch(() => false),
|
|
519
|
+
facts: await videoTrackFacts(track),
|
|
475
520
|
};
|
|
476
521
|
}
|
|
522
|
+
const audioDecode = audio ? await audioDecoding(file) : null;
|
|
477
523
|
return {
|
|
478
524
|
video,
|
|
479
525
|
hasAudio: audio !== null,
|
|
480
|
-
audioDecodable:
|
|
526
|
+
audioDecodable: audioDecode?.decodable ?? false,
|
|
527
|
+
...(audioDecode?.facts ? { audioDecodeFacts: audioDecode.facts } : {}),
|
|
481
528
|
};
|
|
482
529
|
}
|
|
483
530
|
catch (error) {
|
|
@@ -488,6 +535,29 @@ export async function probeVideo(file) {
|
|
|
488
535
|
input.dispose();
|
|
489
536
|
}
|
|
490
537
|
}
|
|
538
|
+
/** `MediaError` codes: the source is in a format the element does not read, or did not decode. */
|
|
539
|
+
const MEDIA_ERR_DECODE = 3;
|
|
540
|
+
const MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
|
|
541
|
+
/**
|
|
542
|
+
* Why an import failed, in this editor's words. Browser error text (`MediaError`, decoder
|
|
543
|
+
* `DOMException`) exposes engine internals, so it is never shown and stays the error's cause.
|
|
544
|
+
* `facts` describe the video track when the probe read one.
|
|
545
|
+
*/
|
|
546
|
+
export function importFailureReason(error, kind, facts) {
|
|
547
|
+
const browserError = typeof DOMException !== "undefined" && error instanceof DOMException;
|
|
548
|
+
const mediaError = !(error instanceof Error) && typeof error?.code === "number";
|
|
549
|
+
if (!mediaError && !browserError && error instanceof Error)
|
|
550
|
+
return error.message;
|
|
551
|
+
const undecodable = browserError ||
|
|
552
|
+
error?.code === MEDIA_ERR_DECODE ||
|
|
553
|
+
error?.code === MEDIA_ERR_SRC_NOT_SUPPORTED;
|
|
554
|
+
if (!undecodable)
|
|
555
|
+
return `this browser could not read the ${kind}`;
|
|
556
|
+
if (kind !== "video" || !facts)
|
|
557
|
+
return `this browser cannot decode this ${kind}`;
|
|
558
|
+
const details = pictureDetails(facts);
|
|
559
|
+
return `this browser cannot decode ${codecName(facts.codec)} video${details.length > 0 ? ` (${details.join(", ")})` : ""}`;
|
|
560
|
+
}
|
|
491
561
|
/** A container's length in seconds, as its last packet ends; null when it cannot be read. */
|
|
492
562
|
async function containerDuration(file) {
|
|
493
563
|
const input = new Input({
|
|
@@ -506,9 +576,23 @@ async function containerDuration(file) {
|
|
|
506
576
|
}
|
|
507
577
|
}
|
|
508
578
|
/**
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
|
|
579
|
+
* Whether this browser decodes a file's primary audio, using the preview decoder's trial decode
|
|
580
|
+
* (`probeAudioSource`), and the refusal facts when not.
|
|
581
|
+
*/
|
|
582
|
+
async function audioDecoding(file) {
|
|
583
|
+
try {
|
|
584
|
+
await probeAudioSource(file.name, file);
|
|
585
|
+
return { decodable: true, facts: null };
|
|
586
|
+
}
|
|
587
|
+
catch (error) {
|
|
588
|
+
if (error instanceof DecodeUnavailableError)
|
|
589
|
+
return { decodable: false, facts: error.facts };
|
|
590
|
+
throw error;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* An audio file's duration and whether this browser can decode it (with facts when not). Files it
|
|
595
|
+
* cannot decode still import; the document records the audio for native hosts and other browsers.
|
|
512
596
|
*/
|
|
513
597
|
async function probeAudio(file) {
|
|
514
598
|
const input = new Input({
|
|
@@ -519,10 +603,10 @@ async function probeAudio(file) {
|
|
|
519
603
|
const track = await input.getPrimaryAudioTrack();
|
|
520
604
|
if (!track)
|
|
521
605
|
throw new Error("media has no audio track");
|
|
522
|
-
const decodable = await
|
|
606
|
+
const { decodable, facts } = await audioDecoding(file);
|
|
523
607
|
const duration = (await track.getDurationFromMetadata().catch(() => null)) ??
|
|
524
608
|
(decodable ? await track.computeDuration() : 0);
|
|
525
|
-
return { duration, decodable };
|
|
609
|
+
return { duration, decodable, facts };
|
|
526
610
|
}
|
|
527
611
|
finally {
|
|
528
612
|
input.dispose();
|
|
@@ -598,8 +682,8 @@ export function computePeaks(buffer, buckets = 1_200) {
|
|
|
598
682
|
}
|
|
599
683
|
/**
|
|
600
684
|
* A thumbnail of `image` shown at `width` x `height`. With `orientation`, `image` is a decoded
|
|
601
|
-
* frame that
|
|
602
|
-
*
|
|
685
|
+
* frame that is mirrored left to right when `mirror` is set, then rotated `rotation` degrees
|
|
686
|
+
* clockwise to show upright.
|
|
603
687
|
*/
|
|
604
688
|
function thumbnailFrom(image, width, height, orientation = null) {
|
|
605
689
|
// Rendered once at import; the timeline re-reads `dataUrl` on every redraw.
|
|
@@ -644,14 +728,14 @@ async function videoThumbnail(video, width, height) {
|
|
|
644
728
|
}
|
|
645
729
|
}
|
|
646
730
|
/**
|
|
647
|
-
* A thumbnail of `asset
|
|
648
|
-
*
|
|
649
|
-
*
|
|
731
|
+
* A thumbnail of `asset` (a file the media element cannot open) from the preview decoder, whose
|
|
732
|
+
* stall limit bounds a decoder that never answers. Rejects when it decodes no picture, or with
|
|
733
|
+
* `signal`'s reason once it aborts.
|
|
650
734
|
*/
|
|
651
735
|
async function decodedThumbnail(asset, signal) {
|
|
652
736
|
const decoder = await MediabunnyVideoDecoder.open(asset.id, asset.file);
|
|
653
737
|
try {
|
|
654
|
-
// Requests before the
|
|
738
|
+
// Requests before the first frame present that frame, as preview shows it.
|
|
655
739
|
const seconds = Math.min(0.25 * (asset.duration || 1), 1);
|
|
656
740
|
const { frame, rotationDegrees, mirror } = await decoder.refill({
|
|
657
741
|
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;
|