alpha2 0.2.2 → 0.3.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/README.md +6 -4
- package/dist/containers.d.ts +89 -0
- package/dist/containers.js +150 -0
- package/dist/effects.d.ts +12 -2
- package/dist/frame-supply.d.ts +5 -0
- package/dist/generated/project-schema.d.ts +564 -100
- package/dist/generated/project-schema.js +36 -0
- package/dist/generated/project-shape.js +345 -55
- package/dist/geometry.d.ts +98 -0
- package/dist/geometry.js +71 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mediabunny.d.ts +33 -26
- package/dist/mediabunny.js +45 -14
- package/dist/player.d.ts +5 -0
- package/dist/project.d.ts +26 -2
- package/dist/project.js +358 -55
- package/dist/worker.js +1 -0
- package/package.json +9 -1
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +116 -8
- package/wasm/alpha2_wasm.js +369 -34
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +16 -4
- /package/wasm/snippets/{alpha2-wasm-e7f44ec6b15db6c6 → alpha2-wasm-7f557ec9a60cc69b}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-e7f44ec6b15db6c6 → alpha2-wasm-7f557ec9a60cc69b}/inline1.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-e7f44ec6b15db6c6 → alpha2-wasm-7f557ec9a60cc69b}/inline2.js +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape geometry for editors, answered in wasm by the code the engine draws shapes with: where a
|
|
3
|
+
* shapes generator's items are, which paint is under a point, how long a path is, and paths cut,
|
|
4
|
+
* resampled, or converted. A hit test or a trim here agrees with what a frame shows.
|
|
5
|
+
*
|
|
6
|
+
* Positions are normalized as the project document's are, `(0, 0)` top-left to `(1, 1)`
|
|
7
|
+
* bottom-right of a `width` by `height` picture; lengths and distances are in its pixels. Times
|
|
8
|
+
* are ticks, as keyframe times are.
|
|
9
|
+
*
|
|
10
|
+
* Every function throws an `INVALID_INPUT` error for a picture outside 1 to 16384 pixels a side, a
|
|
11
|
+
* time that is not a whole number of ticks, or input the model rejects (a content tree or geometry
|
|
12
|
+
* that is not valid, a path point or tangent that is not finite).
|
|
13
|
+
*/
|
|
14
|
+
import type { AnimatedPoint, Path, ShapeGeometry, ShapeItem, Ticks, Vec2 } from "./project.js";
|
|
15
|
+
/** The part of `alpha2/wasm` these functions use. */
|
|
16
|
+
export interface GeometryBinding {
|
|
17
|
+
shapeBounds(itemsJson: string, time: number, width: number, height: number): string;
|
|
18
|
+
hitTest(itemsJson: string, time: number, width: number, height: number, x: number, y: number): string | undefined;
|
|
19
|
+
nearestPoint(pathJson: string, width: number, height: number, x: number, y: number): string;
|
|
20
|
+
pathLength(pathJson: string, width: number, height: number): string;
|
|
21
|
+
trimPath(pathJson: string, width: number, height: number, start: number, end: number, offset: number): string;
|
|
22
|
+
resamplePath(pathJson: string, width: number, height: number, vertexCounts: Uint32Array): string;
|
|
23
|
+
toPath(geometryJson: string, time: number, width: number, height: number): string;
|
|
24
|
+
motionPath(pointJson: string, width: number, height: number): string;
|
|
25
|
+
}
|
|
26
|
+
/** The size of the picture shapes are drawn on, in pixels. */
|
|
27
|
+
export interface PictureSize {
|
|
28
|
+
readonly width: number;
|
|
29
|
+
readonly height: number;
|
|
30
|
+
}
|
|
31
|
+
/** A normalized rectangle: `x0`, `y0` its top-left corner, `x1`, `y1` its bottom-right. */
|
|
32
|
+
export interface Bounds {
|
|
33
|
+
readonly x0: number;
|
|
34
|
+
readonly y0: number;
|
|
35
|
+
readonly x1: number;
|
|
36
|
+
readonly y1: number;
|
|
37
|
+
}
|
|
38
|
+
/** An item's bounds, by its place in the tree (`items[0].items[2]`). */
|
|
39
|
+
export interface ItemBounds {
|
|
40
|
+
readonly at: string;
|
|
41
|
+
/** What it covers: geometry's outline, a paint's area; `null` for an item that shows nothing. */
|
|
42
|
+
readonly bounds: Bounds | null;
|
|
43
|
+
}
|
|
44
|
+
/** The point of a path nearest another. */
|
|
45
|
+
export interface NearestPoint {
|
|
46
|
+
/** The subpath. */
|
|
47
|
+
readonly subpath: number;
|
|
48
|
+
/** The segment within it: segment `i` runs from vertex `i` to the next. */
|
|
49
|
+
readonly segment: number;
|
|
50
|
+
/** The parameter along the segment, in `0..=1`. */
|
|
51
|
+
readonly t: number;
|
|
52
|
+
/** The point, normalized. */
|
|
53
|
+
readonly point: Vec2;
|
|
54
|
+
/** Its distance from the point asked about, in pixels. */
|
|
55
|
+
readonly distance: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Each item's bounds at `time`, in document order: a group's are its items', a stroke's include
|
|
59
|
+
* its width.
|
|
60
|
+
*
|
|
61
|
+
* @throws When `items` is not a valid content tree.
|
|
62
|
+
*/
|
|
63
|
+
export declare function shapeBounds(binding: GeometryBinding, items: readonly ShapeItem[], time: Ticks, size: PictureSize): ItemBounds[];
|
|
64
|
+
/**
|
|
65
|
+
* The front-most fill or stroke at normalized `point` at `time`, by its fill rule (a stroke by
|
|
66
|
+
* its outline): its place in the tree, or `undefined` where nothing is painted.
|
|
67
|
+
*
|
|
68
|
+
* @throws When `items` is not a valid content tree.
|
|
69
|
+
*/
|
|
70
|
+
export declare function hitTest(binding: GeometryBinding, items: readonly ShapeItem[], time: Ticks, size: PictureSize, point: Vec2): string | undefined;
|
|
71
|
+
/** The point of `path` nearest normalized `point`, or `undefined` for an empty path. */
|
|
72
|
+
export declare function nearestPoint(binding: GeometryBinding, path: Path, size: PictureSize, point: Vec2): NearestPoint | undefined;
|
|
73
|
+
/** Each subpath's length, in pixels. */
|
|
74
|
+
export declare function pathLength(binding: GeometryBinding, path: Path, size: PictureSize): number[];
|
|
75
|
+
/**
|
|
76
|
+
* The part of `path` a trim item keeps: from `start` to `end` (fractions of its pixel length, all
|
|
77
|
+
* subpaths end to end, clamped to `0..=1`), shifted by `offset` turns. Nothing when `start` is not
|
|
78
|
+
* before `end`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function trimPath(binding: GeometryBinding, path: Path, size: PictureSize, start: number, end: number, offset?: number): Path;
|
|
81
|
+
/**
|
|
82
|
+
* `path` with `vertexCounts[i]` vertices on subpath `i`, evenly along its length, so two paths can
|
|
83
|
+
* be given the same structure and their keyframes can morph. The engine never resamples on its
|
|
84
|
+
* own. A subpath whose count is missing, below 2 (3 when closed), or that has no length is kept as
|
|
85
|
+
* it is.
|
|
86
|
+
*
|
|
87
|
+
* @throws When a count is over `MAX_PATH_VERTICES`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function resamplePath(binding: GeometryBinding, path: Path, size: PictureSize, vertexCounts: readonly number[]): Path;
|
|
90
|
+
/**
|
|
91
|
+
* A rectangle, ellipse, or polystar at `time` as a path of the same outline, from the same start
|
|
92
|
+
* point and in the same direction: "convert to path".
|
|
93
|
+
*
|
|
94
|
+
* @throws When `geometry` is not valid.
|
|
95
|
+
*/
|
|
96
|
+
export declare function toPath(binding: GeometryBinding, geometry: ShapeGeometry, time: Ticks, size: PictureSize): Path;
|
|
97
|
+
/** The polyline a position travels between its keyframes, along their spatial tangents. */
|
|
98
|
+
export declare function motionPath(binding: GeometryBinding, position: AnimatedPoint, size: PictureSize): Vec2[];
|
package/dist/geometry.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape geometry for editors, answered in wasm by the code the engine draws shapes with: where a
|
|
3
|
+
* shapes generator's items are, which paint is under a point, how long a path is, and paths cut,
|
|
4
|
+
* resampled, or converted. A hit test or a trim here agrees with what a frame shows.
|
|
5
|
+
*
|
|
6
|
+
* Positions are normalized as the project document's are, `(0, 0)` top-left to `(1, 1)`
|
|
7
|
+
* bottom-right of a `width` by `height` picture; lengths and distances are in its pixels. Times
|
|
8
|
+
* are ticks, as keyframe times are.
|
|
9
|
+
*
|
|
10
|
+
* Every function throws an `INVALID_INPUT` error for a picture outside 1 to 16384 pixels a side, a
|
|
11
|
+
* time that is not a whole number of ticks, or input the model rejects (a content tree or geometry
|
|
12
|
+
* that is not valid, a path point or tangent that is not finite).
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Each item's bounds at `time`, in document order: a group's are its items', a stroke's include
|
|
16
|
+
* its width.
|
|
17
|
+
*
|
|
18
|
+
* @throws When `items` is not a valid content tree.
|
|
19
|
+
*/
|
|
20
|
+
export function shapeBounds(binding, items, time, size) {
|
|
21
|
+
return JSON.parse(binding.shapeBounds(JSON.stringify(items), time, size.width, size.height));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The front-most fill or stroke at normalized `point` at `time`, by its fill rule (a stroke by
|
|
25
|
+
* its outline): its place in the tree, or `undefined` where nothing is painted.
|
|
26
|
+
*
|
|
27
|
+
* @throws When `items` is not a valid content tree.
|
|
28
|
+
*/
|
|
29
|
+
export function hitTest(binding, items, time, size, point) {
|
|
30
|
+
return (binding.hitTest(JSON.stringify(items), time, size.width, size.height, point.x, point.y) ?? undefined);
|
|
31
|
+
}
|
|
32
|
+
/** The point of `path` nearest normalized `point`, or `undefined` for an empty path. */
|
|
33
|
+
export function nearestPoint(binding, path, size, point) {
|
|
34
|
+
return (JSON.parse(binding.nearestPoint(JSON.stringify(path), size.width, size.height, point.x, point.y)) ?? undefined);
|
|
35
|
+
}
|
|
36
|
+
/** Each subpath's length, in pixels. */
|
|
37
|
+
export function pathLength(binding, path, size) {
|
|
38
|
+
return JSON.parse(binding.pathLength(JSON.stringify(path), size.width, size.height));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The part of `path` a trim item keeps: from `start` to `end` (fractions of its pixel length, all
|
|
42
|
+
* subpaths end to end, clamped to `0..=1`), shifted by `offset` turns. Nothing when `start` is not
|
|
43
|
+
* before `end`.
|
|
44
|
+
*/
|
|
45
|
+
export function trimPath(binding, path, size, start, end, offset = 0) {
|
|
46
|
+
return JSON.parse(binding.trimPath(JSON.stringify(path), size.width, size.height, start, end, offset));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `path` with `vertexCounts[i]` vertices on subpath `i`, evenly along its length, so two paths can
|
|
50
|
+
* be given the same structure and their keyframes can morph. The engine never resamples on its
|
|
51
|
+
* own. A subpath whose count is missing, below 2 (3 when closed), or that has no length is kept as
|
|
52
|
+
* it is.
|
|
53
|
+
*
|
|
54
|
+
* @throws When a count is over `MAX_PATH_VERTICES`.
|
|
55
|
+
*/
|
|
56
|
+
export function resamplePath(binding, path, size, vertexCounts) {
|
|
57
|
+
return JSON.parse(binding.resamplePath(JSON.stringify(path), size.width, size.height, Uint32Array.from(vertexCounts)));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A rectangle, ellipse, or polystar at `time` as a path of the same outline, from the same start
|
|
61
|
+
* point and in the same direction: "convert to path".
|
|
62
|
+
*
|
|
63
|
+
* @throws When `geometry` is not valid.
|
|
64
|
+
*/
|
|
65
|
+
export function toPath(binding, geometry, time, size) {
|
|
66
|
+
return JSON.parse(binding.toPath(JSON.stringify(geometry), time, size.width, size.height));
|
|
67
|
+
}
|
|
68
|
+
/** The polyline a position travels between its keyframes, along their spatial tangents. */
|
|
69
|
+
export function motionPath(binding, position, size) {
|
|
70
|
+
return JSON.parse(binding.motionPath(JSON.stringify(position), size.width, size.height));
|
|
71
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./audio-worklet.js";
|
|
|
4
4
|
export * from "./audio.js";
|
|
5
5
|
export * from "./audio-timeline.js";
|
|
6
6
|
export * from "./audio-worker.js";
|
|
7
|
+
export * from "./containers.js";
|
|
7
8
|
export * from "./effects.js";
|
|
8
9
|
export * from "./exporter.js";
|
|
9
10
|
export * from "./extensions.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./audio-worklet.js";
|
|
|
4
4
|
export * from "./audio.js";
|
|
5
5
|
export * from "./audio-timeline.js";
|
|
6
6
|
export * from "./audio-worker.js";
|
|
7
|
+
export * from "./containers.js";
|
|
7
8
|
export * from "./effects.js";
|
|
8
9
|
export * from "./exporter.js";
|
|
9
10
|
export * from "./extensions.js";
|
package/dist/mediabunny.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { AudioDecoderRefillRequest, AudioSpeaker, BrowserDecodedFrame, Brow
|
|
|
3
3
|
import type { BrowserAudioBlockSink } from "./audio.js";
|
|
4
4
|
import type { BrowserEncodeSink, ExportedFrame } from "./exporter.js";
|
|
5
5
|
import type { VideoRateControl } from "./rate-control.js";
|
|
6
|
+
import { type ExportContainer } from "./containers.js";
|
|
6
7
|
import type { PositionedWrite } from "./export-destination.js";
|
|
7
8
|
/** Inputs supported by the optional pinned mediabunny adapter. */
|
|
8
9
|
export type MediabunnyInput = Blob | ArrayBuffer | ArrayBufferView;
|
|
@@ -143,9 +144,14 @@ export declare class MediabunnyAudioDecoder implements BrowserAudioDecoder {
|
|
|
143
144
|
close(): void;
|
|
144
145
|
}
|
|
145
146
|
/**
|
|
146
|
-
* Options for {@link
|
|
147
|
+
* Options for {@link MediabunnySink}. At least one of `videoCodec` and `audioCodec` is required.
|
|
147
148
|
*/
|
|
148
|
-
export interface
|
|
149
|
+
export interface MediabunnySinkOptions {
|
|
150
|
+
/**
|
|
151
|
+
* The file format. The codecs must be ones it offers (see `alpha2/containers`): MOV takes no VP9,
|
|
152
|
+
* AV1 or Opus, and WebM takes only VP9, AV1 and Opus.
|
|
153
|
+
*/
|
|
154
|
+
readonly container: ExportContainer;
|
|
149
155
|
/** Adds a video track in this codec; requires `videoRateControl`. */
|
|
150
156
|
readonly videoCodec?: "avc" | "hevc" | "vp9" | "av1";
|
|
151
157
|
/**
|
|
@@ -193,19 +199,20 @@ export interface MediabunnyMp4SinkOptions {
|
|
|
193
199
|
*/
|
|
194
200
|
readonly audioResampler?: AudioResamplerBinding;
|
|
195
201
|
/**
|
|
196
|
-
* Where the file goes. `stream` writes a
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* stream is closed (committed) only once
|
|
200
|
-
* and aborted (discarded) when the export
|
|
201
|
-
*
|
|
202
|
-
* caller sizes (and budgets for, see
|
|
203
|
-
* fails with `RESOURCE_LIMIT`
|
|
202
|
+
* Where the file goes. `stream` writes through a seekable positioned stream as it is muxed (see
|
|
203
|
+
* `WritableFileDestination` in `alpha2/export-destination`): MP4 and MOV put `moov` at the end,
|
|
204
|
+
* without fast start, and MKV and WebM patch sizes and Cues in place, so no part of the encoded
|
|
205
|
+
* output accumulates in memory; the stream is closed (committed) only once
|
|
206
|
+
* {@link MediabunnySink.finish} has finished the file, and aborted (discarded) when the export
|
|
207
|
+
* fails or is cancelled. `memory` keeps it in an `ArrayBuffer`, for small outputs only:
|
|
208
|
+
* `maxBytes` is the most the output may reach, which the caller sizes (and budgets for, see
|
|
209
|
+
* `memoryOutputPeakBytes`) before starting; past it the export fails with `RESOURCE_LIMIT`
|
|
210
|
+
* instead of growing.
|
|
204
211
|
*/
|
|
205
|
-
readonly destination:
|
|
212
|
+
readonly destination: ExportDestination;
|
|
206
213
|
}
|
|
207
|
-
/** Where a {@link
|
|
208
|
-
export type
|
|
214
|
+
/** Where a {@link MediabunnySink} writes. */
|
|
215
|
+
export type ExportDestination = {
|
|
209
216
|
readonly kind: "stream";
|
|
210
217
|
readonly writable: WritableStream<PositionedWrite>;
|
|
211
218
|
} | {
|
|
@@ -214,12 +221,12 @@ export type Mp4Destination = {
|
|
|
214
221
|
};
|
|
215
222
|
/**
|
|
216
223
|
* The mediabunny quality a video track encodes at for the engine's rate control: what
|
|
217
|
-
* {@link
|
|
224
|
+
* {@link MediabunnySink} configures its encoder with.
|
|
218
225
|
*/
|
|
219
226
|
export declare function videoEncoderQuality(rate: VideoRateControl): Quality;
|
|
220
227
|
/**
|
|
221
228
|
* Whether this browser can encode `codec` video at `width`x`height` with `rate`, asked with the
|
|
222
|
-
* configurations {@link
|
|
229
|
+
* configurations {@link MediabunnySink} would try. WebCodecs leaves the codecs to the browser
|
|
223
230
|
* (Chrome on Linux encodes no HEVC, for one), so an export asks before it opens its encoder.
|
|
224
231
|
*/
|
|
225
232
|
export declare function canEncodeVideoTrack(codec: "avc" | "hevc" | "vp9" | "av1", options: {
|
|
@@ -230,7 +237,7 @@ export declare function canEncodeVideoTrack(codec: "avc" | "hevc" | "vp9" | "av1
|
|
|
230
237
|
/** How a browser's video encoder is opened: see {@link videoEncoderLatencyMode}. */
|
|
231
238
|
export type VideoEncoderLatencyMode = "quality" | "realtime";
|
|
232
239
|
/**
|
|
233
|
-
* The latency mode {@link
|
|
240
|
+
* The latency mode {@link MediabunnySink} opens `codec`'s encoder with: `"realtime"` only where a
|
|
234
241
|
* quality-mode encoder puts out nothing (Safari 27's H.264) and a realtime one works. Measured once
|
|
235
242
|
* per codec.
|
|
236
243
|
*/
|
|
@@ -239,7 +246,7 @@ export declare function videoEncoderLatencyMode(codec: "avc" | "hevc" | "vp9" |
|
|
|
239
246
|
* The rate this browser encodes `codec` audio of a project at `sampleRate` with, by the rule a
|
|
240
247
|
* native host follows: the project rate when the browser's encoder takes it, else the lowest rate
|
|
241
248
|
* the codec carries above it that the encoder takes, else the highest below it; `null` when the
|
|
242
|
-
* encoder takes none. Pass it to {@link
|
|
249
|
+
* encoder takes none. Pass it to {@link MediabunnySink} as `audioSampleRate`, so every project
|
|
243
250
|
* rate exports where the browser encodes the codec at all.
|
|
244
251
|
*/
|
|
245
252
|
export declare function audioEncoderSampleRate(codec: "aac" | "opus", options: {
|
|
@@ -247,8 +254,8 @@ export declare function audioEncoderSampleRate(codec: "aac" | "opus", options: {
|
|
|
247
254
|
readonly numberOfChannels: number;
|
|
248
255
|
readonly bitrate: number;
|
|
249
256
|
}): Promise<number | null>;
|
|
250
|
-
/** What a finished {@link
|
|
251
|
-
export type
|
|
257
|
+
/** What a finished {@link MediabunnySink} produced. */
|
|
258
|
+
export type ExportOutput = {
|
|
252
259
|
readonly kind: "stream";
|
|
253
260
|
readonly bytes: number;
|
|
254
261
|
} | {
|
|
@@ -268,18 +275,18 @@ export interface AppliedVideoRateControl {
|
|
|
268
275
|
* The sink is the file: its `finish` finalizes every track, which suits one runner, or a host that
|
|
269
276
|
* writes both tracks itself and finishes once. When two runners share the file (`exportToSink` for
|
|
270
277
|
* the video and `renderOfflineAudio` for the audio, at once or one after the other), give each its
|
|
271
|
-
* track instead, {@link
|
|
278
|
+
* track instead, {@link MediabunnySink.videoTrack} and {@link MediabunnySink.audioTrack}: a
|
|
272
279
|
* runner's `finish` then ends its own track, and the file is finalized when every configured track
|
|
273
280
|
* has ended. Either track's `abort` discards the whole file, and the other runner's next write
|
|
274
281
|
* fails.
|
|
275
282
|
*
|
|
276
|
-
* The constructor throws `RangeError` when no track is configured,
|
|
277
|
-
*
|
|
278
|
-
* range.
|
|
283
|
+
* The constructor throws `RangeError` when no track is configured, the container does not offer a
|
|
284
|
+
* codec (an `ExportFormatError`), a codec lacks its rate, a memory destination's `maxBytes` is not
|
|
285
|
+
* a positive safe integer, or `stallTimeoutMs` is out of range.
|
|
279
286
|
*/
|
|
280
|
-
export declare class
|
|
287
|
+
export declare class MediabunnySink implements BrowserEncodeSink, BrowserAudioBlockSink {
|
|
281
288
|
#private;
|
|
282
|
-
constructor(options:
|
|
289
|
+
constructor(options: MediabunnySinkOptions);
|
|
283
290
|
/** The latency mode the video encoder was opened with; undefined until the sink has started. */
|
|
284
291
|
get videoLatencyMode(): VideoEncoderLatencyMode | undefined;
|
|
285
292
|
/**
|
|
@@ -332,7 +339,7 @@ export declare class MediabunnyMp4Sink implements BrowserEncodeSink, BrowserAudi
|
|
|
332
339
|
* The finished output: its length for a stream, the bytes in memory. Null until {@link finish}
|
|
333
340
|
* resolves.
|
|
334
341
|
*/
|
|
335
|
-
get output():
|
|
342
|
+
get output(): ExportOutput | null;
|
|
336
343
|
/** Bytes muxed so far: the file's length as written. */
|
|
337
344
|
get bytesWritten(): number;
|
|
338
345
|
}
|
package/dist/mediabunny.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readAudioSpeakers } from "./audio-layout.js";
|
|
2
2
|
import { chromaSitingForStream } from "./chroma-siting.js";
|
|
3
3
|
import { decoderOrderKey, decoderPlaneOrder } from "./decoder-order.js";
|
|
4
|
-
import { ALL_FORMATS, AudioSample, AudioSampleSink, AudioSampleSource, BlobSource, BufferTarget, BufferSource, canEncodeAudio, canEncodeVideo, StreamTarget, EncodedPacketSink, Input, Mp4OutputFormat, Output, Quality, VideoSample, VideoSampleSink, VideoSampleSource, } from "mediabunny";
|
|
4
|
+
import { ALL_FORMATS, AudioSample, AudioSampleSink, AudioSampleSource, BlobSource, BufferTarget, BufferSource, canEncodeAudio, canEncodeVideo, StreamTarget, EncodedPacketSink, Input, MkvOutputFormat, MovOutputFormat, Mp4OutputFormat, Output, Quality, VideoSample, VideoSampleSink, VideoSampleSource, WebMOutputFormat, } from "mediabunny";
|
|
5
5
|
import { audioFrameGrid, MAX_AUDIO_CHANNELS, microsecondsToTicks, placeOnAudioFrameGrid, presentationSlackTicks, readMatroskaCodecDelay, readVideoOrientation, roundingQuantum, ROUNDING_SCAN_BYTES, ROUNDING_SCAN_FRAMES, validateStallTimeout, } from "./media.js";
|
|
6
|
+
import { resolveExportFormat } from "./containers.js";
|
|
6
7
|
import { ExportFailureError } from "./export-failure.js";
|
|
7
8
|
/**
|
|
8
9
|
* How far past the decode cursor a request may be (2 s) and still be reached by decoding forward;
|
|
@@ -1084,7 +1085,7 @@ export class MediabunnyAudioDecoder {
|
|
|
1084
1085
|
}
|
|
1085
1086
|
/**
|
|
1086
1087
|
* The mediabunny quality a video track encodes at for the engine's rate control: what
|
|
1087
|
-
* {@link
|
|
1088
|
+
* {@link MediabunnySink} configures its encoder with.
|
|
1088
1089
|
*/
|
|
1089
1090
|
export function videoEncoderQuality(rate) {
|
|
1090
1091
|
return new Quality({
|
|
@@ -1095,7 +1096,7 @@ export function videoEncoderQuality(rate) {
|
|
|
1095
1096
|
}
|
|
1096
1097
|
/**
|
|
1097
1098
|
* Whether this browser can encode `codec` video at `width`x`height` with `rate`, asked with the
|
|
1098
|
-
* configurations {@link
|
|
1099
|
+
* configurations {@link MediabunnySink} would try. WebCodecs leaves the codecs to the browser
|
|
1099
1100
|
* (Chrome on Linux encodes no HEVC, for one), so an export asks before it opens its encoder.
|
|
1100
1101
|
*/
|
|
1101
1102
|
export async function canEncodeVideoTrack(codec, options) {
|
|
@@ -1105,7 +1106,10 @@ export async function canEncodeVideoTrack(codec, options) {
|
|
|
1105
1106
|
quality: videoEncoderQuality(options.rate),
|
|
1106
1107
|
}).catch(() => false);
|
|
1107
1108
|
}
|
|
1108
|
-
/**
|
|
1109
|
+
/**
|
|
1110
|
+
* The profiles mediabunny opens (H.264 High, HEVC Main, VP9 profile 0, AV1 Main), at a level for
|
|
1111
|
+
* the probe's frames.
|
|
1112
|
+
*/
|
|
1109
1113
|
const LATENCY_PROBE_CODECS = {
|
|
1110
1114
|
avc: "avc1.64001e",
|
|
1111
1115
|
hevc: "hev1.1.6.L93.B0",
|
|
@@ -1120,7 +1124,7 @@ const LATENCY_PROBE_FRAMES = 6;
|
|
|
1120
1124
|
const LATENCY_PROBE_TIMEOUT_MS = 1_500;
|
|
1121
1125
|
const latencyModes = new Map();
|
|
1122
1126
|
/**
|
|
1123
|
-
* The latency mode {@link
|
|
1127
|
+
* The latency mode {@link MediabunnySink} opens `codec`'s encoder with: `"realtime"` only where a
|
|
1124
1128
|
* quality-mode encoder puts out nothing (Safari 27's H.264) and a realtime one works. Measured once
|
|
1125
1129
|
* per codec.
|
|
1126
1130
|
*/
|
|
@@ -1218,7 +1222,7 @@ async function encoderPutsOut(codec, latencyMode) {
|
|
|
1218
1222
|
}
|
|
1219
1223
|
}
|
|
1220
1224
|
/**
|
|
1221
|
-
* The sample rates each audio codec a {@link
|
|
1225
|
+
* The sample rates each audio codec a {@link MediabunnySink} writes can carry, lowest first:
|
|
1222
1226
|
* AAC's MPEG-4 rates up to the project limit, and Opus's.
|
|
1223
1227
|
*/
|
|
1224
1228
|
const ENCODER_SAMPLE_RATES = {
|
|
@@ -1232,7 +1236,7 @@ const ENCODER_SAMPLE_RATES = {
|
|
|
1232
1236
|
* The rate this browser encodes `codec` audio of a project at `sampleRate` with, by the rule a
|
|
1233
1237
|
* native host follows: the project rate when the browser's encoder takes it, else the lowest rate
|
|
1234
1238
|
* the codec carries above it that the encoder takes, else the highest below it; `null` when the
|
|
1235
|
-
* encoder takes none. Pass it to {@link
|
|
1239
|
+
* encoder takes none. Pass it to {@link MediabunnySink} as `audioSampleRate`, so every project
|
|
1236
1240
|
* rate exports where the browser encodes the codec at all.
|
|
1237
1241
|
*/
|
|
1238
1242
|
export async function audioEncoderSampleRate(codec, options) {
|
|
@@ -1337,22 +1341,39 @@ class EncoderRateConverter {
|
|
|
1337
1341
|
return { startSample: start, channels };
|
|
1338
1342
|
}
|
|
1339
1343
|
}
|
|
1344
|
+
/**
|
|
1345
|
+
* The muxer for `container`. MP4 and MOV go without fast start and MKV and WebM are not
|
|
1346
|
+
* append-only, so the payload is never held in memory or rewritten: the muxer seeks back only to
|
|
1347
|
+
* patch headers.
|
|
1348
|
+
*/
|
|
1349
|
+
function outputFormat(container) {
|
|
1350
|
+
switch (container) {
|
|
1351
|
+
case "mp4":
|
|
1352
|
+
return new Mp4OutputFormat({ fastStart: false });
|
|
1353
|
+
case "mov":
|
|
1354
|
+
return new MovOutputFormat({ fastStart: false });
|
|
1355
|
+
case "mkv":
|
|
1356
|
+
return new MkvOutputFormat({ appendOnly: false });
|
|
1357
|
+
case "webm":
|
|
1358
|
+
return new WebMOutputFormat({ appendOnly: false });
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1340
1361
|
/**
|
|
1341
1362
|
* Optional mediabunny encoder/muxer implementing both public alpha2 sinks.
|
|
1342
1363
|
*
|
|
1343
1364
|
* The sink is the file: its `finish` finalizes every track, which suits one runner, or a host that
|
|
1344
1365
|
* writes both tracks itself and finishes once. When two runners share the file (`exportToSink` for
|
|
1345
1366
|
* the video and `renderOfflineAudio` for the audio, at once or one after the other), give each its
|
|
1346
|
-
* track instead, {@link
|
|
1367
|
+
* track instead, {@link MediabunnySink.videoTrack} and {@link MediabunnySink.audioTrack}: a
|
|
1347
1368
|
* runner's `finish` then ends its own track, and the file is finalized when every configured track
|
|
1348
1369
|
* has ended. Either track's `abort` discards the whole file, and the other runner's next write
|
|
1349
1370
|
* fails.
|
|
1350
1371
|
*
|
|
1351
|
-
* The constructor throws `RangeError` when no track is configured,
|
|
1352
|
-
*
|
|
1353
|
-
* range.
|
|
1372
|
+
* The constructor throws `RangeError` when no track is configured, the container does not offer a
|
|
1373
|
+
* codec (an `ExportFormatError`), a codec lacks its rate, a memory destination's `maxBytes` is not
|
|
1374
|
+
* a positive safe integer, or `stallTimeoutMs` is out of range.
|
|
1354
1375
|
*/
|
|
1355
|
-
export class
|
|
1376
|
+
export class MediabunnySink {
|
|
1356
1377
|
#target;
|
|
1357
1378
|
/**
|
|
1358
1379
|
* A stream destination, written through the muxer and committed or discarded by this sink alone:
|
|
@@ -1385,6 +1406,17 @@ export class MediabunnyMp4Sink {
|
|
|
1385
1406
|
#videoTrack;
|
|
1386
1407
|
#audioTrack;
|
|
1387
1408
|
constructor(options) {
|
|
1409
|
+
// Before anything is opened or locked: a pair the container does not offer is the caller's
|
|
1410
|
+
// mistake, not a failed export.
|
|
1411
|
+
resolveExportFormat({
|
|
1412
|
+
container: options.container,
|
|
1413
|
+
...(options.videoCodec === undefined
|
|
1414
|
+
? {}
|
|
1415
|
+
: { videoCodec: options.videoCodec }),
|
|
1416
|
+
...(options.audioCodec === undefined
|
|
1417
|
+
? {}
|
|
1418
|
+
: { audioCodec: options.audioCodec }),
|
|
1419
|
+
});
|
|
1388
1420
|
const destination = options.destination;
|
|
1389
1421
|
if (destination.kind === "memory") {
|
|
1390
1422
|
if (!Number.isSafeInteger(destination.maxBytes) ||
|
|
@@ -1428,8 +1460,7 @@ export class MediabunnyMp4Sink {
|
|
|
1428
1460
|
};
|
|
1429
1461
|
}
|
|
1430
1462
|
this.#output = new Output({
|
|
1431
|
-
|
|
1432
|
-
format: new Mp4OutputFormat({ fastStart: false }),
|
|
1463
|
+
format: outputFormat(options.container),
|
|
1433
1464
|
target: this.#target,
|
|
1434
1465
|
});
|
|
1435
1466
|
this.#hasVideo = options.videoCodec !== undefined;
|
package/dist/player.d.ts
CHANGED
|
@@ -48,6 +48,11 @@ export interface PresentedFrame {
|
|
|
48
48
|
readonly missingFrames: readonly MissingFrame[];
|
|
49
49
|
/** Whether the previous picture was shown again instead of a new one. */
|
|
50
50
|
readonly repeated: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the frame equals the one on screen, so nothing was rendered or presented: the canvas
|
|
53
|
+
* still shows it.
|
|
54
|
+
*/
|
|
55
|
+
readonly unchanged: boolean;
|
|
51
56
|
}
|
|
52
57
|
/** The worker-side renderer an {@link Alpha2Player} drives. */
|
|
53
58
|
export interface RenderBackend {
|
package/dist/project.d.ts
CHANGED
|
@@ -150,6 +150,15 @@ export type LintOwner = {
|
|
|
150
150
|
readonly track: string;
|
|
151
151
|
readonly index: number;
|
|
152
152
|
};
|
|
153
|
+
/** The shapes generator a shape {@link LintIssue} is about. */
|
|
154
|
+
export type ShapeLintOwner = {
|
|
155
|
+
readonly type: "source";
|
|
156
|
+
readonly source: string;
|
|
157
|
+
} | {
|
|
158
|
+
readonly type: "node";
|
|
159
|
+
readonly composition: string;
|
|
160
|
+
readonly node: string;
|
|
161
|
+
};
|
|
153
162
|
/**
|
|
154
163
|
* Something in a valid project that is probably not meant. Every check is conservative: a reported
|
|
155
164
|
* issue is certain.
|
|
@@ -198,6 +207,20 @@ export type LintIssue =
|
|
|
198
207
|
| {
|
|
199
208
|
readonly kind: "hdr_source";
|
|
200
209
|
readonly source: string;
|
|
210
|
+
}
|
|
211
|
+
/** A path's subpath without vertices, which draws nothing. */
|
|
212
|
+
| {
|
|
213
|
+
readonly kind: "empty_subpath";
|
|
214
|
+
readonly owner: ShapeLintOwner;
|
|
215
|
+
/** Such as `items[0].path.subpaths[1]`. */
|
|
216
|
+
readonly at: string;
|
|
217
|
+
}
|
|
218
|
+
/** A fill or stroke with no geometry before it in its group, which paints nothing. */
|
|
219
|
+
| {
|
|
220
|
+
readonly kind: "paint_without_geometry";
|
|
221
|
+
readonly owner: ShapeLintOwner;
|
|
222
|
+
/** Such as `items[1].items[0]`. */
|
|
223
|
+
readonly at: string;
|
|
201
224
|
};
|
|
202
225
|
/** The part of `alpha2/wasm` {@link lintProject} uses. */
|
|
203
226
|
export interface LintBinding {
|
|
@@ -205,8 +228,9 @@ export interface LintBinding {
|
|
|
205
228
|
}
|
|
206
229
|
/**
|
|
207
230
|
* A valid project's non-fatal diagnostics, computed by the engine's own
|
|
208
|
-
* `Project::lint`, in a fixed order: sources, then
|
|
209
|
-
*
|
|
231
|
+
* `Project::lint`, in a fixed order: unused sources, then shapes generators
|
|
232
|
+
* (sources', then composition nodes'), then HDR sources, then each track's
|
|
233
|
+
* clips, transitions, and cues.
|
|
210
234
|
*
|
|
211
235
|
* Diagnostics never block a load or an export; they flag what is probably a
|
|
212
236
|
* mistake in a project the engine accepts.
|