alpha2 0.4.5 → 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/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +28 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +109 -173
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +98 -157
- package/dist/frame-supply.js +191 -162
- package/dist/generated/project-schema.d.ts +742 -464
- package/dist/generated/project-schema.js +63 -2
- package/dist/generated/project-shape.js +663 -118
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +88 -62
- package/dist/hdr-frames.js +123 -46
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +55 -55
- package/dist/layout.js +37 -36
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +173 -237
- package/dist/mediabunny.js +943 -518
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +83 -110
- package/dist/project.js +421 -447
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +106 -63
- package/dist/text.js +44 -69
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -92
- package/dist/worker.js +239 -144
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +487 -543
- package/wasm/alpha2_wasm.js +669 -572
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +20 -8
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-57b04ecc6db57e1f/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
package/dist/mediabunny.d.ts
CHANGED
|
@@ -1,167 +1,144 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AacEncoderProbe, VideoLatencyProbe } from "./export-metrics.js";
|
|
2
|
+
export type { AacEncoderProbe, AacProbeOutcome, EncoderProbeOutcome, VideoLatencyProbe, } from "./export-metrics.js";
|
|
3
|
+
import { type InputAudioTrack, type InputVideoTrack, Quality } from "mediabunny";
|
|
2
4
|
import type { AudioDecoderRefillRequest, AudioSpeaker, BrowserDecodedFrame, BrowserAudioBlock, BrowserAudioDecoder, BrowserVideoDecoder, BrowserVideoDecoderOptions, DecoderRefillRequest, OptionalMediaAdapterFactory } from "./media.js";
|
|
5
|
+
import { type TrackDecodeFacts } from "./hdr-frames.js";
|
|
6
|
+
import type { ColorMetadata } from "./generated/project-schema.js";
|
|
3
7
|
import type { BrowserAudioBlockSink } from "./audio.js";
|
|
4
8
|
import type { BrowserEncodeSink, ExportedFrame } from "./exporter.js";
|
|
5
9
|
import type { VideoRateControl } from "./rate-control.js";
|
|
6
10
|
import { type ExportContainer } from "./containers.js";
|
|
7
11
|
import type { PositionedWrite } from "./export-destination.js";
|
|
8
|
-
/** Inputs supported by the optional pinned mediabunny adapter. */
|
|
9
12
|
export type MediabunnyInput = Blob | ArrayBuffer | ArrayBufferView;
|
|
10
13
|
/** Limits for {@link MediabunnyVideoDecoder.open}, on top of the shared decoder options. */
|
|
11
14
|
export interface MediabunnyVideoDecoderOptions extends BrowserVideoDecoderOptions {
|
|
12
15
|
/**
|
|
13
|
-
* Bytes of frames
|
|
14
|
-
*
|
|
15
|
-
* fewer times.
|
|
16
|
+
* Bytes of copied frames for backward playback (default 128 MiB); copies hold no decoder
|
|
17
|
+
* surfaces.
|
|
16
18
|
*/
|
|
17
19
|
readonly maxReverseFrameBytes?: number;
|
|
18
|
-
/**
|
|
19
|
-
* The decoder the browser is asked for (default `"no-preference"`, which lets it pick hardware).
|
|
20
|
-
* Whichever it picks, a decoder that fails is replaced once by a software decoder: see {@link
|
|
21
|
-
* MediabunnyVideoDecoder.refill}.
|
|
22
|
-
*/
|
|
20
|
+
/** Default `"no-preference"`; a failing decoder is replaced once by a software one. */
|
|
23
21
|
readonly hardwareAcceleration?: HardwareAcceleration;
|
|
24
22
|
}
|
|
25
23
|
/**
|
|
26
|
-
* Optional demux/decode adapter
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* it, seeks: decoding restarts at the keyframe before it, and the frames it passes go through a
|
|
30
|
-
* window of the last two decoder frames. A decoder that produces no frame for the stall timeout
|
|
31
|
-
* fails the request instead of holding it, and every request after it, forever. When requests keep
|
|
32
|
-
* stepping back (a reversed clip, a ping-pong loop's backward pass), the next miss decodes a
|
|
33
|
-
* reverse window instead: the frames up to the requested time, from the keyframe before it, copied
|
|
34
|
-
* out of the decoder so that dozens can be kept without stalling it. The run then plays from that
|
|
35
|
-
* window, and each keyframe interval is decoded about `interval / window` times rather than once
|
|
36
|
-
* per frame.
|
|
24
|
+
* Optional mediabunny demux/decode adapter for alpha2's decoder contract. Forward requests share
|
|
25
|
+
* one sequential decode; a backward run (reversed clip, ping-pong loop) decodes windows of frames
|
|
26
|
+
* copied out of the decoder, so each keyframe interval is decoded a few times instead of per frame.
|
|
37
27
|
*/
|
|
38
28
|
export declare class MediabunnyVideoDecoder implements BrowserVideoDecoder {
|
|
39
29
|
#private;
|
|
40
30
|
private constructor();
|
|
41
31
|
/**
|
|
42
|
-
* Opens `resource`'s primary video track. Rejects when it has none
|
|
43
|
-
*
|
|
44
|
-
* "prefer-software"`, a track the browser has no software decoder for rejects with `code:
|
|
32
|
+
* Opens `resource`'s primary video track. Rejects when it has none or this browser cannot decode
|
|
33
|
+
* it; with `"prefer-software"` and no software decoder, with `code:
|
|
45
34
|
* "software_decode_unavailable"`.
|
|
46
35
|
*/
|
|
47
36
|
static open(sourceId: string, resource: MediabunnyInput, options?: MediabunnyVideoDecoderOptions): Promise<MediabunnyVideoDecoder>;
|
|
48
|
-
/** Bytes both windows hold: decoder frames and reverse copies. */
|
|
49
37
|
get cachedFrameBytes(): number;
|
|
50
|
-
/** Requests answered from a window without decoding. */
|
|
51
38
|
get reverseCacheHits(): number;
|
|
52
|
-
/** Reverse windows decoded: one per stretch of a backward run. */
|
|
53
39
|
get reverseWindowsBuilt(): number;
|
|
54
|
-
/**
|
|
55
|
-
* Why the decoder moved to software decoding, when the one the browser picked first failed;
|
|
56
|
-
* `undefined` while that one serves.
|
|
57
|
-
*/
|
|
40
|
+
/** Why decoding moved to software after the browser's first pick failed, if it did. */
|
|
58
41
|
get softwareFallback(): string | undefined;
|
|
59
42
|
/**
|
|
60
|
-
* The frame presented at the request's time.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* on Linux report `EncodingError: Decoding error.`), so a decoder failure replaces it, once, with
|
|
64
|
-
* a software decoder, which decodes the request again from its keyframe. A software decoder that
|
|
65
|
-
* fails too rejects the request.
|
|
43
|
+
* The frame presented at the request's time. A decoder failure (Chromium's VA-API decoders report
|
|
44
|
+
* `EncodingError`) retries once with a software decoder; if that fails, rejects with
|
|
45
|
+
* {@link DecodeUnavailableError} when no frame was ever decoded, else with the failure.
|
|
66
46
|
*/
|
|
67
47
|
refill(request: DecoderRefillRequest, signal?: AbortSignal): Promise<BrowserDecodedFrame>;
|
|
68
|
-
/** Drops the decode cursor and both windows; the next request seeks. */
|
|
69
48
|
flush(): Promise<void>;
|
|
70
|
-
/** Releases the decoder, both windows, and the input. A later `refill` rejects. */
|
|
71
49
|
close(): void;
|
|
72
50
|
}
|
|
73
|
-
/**
|
|
74
|
-
* The part of `alpha2/wasm` the audio adapter resamples with: the engine's `AudioResampler`, the
|
|
75
|
-
* converter a native host uses.
|
|
76
|
-
*/
|
|
51
|
+
/** The part of `alpha2/wasm` the audio adapter resamples with. */
|
|
77
52
|
export interface AudioResamplerBinding {
|
|
78
53
|
readonly AudioResampler: new (sourceRate: number, targetRate: number) => AudioResampler;
|
|
79
54
|
}
|
|
80
55
|
/**
|
|
81
|
-
* One `alpha2/wasm` `AudioResampler`.
|
|
82
|
-
*
|
|
56
|
+
* One `alpha2/wasm` `AudioResampler`. Source positions are at the source rate, outputs at the
|
|
57
|
+
* project rate.
|
|
83
58
|
*/
|
|
84
59
|
export interface AudioResampler {
|
|
85
|
-
/** The first source sample output `targetStart` weighs. */
|
|
86
60
|
sourceStart(targetStart: number): number;
|
|
87
|
-
/** The source sample after the last one output `targetEnd - 1` weighs. */
|
|
88
61
|
sourceEnd(targetEnd: number): number;
|
|
89
|
-
/** The first output sample at or after source sample `source`. */
|
|
90
62
|
targetAtOrAfter(source: number): number;
|
|
91
|
-
/**
|
|
92
|
-
* `frames` outputs from `targetStart`, from `input` starting at source sample `inputStart`; the
|
|
93
|
-
* source is silent outside `input`.
|
|
94
|
-
*/
|
|
63
|
+
/** The source is silent outside `input`. */
|
|
95
64
|
resample(input: Float32Array, inputStart: number, targetStart: number, frames: number): Float32Array;
|
|
96
65
|
free?(): void;
|
|
97
66
|
}
|
|
67
|
+
/** The facts a refusal message names ({@link decodeRefusalMessage}), with `extra` over them. */
|
|
68
|
+
export declare function videoTrackFacts(track: InputVideoTrack, extra?: Partial<TrackDecodeFacts>): Promise<TrackDecodeFacts>;
|
|
69
|
+
/**
|
|
70
|
+
* Whether this browser hands `resource`'s video over as planes the engine reads, for sources that
|
|
71
|
+
* need them (HDR, or a `declared` color). Resolves `"not-required"`, `"decoder"`, or `"software"`
|
|
72
|
+
* when only a software decoder gives planar frames. Each decode waits at most `timeoutMs`
|
|
73
|
+
* (default 5000). Rejects with {@link PlanarDecodeUnavailableError} when no readable frames
|
|
74
|
+
* decode, and with {@link DecodeUnavailableError} when there is no video track.
|
|
75
|
+
*/
|
|
76
|
+
export declare function probePlanarDecode(resource: MediabunnyInput, options: {
|
|
77
|
+
declared: ColorMetadata | null;
|
|
78
|
+
timeoutMs?: number;
|
|
79
|
+
}): Promise<{
|
|
80
|
+
planes: "not-required" | "decoder" | "software";
|
|
81
|
+
}>;
|
|
82
|
+
export interface AudioTrialDecode {
|
|
83
|
+
readonly channels: number;
|
|
84
|
+
readonly sampleRate: number;
|
|
85
|
+
readonly planeRms: readonly number[];
|
|
86
|
+
}
|
|
87
|
+
/** An audio track this browser decodes, as measured by a trial decode. */
|
|
88
|
+
export interface DecodableAudioTrack {
|
|
89
|
+
readonly channels: number;
|
|
90
|
+
readonly sampleRate: number;
|
|
91
|
+
readonly speakers: AudioSpeaker[] | null;
|
|
92
|
+
/** The decoder delivers one silent plane more than declared (an added LFE). */
|
|
93
|
+
readonly addedLfe: boolean;
|
|
94
|
+
readonly trial: AudioTrialDecode;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Whether this browser decodes `track`, by a trial decode of its first packet (Firefox's
|
|
98
|
+
* `canDecode()` says true for AAC layouts it then rejects), and the channel count, rate and
|
|
99
|
+
* speakers it delivers. A silent extra plane is taken as an added LFE (Edge decodes E-AC-3 5.0 as
|
|
100
|
+
* 5.1). Rejects with {@link DecodeUnavailableError} when the track does not decode as declared.
|
|
101
|
+
*/
|
|
102
|
+
export declare function probeAudioDecode(name: string, track: InputAudioTrack, declared: readonly AudioSpeaker[] | null): Promise<DecodableAudioTrack>;
|
|
103
|
+
/** {@link probeAudioDecode} on the primary audio track; rejects with `Error` when there is none. */
|
|
104
|
+
export declare function probeAudioSource(name: string, resource: MediabunnyInput): Promise<DecodableAudioTrack>;
|
|
98
105
|
/**
|
|
99
|
-
* Optional mediabunny audio demux/decode adapter with project-rate resampling
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* silence, one further back drops what it repeats. A window's first sample goes on the frame grid
|
|
104
|
-
* the stream's first timestamps show ({@link audioFrameGrid}), so in a file that rounds them
|
|
105
|
-
* (Matroska, WebM) every window holds its samples where a decode from the start puts them. A
|
|
106
|
-
* window's source samples are then resampled together by the engine's `AudioResampler`, so a window
|
|
107
|
-
* holds the samples a native decode of the same source holds.
|
|
108
|
-
*
|
|
109
|
-
* Every channel is kept, 1 to {@link MAX_AUDIO_CHANNELS}, and each block names the speaker each
|
|
110
|
-
* feeds ({@link MediabunnyAudioDecoder.speakers}), read from the file as a native host reads it: a
|
|
111
|
-
* WAVE channel mask, a QuickTime `chan` box, or the codec's channel configuration (AAC, Opus
|
|
112
|
-
* mapping family 1, Vorbis, FLAC). The engine folds them by speaker. Those speakers are in the
|
|
113
|
-
* order `FFmpeg`'s decoder delivers; a browser decoder that delivers another (Safari's AAC decoder
|
|
114
|
-
* keeps the bitstream's) has its planes put back in that order, as measured once per kind of
|
|
115
|
-
* stream: an AAC channel configuration or program config element, an Opus or Vorbis channel
|
|
116
|
-
* count, an AC-3 or E-AC-3 layout ({@link decoderPlaneOrder}).
|
|
106
|
+
* Optional mediabunny audio demux/decode adapter with project-rate resampling, placing samples as
|
|
107
|
+
* a native host does (including the {@link audioFrameGrid}). Keeps every channel, 1 to
|
|
108
|
+
* {@link MAX_AUDIO_CHANNELS}, reordered to `FFmpeg`'s plane order where a browser decoder differs
|
|
109
|
+
* (Safari's AAC).
|
|
117
110
|
*/
|
|
118
111
|
export declare class MediabunnyAudioDecoder implements BrowserAudioDecoder {
|
|
119
112
|
#private;
|
|
120
113
|
/**
|
|
121
|
-
* The speaker each plane
|
|
122
|
-
* `
|
|
123
|
-
* no `speakers`, and the engine assumes `FFmpeg`'s default for the channel count, as a native
|
|
124
|
-
* host does. A host may report a `null` layout of more than two channels as a guess.
|
|
114
|
+
* The speaker each plane feeds. `null` when the source declares no layout; the engine then
|
|
115
|
+
* assumes `FFmpeg`'s default for the channel count.
|
|
125
116
|
*/
|
|
126
117
|
readonly speakers: readonly AudioSpeaker[] | null;
|
|
127
118
|
private constructor();
|
|
128
119
|
/**
|
|
129
|
-
* Opens `resource`'s primary audio track,
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* {@link MAX_AUDIO_CHANNELS} or its sample rate outside 1 kHz to 768 kHz (`RangeError`), or when
|
|
133
|
-
* its decoder configuration or channel layout cannot be read.
|
|
120
|
+
* Opens `resource`'s primary audio track. Rejects when there is none, with `RangeError` for more
|
|
121
|
+
* than {@link MAX_AUDIO_CHANNELS} channels or a rate outside 1 kHz to 768 kHz, and with
|
|
122
|
+
* {@link DecodeUnavailableError} when this browser cannot decode it.
|
|
134
123
|
*/
|
|
135
124
|
static open(sourceId: string, resource: MediabunnyInput, binding: AudioResamplerBinding): Promise<MediabunnyAudioDecoder>;
|
|
136
125
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* the rate is not a positive integer, `signal` aborts, or the track changes channel count or
|
|
142
|
-
* sample rate mid-stream.
|
|
126
|
+
* Decodes the interval at `projectSampleRate`, plus two samples each side; silence outside the
|
|
127
|
+
* stream. Rejects when closed, for another source or empty interval, on abort, or when the track
|
|
128
|
+
* changes format mid-stream; with {@link DecodeUnavailableError} when the browser's decoder
|
|
129
|
+
* fails.
|
|
143
130
|
*/
|
|
144
131
|
refill(request: AudioDecoderRefillRequest, projectSampleRate: number, signal?: AbortSignal): Promise<BrowserAudioBlock>;
|
|
145
|
-
/** Frees the resampler and the input. A later `refill` rejects. */
|
|
146
132
|
close(): void;
|
|
147
133
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Options for {@link MediabunnySink}. At least one of `videoCodec` and `audioCodec` is required.
|
|
150
|
-
*/
|
|
134
|
+
/** At least one of `videoCodec` and `audioCodec` is required. */
|
|
151
135
|
export interface MediabunnySinkOptions {
|
|
152
|
-
/**
|
|
153
|
-
* The file format. The codecs must be ones it offers (see `alpha2/containers`): MOV takes no VP9,
|
|
154
|
-
* AV1 or Opus, and WebM takes only VP9, AV1 and Opus.
|
|
155
|
-
*/
|
|
136
|
+
/** The codecs must be ones the container offers (see `alpha2/containers`). */
|
|
156
137
|
readonly container: ExportContainer;
|
|
157
138
|
/** Adds a video track in this codec; requires `videoRateControl`. */
|
|
158
139
|
readonly videoCodec?: "avc" | "hevc" | "vp9" | "av1";
|
|
159
140
|
/**
|
|
160
|
-
* Exact project frame rate
|
|
161
|
-
*
|
|
162
|
-
* Declaring it snaps every written timestamp and duration to the rate, which is what produces a
|
|
163
|
-
* constant-frame-rate track. Without it the muxer derives durations from floating-point timestamp
|
|
164
|
-
* deltas and can alternate between neighbouring values, which plays back as intermittent judder.
|
|
141
|
+
* Exact project frame rate; without it the muxer derives durations from float deltas and judders.
|
|
165
142
|
*/
|
|
166
143
|
readonly frameRate?: {
|
|
167
144
|
readonly num: number;
|
|
@@ -170,52 +147,32 @@ export interface MediabunnySinkOptions {
|
|
|
170
147
|
/** Adds an audio track in this codec; requires `audioBitrate`. */
|
|
171
148
|
readonly audioCodec?: "aac" | "opus";
|
|
172
149
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* This adapter takes numbers and never a quality level: what a level costs is the engine's
|
|
176
|
-
* decision (`resolveVideoRateControl` in `alpha2`), so a caller that swaps this sink for its own
|
|
177
|
-
* WebCodecs one receives the same numbers this one does. With a `quantizer`, mediabunny tries
|
|
178
|
-
* constant-quantizer encoding first and falls back to `bitrate` where the browser's encoder
|
|
179
|
-
* refuses it; `appliedVideoRateControl` says which ran.
|
|
150
|
+
* Required with `videoCodec`. With a `quantizer`, constant-quantizer encoding is tried first,
|
|
151
|
+
* falling back to `bitrate`; `appliedVideoRateControl` says which ran.
|
|
180
152
|
*/
|
|
181
153
|
readonly videoRateControl?: VideoRateControl;
|
|
182
|
-
/**
|
|
183
|
-
* The WebCodecs codec string the video encoder opens with: the `codecString`
|
|
184
|
-
* {@link canEncodeVideoTrack} chose, so H.264 opens in the profile this browser encodes. By
|
|
185
|
-
* default mediabunny's own (H.264 High at a level for the frame size and bitrate).
|
|
186
|
-
*/
|
|
154
|
+
/** Normally {@link canEncodeVideoTrack}'s `codecString`; defaults to mediabunny's choice. */
|
|
187
155
|
readonly videoCodecString?: string;
|
|
188
|
-
/**
|
|
156
|
+
/** Keep alpha (VP9 in WebM or Matroska). Check {@link canEncodePixels} first. */
|
|
157
|
+
readonly videoAlpha?: boolean;
|
|
158
|
+
/** 10 encodes `I420P10` frames with {@link tenBitCodecString}. Default 8. */
|
|
159
|
+
readonly videoBitDepth?: 8 | 10;
|
|
160
|
+
/** Defaults to what {@link videoEncoderLatencyMode} measures. */
|
|
189
161
|
readonly videoLatencyMode?: VideoEncoderLatencyMode;
|
|
190
|
-
/**
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
*/
|
|
162
|
+
/** Default `"no-preference"`. Check {@link canEncodeInSoftware} before asking for software. */
|
|
163
|
+
readonly videoHardwareAcceleration?: "no-preference" | "prefer-software";
|
|
164
|
+
/** Writes reject with `ENCODE_STALLED` after this long without output (default 10 s). */
|
|
194
165
|
readonly stallTimeoutMs?: number;
|
|
195
|
-
/**
|
|
166
|
+
/** Bits per second. Required with `audioCodec`. */
|
|
196
167
|
readonly audioBitrate?: number;
|
|
197
|
-
/**
|
|
198
|
-
* The rate the audio encoder is given, already resolved: {@link audioEncoderSampleRate}'s answer
|
|
199
|
-
* for the project rate. Blocks at another rate (the project's) are converted to it with
|
|
200
|
-
* `audioResampler`, the engine's converter, as a native host converts for an encoder that does
|
|
201
|
-
* not take the project rate. Defaults to the blocks' own rate.
|
|
202
|
-
*/
|
|
168
|
+
/** Normally {@link audioEncoderSampleRate}'s answer; defaults to the blocks' own rate. */
|
|
203
169
|
readonly audioSampleRate?: number;
|
|
204
|
-
/**
|
|
205
|
-
* The initialized `alpha2/wasm` module, whose `AudioResampler` converts the blocks to
|
|
206
|
-
* `audioSampleRate`. Required when that differs from the blocks' rate.
|
|
207
|
-
*/
|
|
170
|
+
/** Required when `audioSampleRate` differs from the blocks' rate. */
|
|
208
171
|
readonly audioResampler?: AudioResamplerBinding;
|
|
209
172
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* output accumulates in memory; the stream is closed (committed) only once
|
|
214
|
-
* {@link MediabunnySink.finish} has finished the file, and aborted (discarded) when the export
|
|
215
|
-
* fails or is cancelled. `memory` keeps it in an `ArrayBuffer`, for small outputs only:
|
|
216
|
-
* `maxBytes` is the most the output may reach, which the caller sizes (and budgets for, see
|
|
217
|
-
* `memoryOutputPeakBytes`) before starting; past it the export fails with `RESOURCE_LIMIT`
|
|
218
|
-
* instead of growing.
|
|
173
|
+
* `stream` writes through a seekable stream as it muxes, committed by
|
|
174
|
+
* {@link MediabunnySink.finish} and discarded on failure. `memory` is for small outputs; past
|
|
175
|
+
* `maxBytes` the export fails with `RESOURCE_LIMIT`.
|
|
219
176
|
*/
|
|
220
177
|
readonly destination: ExportDestination;
|
|
221
178
|
}
|
|
@@ -227,25 +184,14 @@ export type ExportDestination = {
|
|
|
227
184
|
readonly kind: "memory";
|
|
228
185
|
readonly maxBytes: number;
|
|
229
186
|
};
|
|
230
|
-
/**
|
|
231
|
-
* The mediabunny quality a video track encodes at for the engine's rate control: what
|
|
232
|
-
* {@link MediabunnySink} configures its encoder with.
|
|
233
|
-
*/
|
|
234
187
|
export declare function videoEncoderQuality(rate: VideoRateControl): Quality;
|
|
235
|
-
/** An H.264 profile a browser export asks the encoder for, named as the standard names it. */
|
|
236
188
|
export type AvcProfile = "High" | "Main" | "Constrained Baseline";
|
|
237
|
-
/** One H.264 profile at the level an export needs, as {@link videoEncoderProfiles} lists it. */
|
|
238
189
|
export interface VideoEncoderProfile {
|
|
239
190
|
readonly profile: AvcProfile;
|
|
240
|
-
/** The WebCodecs codec string, for example `avc1.4d0028`. */
|
|
241
191
|
readonly codecString: string;
|
|
242
192
|
}
|
|
243
|
-
/**
|
|
244
|
-
* A profile asked for before the one an export opens, and refused. Shaped like a native export's
|
|
245
|
-
* `videoEncoderFallbacks` entries; the codec is the same, only the profile differs.
|
|
246
|
-
*/
|
|
193
|
+
/** A profile asked for and refused before the one the export opened. */
|
|
247
194
|
export interface VideoEncoderFallback {
|
|
248
|
-
/** The codec string asked for. */
|
|
249
195
|
readonly encoder: string;
|
|
250
196
|
readonly profile: AvcProfile;
|
|
251
197
|
readonly reason: "unsupported";
|
|
@@ -253,21 +199,15 @@ export interface VideoEncoderFallback {
|
|
|
253
199
|
}
|
|
254
200
|
/** How a video track is encoded, as {@link canEncodeVideoTrack} chose it. */
|
|
255
201
|
export interface VideoTrackEncoding {
|
|
256
|
-
/**
|
|
257
|
-
* The codec string to open the encoder with ({@link MediabunnySinkOptions.videoCodecString}).
|
|
258
|
-
* Undefined for codecs other than H.264, which open with mediabunny's own.
|
|
259
|
-
*/
|
|
202
|
+
/** Undefined for codecs other than H.264, which open with mediabunny's own. */
|
|
260
203
|
readonly codecString?: string;
|
|
261
|
-
/** H.264: the profile `codecString` names. */
|
|
262
204
|
readonly profile?: AvcProfile;
|
|
263
|
-
/**
|
|
205
|
+
/** Profiles asked for first and refused; empty when High is encoded. */
|
|
264
206
|
readonly fallbacks: readonly VideoEncoderFallback[];
|
|
265
207
|
}
|
|
266
208
|
/**
|
|
267
|
-
* The profiles {@link canEncodeVideoTrack}
|
|
268
|
-
*
|
|
269
|
-
* encoder may take only the lower ones. Empty for the other codecs, which have one profile each
|
|
270
|
-
* (HEVC Main, VP9 profile 0, AV1 Main) at the level mediabunny picks.
|
|
209
|
+
* The H.264 profiles {@link canEncodeVideoTrack} tries, in order (High, Main, Constrained
|
|
210
|
+
* Baseline), at the needed level. Empty for other codecs.
|
|
271
211
|
*/
|
|
272
212
|
export declare function videoEncoderProfiles(codec: "avc" | "hevc" | "vp9" | "av1", options: {
|
|
273
213
|
readonly width: number;
|
|
@@ -276,36 +216,64 @@ export declare function videoEncoderProfiles(codec: "avc" | "hevc" | "vp9" | "av
|
|
|
276
216
|
}): readonly VideoEncoderProfile[];
|
|
277
217
|
/**
|
|
278
218
|
* How this browser encodes `codec` video at `width`x`height` with `rate`, or `null` when it does
|
|
279
|
-
* not
|
|
280
|
-
*
|
|
281
|
-
* encoder. H.264 is asked for in each of {@link videoEncoderProfiles} in turn, and the first one
|
|
282
|
-
* encoded is chosen: pass its `codecString` to the sink, and report its `fallbacks`.
|
|
219
|
+
* not. H.264 picks the first accepted of {@link videoEncoderProfiles}: pass its `codecString` to
|
|
220
|
+
* the sink and report its `fallbacks`.
|
|
283
221
|
*/
|
|
284
222
|
export declare function canEncodeVideoTrack(codec: "avc" | "hevc" | "vp9" | "av1", options: {
|
|
285
223
|
readonly width: number;
|
|
286
224
|
readonly height: number;
|
|
287
225
|
readonly rate: VideoRateControl;
|
|
288
226
|
}): Promise<VideoTrackEncoding | null>;
|
|
289
|
-
/**
|
|
290
|
-
export
|
|
227
|
+
/** Whether this browser has a software encoder for this configuration. */
|
|
228
|
+
export declare function canEncodeInSoftware(codec: "avc" | "hevc" | "vp9" | "av1", options: {
|
|
229
|
+
readonly width: number;
|
|
230
|
+
readonly height: number;
|
|
231
|
+
readonly rate: VideoRateControl;
|
|
232
|
+
readonly codecString?: string;
|
|
233
|
+
}): Promise<boolean>;
|
|
234
|
+
/**
|
|
235
|
+
* The 10-bit codec string for `codec`; `undefined` for H.264, which browsers do not encode at 10
|
|
236
|
+
* bits.
|
|
237
|
+
*/
|
|
238
|
+
export declare function tenBitCodecString(codec: "avc" | "hevc" | "vp9" | "av1"): string | undefined;
|
|
291
239
|
/**
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* per codec.
|
|
240
|
+
* Whether this browser encodes `codec` in `pixels` (alpha, 10 bits, or both). Encodes one real
|
|
241
|
+
* frame, since `isConfigSupported` can claim alpha that is then dropped.
|
|
295
242
|
*/
|
|
243
|
+
export declare function canEncodePixels(codec: "avc" | "hevc" | "vp9" | "av1", pixels: {
|
|
244
|
+
readonly bitDepth: 8 | 10;
|
|
245
|
+
readonly alpha: boolean;
|
|
246
|
+
}): Promise<boolean>;
|
|
247
|
+
export type VideoEncoderLatencyMode = "quality" | "realtime";
|
|
248
|
+
/** `"realtime"` only where a quality-mode encoder outputs nothing (Safari 27's H.264). */
|
|
296
249
|
export declare function videoEncoderLatencyMode(codec: "avc" | "hevc" | "vp9" | "av1"): Promise<VideoEncoderLatencyMode>;
|
|
250
|
+
/** {@link videoEncoderLatencyMode} with how it was measured. */
|
|
251
|
+
export declare function videoEncoderLatencyProbe(codec: "avc" | "hevc" | "vp9" | "av1"): Promise<VideoLatencyProbe>;
|
|
297
252
|
/**
|
|
298
|
-
* The rate
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* encoder takes none. Pass it to {@link MediabunnySink} as `audioSampleRate`, so every project
|
|
302
|
-
* rate exports where the browser encodes the codec at all.
|
|
253
|
+
* The rate to encode `codec` audio at for a project at `sampleRate`: the project rate if supported,
|
|
254
|
+
* else the nearest higher supported rate, else the nearest lower; `null` for none. Pass it to
|
|
255
|
+
* {@link MediabunnySink} as `audioSampleRate`.
|
|
303
256
|
*/
|
|
304
257
|
export declare function audioEncoderSampleRate(codec: "aac" | "opus", options: {
|
|
305
258
|
readonly sampleRate: number;
|
|
306
259
|
readonly numberOfChannels: number;
|
|
307
260
|
readonly bitrate: number;
|
|
308
261
|
}): Promise<number | null>;
|
|
262
|
+
/**
|
|
263
|
+
* The priming frames this browser's AAC-LC encoder puts before its input, which WebCodecs does not
|
|
264
|
+
* report. Measured once per configuration by finding an encoded noise burst; 0 on failure.
|
|
265
|
+
*/
|
|
266
|
+
export declare function aacEncoderDelay(options: {
|
|
267
|
+
readonly sampleRate: number;
|
|
268
|
+
readonly numberOfChannels: number;
|
|
269
|
+
readonly bitrate: number;
|
|
270
|
+
}): Promise<number>;
|
|
271
|
+
/** {@link aacEncoderDelay} with its outcome. Timeouts are retried once and never cached. */
|
|
272
|
+
export declare function aacEncoderPrimingProbe(options: {
|
|
273
|
+
readonly sampleRate: number;
|
|
274
|
+
readonly numberOfChannels: number;
|
|
275
|
+
readonly bitrate: number;
|
|
276
|
+
}): Promise<AacEncoderProbe>;
|
|
309
277
|
/** What a finished {@link MediabunnySink} produced. */
|
|
310
278
|
export type ExportOutput = {
|
|
311
279
|
readonly kind: "stream";
|
|
@@ -314,109 +282,77 @@ export type ExportOutput = {
|
|
|
314
282
|
readonly kind: "memory";
|
|
315
283
|
readonly buffer: ArrayBuffer;
|
|
316
284
|
};
|
|
317
|
-
/** The rate control the browser's encoder was actually configured with. */
|
|
318
285
|
export interface AppliedVideoRateControl {
|
|
319
|
-
/** `quantizer` when the constant-quantizer candidate was accepted. */
|
|
320
286
|
readonly bitrateMode: "constant" | "variable" | "quantizer";
|
|
321
|
-
/** The configured bitrate in bits per second, when the configuration set one. */
|
|
322
287
|
readonly bitrate?: number;
|
|
323
288
|
}
|
|
324
289
|
/**
|
|
325
|
-
* Optional mediabunny encoder/muxer implementing both public alpha2 sinks.
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* the video and `renderOfflineAudio` for the audio, at once or one after the other), give each its
|
|
330
|
-
* track instead, {@link MediabunnySink.videoTrack} and {@link MediabunnySink.audioTrack}: a
|
|
331
|
-
* runner's `finish` then ends its own track, and the file is finalized when every configured track
|
|
332
|
-
* has ended. Either track's `abort` discards the whole file, and the other runner's next write
|
|
333
|
-
* fails.
|
|
334
|
-
*
|
|
335
|
-
* The constructor throws `RangeError` when no track is configured, the container does not offer a
|
|
336
|
-
* codec (an `ExportFormatError`), a codec lacks its rate, a memory destination's `maxBytes` is not
|
|
337
|
-
* a positive safe integer, or `stallTimeoutMs` is out of range.
|
|
290
|
+
* Optional mediabunny encoder/muxer implementing both public alpha2 sinks. When two runners share
|
|
291
|
+
* the file, give each its own {@link MediabunnySink.videoTrack} or
|
|
292
|
+
* {@link MediabunnySink.audioTrack}; the file is finalized once every configured track has ended,
|
|
293
|
+
* and either `abort` discards it. The constructor throws `RangeError` for invalid options.
|
|
338
294
|
*/
|
|
339
295
|
export declare class MediabunnySink implements BrowserEncodeSink, BrowserAudioBlockSink {
|
|
340
296
|
#private;
|
|
341
297
|
constructor(options: MediabunnySinkOptions);
|
|
342
|
-
/**
|
|
298
|
+
/** Undefined until the sink has started. */
|
|
343
299
|
get videoLatencyMode(): VideoEncoderLatencyMode | undefined;
|
|
300
|
+
/** Undefined until the sink has started, and when `videoLatencyMode` was given. */
|
|
301
|
+
get videoLatencyProbe(): VideoLatencyProbe | undefined;
|
|
302
|
+
/** Undefined until the sink has started. */
|
|
303
|
+
get videoEncoderAcceleration(): "no-preference" | "prefer-software" | undefined;
|
|
304
|
+
/** Hand-over to encoded packet, including queueing in the encoder. */
|
|
305
|
+
get videoEncodeLatencyMs(): {
|
|
306
|
+
readonly mean: number;
|
|
307
|
+
readonly max: number;
|
|
308
|
+
readonly count: number;
|
|
309
|
+
};
|
|
310
|
+
/** Undefined before the first AAC block. */
|
|
311
|
+
get aacPrimingProbe(): AacEncoderProbe | undefined;
|
|
344
312
|
/**
|
|
345
|
-
* The video track as
|
|
346
|
-
* `finish` ends the video track and finalizes the file once every configured track has ended;
|
|
347
|
-
* its `abort` discards the file. Throws `RangeError` when no video track is configured.
|
|
313
|
+
* The video track as its own sink, for runners sharing the file. Throws `RangeError` if absent.
|
|
348
314
|
*/
|
|
349
315
|
get videoTrack(): BrowserEncodeSink;
|
|
350
|
-
/**
|
|
351
|
-
* The audio track as a sink of its own, for a runner that shares the file with another: see
|
|
352
|
-
* {@link videoTrack}. Throws `RangeError` when no audio track is configured.
|
|
353
|
-
*/
|
|
316
|
+
/** The audio track as its own sink; see {@link videoTrack}. Throws `RangeError` if absent. */
|
|
354
317
|
get audioTrack(): BrowserAudioBlockSink;
|
|
355
|
-
/**
|
|
356
|
-
* The rate control the browser's encoder was configured with, once the first frame has been
|
|
357
|
-
* written: whether the quantizer candidate was accepted or the bitrate fallback ran. Undefined
|
|
358
|
-
* before then.
|
|
359
|
-
*/
|
|
318
|
+
/** Undefined until the first frame has been written. */
|
|
360
319
|
get appliedVideoRateControl(): AppliedVideoRateControl | undefined;
|
|
361
|
-
/**
|
|
362
|
-
* The WebCodecs codec string the video encoder was configured with (for H.264, its profile and
|
|
363
|
-
* level), once the first frame has been written. Undefined before then.
|
|
364
|
-
*/
|
|
320
|
+
/** Undefined until the first frame has been written. */
|
|
365
321
|
get videoCodecString(): string | undefined;
|
|
366
322
|
/**
|
|
367
|
-
* Encodes one frame at
|
|
368
|
-
*
|
|
369
|
-
* destination has passed `maxBytes`, with `ENCODE_STALLED` when the encoder stalls, or when no
|
|
323
|
+
* Encodes one frame at `output.timeTicks` and always closes `output.frame`. Rejects with
|
|
324
|
+
* `RESOURCE_LIMIT` past a memory destination's `maxBytes`, with `ENCODE_STALLED`, or when no
|
|
370
325
|
* video track is configured.
|
|
371
326
|
*/
|
|
372
327
|
writeVideo(output: ExportedFrame): Promise<void>;
|
|
373
328
|
/**
|
|
374
|
-
* Encodes one
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
* rate and channel count. Rejects with `RESOURCE_LIMIT` once a memory destination has passed
|
|
378
|
-
* `maxBytes`, when no audio track is configured, when the block's channels differ in length, or
|
|
379
|
-
* (`RangeError`) when a block to convert does not continue the last or no `audioResampler` was
|
|
380
|
-
* given.
|
|
329
|
+
* Encodes one block at `block.startSample`, from the output's zero. Blocks that need rate
|
|
330
|
+
* conversion must be contiguous. Rejects with `RESOURCE_LIMIT`, when no audio track is
|
|
331
|
+
* configured, for ragged channels, or with `RangeError` for a gap or a missing `audioResampler`.
|
|
381
332
|
*/
|
|
382
333
|
writeAudio(block: BrowserAudioBlock): Promise<void>;
|
|
383
334
|
/**
|
|
384
|
-
* Finalizes the file and commits a stream destination;
|
|
385
|
-
*
|
|
386
|
-
* `ENCODE_STALLED` when the encoder stalls, and with what the muxer or the destination refused; a
|
|
387
|
-
* stream destination is then discarded.
|
|
335
|
+
* Finalizes the file and commits a stream destination; idempotent once resolved. Rejects with
|
|
336
|
+
* `RESOURCE_LIMIT`, `ENCODE_STALLED`, or the muxer's or destination's error, discarding a stream.
|
|
388
337
|
*/
|
|
389
338
|
finish(): Promise<void>;
|
|
390
|
-
/**
|
|
391
|
-
* Cancels the output and discards a stream destination, unless the file already finished.
|
|
392
|
-
* Rejects when the destination refuses to be discarded.
|
|
393
|
-
*/
|
|
339
|
+
/** Discards the output unless already finished; rejects if the destination refuses. */
|
|
394
340
|
abort(reason: Error): Promise<void>;
|
|
395
|
-
/**
|
|
396
|
-
* The finished output: its length for a stream, the bytes in memory. Null until {@link finish}
|
|
397
|
-
* resolves.
|
|
398
|
-
*/
|
|
341
|
+
/** Null until {@link finish} resolves. */
|
|
399
342
|
get output(): ExportOutput | null;
|
|
400
|
-
/** Bytes muxed so far: the file's length as written. */
|
|
401
343
|
get bytesWritten(): number;
|
|
402
344
|
}
|
|
403
|
-
/**
|
|
404
|
-
* Factory kept in the optional subpath so mediabunny is never loaded by core APIs. Audio needs
|
|
405
|
-
* `alpha2/wasm`'s resampler: see {@link MediabunnyAudioDecoder}.
|
|
406
|
-
*/
|
|
345
|
+
/** Kept in an optional subpath so core APIs never load mediabunny. */
|
|
407
346
|
export declare class MediabunnyAdapterFactory implements OptionalMediaAdapterFactory {
|
|
408
347
|
#private;
|
|
409
348
|
constructor(audioResampler?: AudioResamplerBinding);
|
|
410
349
|
/**
|
|
411
|
-
*
|
|
412
|
-
* `input` is a Blob, ArrayBuffer, or ArrayBuffer view, and as {@link MediabunnyVideoDecoder.open}
|
|
413
|
-
* does.
|
|
350
|
+
* Rejects with `TypeError` for an unsupported input, and as {@link MediabunnyVideoDecoder.open}.
|
|
414
351
|
*/
|
|
415
352
|
openVideo(sourceId: string, input: unknown): Promise<BrowserVideoDecoder>;
|
|
416
353
|
/**
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
* binding, and as {@link MediabunnyAudioDecoder.open} does.
|
|
354
|
+
* Rejects with `TypeError` for an unsupported input or a missing resampler binding, and as
|
|
355
|
+
* {@link MediabunnyAudioDecoder.open}.
|
|
420
356
|
*/
|
|
421
357
|
openAudio(sourceId: string, input: unknown): Promise<BrowserAudioDecoder>;
|
|
422
358
|
}
|