alpha2 0.4.6 → 0.5.1

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