alpha2 0.4.6 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) 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 +28 -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 +108 -177
  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/generated/project-schema.d.ts +701 -485
  55. package/dist/generated/project-schema.js +55 -2
  56. package/dist/generated/project-shape.js +261 -16
  57. package/dist/geometry.d.ts +28 -34
  58. package/dist/geometry.js +18 -23
  59. package/dist/gpu-recovery.d.ts +92 -0
  60. package/dist/gpu-recovery.js +135 -0
  61. package/dist/hdr-frames.d.ts +82 -67
  62. package/dist/hdr-frames.js +112 -49
  63. package/dist/index.d.ts +4 -0
  64. package/dist/index.js +4 -0
  65. package/dist/json-text.d.ts +13 -23
  66. package/dist/json-text.js +10 -20
  67. package/dist/layout-values.d.ts +14 -22
  68. package/dist/layout-values.js +18 -21
  69. package/dist/layout.d.ts +48 -63
  70. package/dist/layout.js +37 -37
  71. package/dist/loudness.d.ts +27 -32
  72. package/dist/loudness.js +19 -23
  73. package/dist/media.d.ts +85 -237
  74. package/dist/media.js +133 -287
  75. package/dist/mediabunny.d.ts +166 -245
  76. package/dist/mediabunny.js +741 -580
  77. package/dist/physical-frames.d.ts +5 -17
  78. package/dist/physical-frames.js +4 -11
  79. package/dist/player.d.ts +56 -47
  80. package/dist/player.js +155 -40
  81. package/dist/presented-frames.d.ts +2 -7
  82. package/dist/presented-frames.js +3 -8
  83. package/dist/project.d.ts +73 -117
  84. package/dist/project.js +384 -445
  85. package/dist/rate-control.d.ts +9 -23
  86. package/dist/rate-control.js +7 -18
  87. package/dist/renderer-choice.d.ts +41 -0
  88. package/dist/renderer-choice.js +82 -0
  89. package/dist/repacked-bytes.d.ts +0 -2
  90. package/dist/repacked-bytes.js +2 -5
  91. package/dist/robustness.d.ts +25 -37
  92. package/dist/robustness.js +71 -54
  93. package/dist/sha256.d.ts +5 -13
  94. package/dist/sha256.js +9 -24
  95. package/dist/text.d.ts +97 -71
  96. package/dist/text.js +33 -70
  97. package/dist/video-frames.d.ts +7 -25
  98. package/dist/video-frames.js +12 -29
  99. package/dist/waveform.d.ts +5 -11
  100. package/dist/waveform.js +4 -9
  101. package/dist/worker-error.d.ts +5 -20
  102. package/dist/worker-error.js +8 -25
  103. package/dist/worker.d.ts +82 -95
  104. package/dist/worker.js +235 -143
  105. package/package.json +26 -2
  106. package/wasm/alpha2_audio_worklet.wasm +0 -0
  107. package/wasm/alpha2_extensions.d.ts +26 -47
  108. package/wasm/alpha2_extensions.js +26 -47
  109. package/wasm/alpha2_extensions_bg.wasm +0 -0
  110. package/wasm/alpha2_wasm.d.ts +460 -567
  111. package/wasm/alpha2_wasm.js +594 -594
  112. package/wasm/alpha2_wasm_bg.wasm +0 -0
  113. package/wasm/alpha2_wasm_bg.wasm.d.ts +15 -8
  114. package/wasm/rust-crate-licenses.md +2 -2
  115. package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
  116. package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
  117. package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
  118. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
  119. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
@@ -1,167 +1,144 @@
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";
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 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.
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 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.
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, 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:
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
- * 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.
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`. Positions are sample indexes: of the source at its rate, of
82
- * the output at the project's.
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>;
98
69
  /**
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}).
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>;
105
+ /**
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 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.
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, 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.
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
- * 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.
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, 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.
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
- * 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.
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
- /** The video encoder's latency mode; by default the one {@link videoEncoderLatencyMode} measures. */
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
- * How long the video encoder may hold frames without output before writes reject with
192
- * `ENCODE_STALLED` (default 10 s).
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
- /** The audio bitrate in bits per second, already resolved. Required with `audioCodec`. */
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
- * 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.
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
- /** H.264: the profiles asked for first and refused, in order; empty when High is encoded. */
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} 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.
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,32 +216,43 @@ 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, 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`.
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
- /** How a browser's video encoder is opened: see {@link videoEncoderLatencyMode}. */
290
- export type VideoEncoderLatencyMode = "quality" | "realtime";
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
- * 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.
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 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.
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`.
305
256
  */
306
257
  export declare function audioEncoderSampleRate(codec: "aac" | "opus", options: {
307
258
  readonly sampleRate: number;
@@ -309,18 +260,20 @@ export declare function audioEncoderSampleRate(codec: "aac" | "opus", options: {
309
260
  readonly bitrate: number;
310
261
  }): Promise<number | null>;
311
262
  /**
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.
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.
318
265
  */
319
266
  export declare function aacEncoderDelay(options: {
320
267
  readonly sampleRate: number;
321
268
  readonly numberOfChannels: number;
322
269
  readonly bitrate: number;
323
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>;
324
277
  /** What a finished {@link MediabunnySink} produced. */
325
278
  export type ExportOutput = {
326
279
  readonly kind: "stream";
@@ -329,109 +282,77 @@ export type ExportOutput = {
329
282
  readonly kind: "memory";
330
283
  readonly buffer: ArrayBuffer;
331
284
  };
332
- /** The rate control the browser's encoder was actually configured with. */
333
285
  export interface AppliedVideoRateControl {
334
- /** `quantizer` when the constant-quantizer candidate was accepted. */
335
286
  readonly bitrateMode: "constant" | "variable" | "quantizer";
336
- /** The configured bitrate in bits per second, when the configuration set one. */
337
287
  readonly bitrate?: number;
338
288
  }
339
289
  /**
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.
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.
353
294
  */
354
295
  export declare class MediabunnySink implements BrowserEncodeSink, BrowserAudioBlockSink {
355
296
  #private;
356
297
  constructor(options: MediabunnySinkOptions);
357
- /** The latency mode the video encoder was opened with; undefined until the sink has started. */
298
+ /** Undefined until the sink has started. */
358
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;
359
312
  /**
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.
313
+ * The video track as its own sink, for runners sharing the file. Throws `RangeError` if absent.
363
314
  */
364
315
  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
- */
316
+ /** The audio track as its own sink; see {@link videoTrack}. Throws `RangeError` if absent. */
369
317
  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
- */
318
+ /** Undefined until the first frame has been written. */
375
319
  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
- */
320
+ /** Undefined until the first frame has been written. */
380
321
  get videoCodecString(): string | undefined;
381
322
  /**
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
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
385
325
  * video track is configured.
386
326
  */
387
327
  writeVideo(output: ExportedFrame): Promise<void>;
388
328
  /**
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.
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`.
396
332
  */
397
333
  writeAudio(block: BrowserAudioBlock): Promise<void>;
398
334
  /**
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.
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.
403
337
  */
404
338
  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
- */
339
+ /** Discards the output unless already finished; rejects if the destination refuses. */
409
340
  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
- */
341
+ /** Null until {@link finish} resolves. */
414
342
  get output(): ExportOutput | null;
415
- /** Bytes muxed so far: the file's length as written. */
416
343
  get bytesWritten(): number;
417
344
  }
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
- */
345
+ /** Kept in an optional subpath so core APIs never load mediabunny. */
422
346
  export declare class MediabunnyAdapterFactory implements OptionalMediaAdapterFactory {
423
347
  #private;
424
348
  constructor(audioResampler?: AudioResamplerBinding);
425
349
  /**
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.
350
+ * Rejects with `TypeError` for an unsupported input, and as {@link MediabunnyVideoDecoder.open}.
429
351
  */
430
352
  openVideo(sourceId: string, input: unknown): Promise<BrowserVideoDecoder>;
431
353
  /**
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.
354
+ * Rejects with `TypeError` for an unsupported input or a missing resampler binding, and as
355
+ * {@link MediabunnyAudioDecoder.open}.
435
356
  */
436
357
  openAudio(sourceId: string, input: unknown): Promise<BrowserAudioDecoder>;
437
358
  }