@napi-rs/webcodecs 0.0.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/LICENSE +21 -0
- package/README.md +398 -0
- package/index.d.ts +1299 -0
- package/index.js +772 -0
- package/package.json +150 -0
- package/polyfill.d.ts +33 -0
- package/polyfill.js +20 -0
- package/standard.d.ts +413 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,1299 @@
|
|
|
1
|
+
// Import types from standard.d.ts for use in index.d.ts
|
|
2
|
+
import type {
|
|
3
|
+
VideoDecoderConfig,
|
|
4
|
+
VideoEncoderConfig,
|
|
5
|
+
AudioEncoderConfig,
|
|
6
|
+
AudioDecoderConfig,
|
|
7
|
+
VideoFrameBufferInit,
|
|
8
|
+
EncodedVideoChunkInit,
|
|
9
|
+
EncodedAudioChunkInit,
|
|
10
|
+
AudioDataInit,
|
|
11
|
+
VideoColorSpaceInit,
|
|
12
|
+
ImageDecoderInit,
|
|
13
|
+
BufferSource,
|
|
14
|
+
AllowSharedBufferSource,
|
|
15
|
+
} from './standard'
|
|
16
|
+
|
|
17
|
+
// Re-export types from standard.d.ts
|
|
18
|
+
export {
|
|
19
|
+
// Config types
|
|
20
|
+
VideoDecoderConfig,
|
|
21
|
+
VideoEncoderConfig,
|
|
22
|
+
AudioEncoderConfig,
|
|
23
|
+
AudioDecoderConfig,
|
|
24
|
+
VideoFrameBufferInit,
|
|
25
|
+
// Init types (used by constructors)
|
|
26
|
+
EncodedVideoChunkInit,
|
|
27
|
+
EncodedAudioChunkInit,
|
|
28
|
+
AudioDataInit,
|
|
29
|
+
VideoColorSpaceInit,
|
|
30
|
+
ImageDecoderInit,
|
|
31
|
+
// Buffer types
|
|
32
|
+
BufferSource,
|
|
33
|
+
AllowSharedBufferSource,
|
|
34
|
+
} from './standard'
|
|
35
|
+
|
|
36
|
+
export type TypedArray =
|
|
37
|
+
| Int8Array
|
|
38
|
+
| Uint8Array
|
|
39
|
+
| Uint8ClampedArray
|
|
40
|
+
| Int16Array
|
|
41
|
+
| Uint16Array
|
|
42
|
+
| Int32Array
|
|
43
|
+
| Uint32Array
|
|
44
|
+
| Float32Array
|
|
45
|
+
| Float64Array
|
|
46
|
+
| BigInt64Array
|
|
47
|
+
| BigUint64Array
|
|
48
|
+
/**
|
|
49
|
+
* AudioData - represents uncompressed audio data
|
|
50
|
+
*
|
|
51
|
+
* This is a WebCodecs-compliant AudioData implementation backed by FFmpeg.
|
|
52
|
+
*/
|
|
53
|
+
export declare class AudioData {
|
|
54
|
+
/**
|
|
55
|
+
* Create a new AudioData (W3C WebCodecs spec)
|
|
56
|
+
* Per spec, the constructor takes a single init object containing all parameters including data
|
|
57
|
+
*/
|
|
58
|
+
constructor(init: import('./standard').AudioDataInit)
|
|
59
|
+
/** Get sample format */
|
|
60
|
+
get format(): AudioSampleFormat | null
|
|
61
|
+
/**
|
|
62
|
+
* Get sample rate in Hz (W3C spec uses float)
|
|
63
|
+
* Returns 0 after close per W3C spec
|
|
64
|
+
*/
|
|
65
|
+
get sampleRate(): number
|
|
66
|
+
/**
|
|
67
|
+
* Get number of frames (samples per channel)
|
|
68
|
+
* Returns 0 after close per W3C spec
|
|
69
|
+
*/
|
|
70
|
+
get numberOfFrames(): number
|
|
71
|
+
/**
|
|
72
|
+
* Get number of channels
|
|
73
|
+
* Returns 0 after close per W3C spec
|
|
74
|
+
*/
|
|
75
|
+
get numberOfChannels(): number
|
|
76
|
+
/**
|
|
77
|
+
* Get duration in microseconds
|
|
78
|
+
* Returns 0 after close per W3C spec
|
|
79
|
+
*/
|
|
80
|
+
get duration(): number
|
|
81
|
+
/**
|
|
82
|
+
* Get timestamp in microseconds
|
|
83
|
+
* Timestamp is preserved after close per W3C spec
|
|
84
|
+
*/
|
|
85
|
+
get timestamp(): number
|
|
86
|
+
/** Get whether this AudioData has been closed (W3C WebCodecs spec) */
|
|
87
|
+
get closed(): boolean
|
|
88
|
+
/**
|
|
89
|
+
* Get the number of planes in this AudioData (W3C WebCodecs spec)
|
|
90
|
+
* For interleaved formats: 1
|
|
91
|
+
* For planar formats: numberOfChannels
|
|
92
|
+
*/
|
|
93
|
+
get numberOfPlanes(): number
|
|
94
|
+
/**
|
|
95
|
+
* Get the buffer size required for copyTo (W3C WebCodecs spec)
|
|
96
|
+
* Note: options is REQUIRED per spec
|
|
97
|
+
*/
|
|
98
|
+
allocationSize(options: AudioDataCopyToOptions): number
|
|
99
|
+
/**
|
|
100
|
+
* Copy audio data to a buffer (W3C WebCodecs spec)
|
|
101
|
+
* Note: Per spec, this is SYNCHRONOUS and returns undefined
|
|
102
|
+
* Accepts AllowSharedBufferSource (any TypedArray, DataView, or ArrayBuffer)
|
|
103
|
+
*/
|
|
104
|
+
copyTo(destination: import('./standard').AllowSharedBufferSource, options: AudioDataCopyToOptions): void
|
|
105
|
+
/** Create a copy of this AudioData */
|
|
106
|
+
clone(): AudioData
|
|
107
|
+
/** Close and release resources */
|
|
108
|
+
close(): void
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* AudioDecoder - WebCodecs-compliant audio decoder
|
|
113
|
+
*
|
|
114
|
+
* Decodes EncodedAudioChunk objects into AudioData objects using FFmpeg.
|
|
115
|
+
*
|
|
116
|
+
* Per the WebCodecs spec, the constructor takes an init dictionary with callbacks.
|
|
117
|
+
*
|
|
118
|
+
* Example:
|
|
119
|
+
* ```javascript
|
|
120
|
+
* const decoder = new AudioDecoder({
|
|
121
|
+
* output: (data) => { console.log('decoded audio', data); },
|
|
122
|
+
* error: (e) => { console.error('error', e); }
|
|
123
|
+
* });
|
|
124
|
+
*
|
|
125
|
+
* decoder.configure({
|
|
126
|
+
* codec: 'opus',
|
|
127
|
+
* sampleRate: 48000,
|
|
128
|
+
* numberOfChannels: 2
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* decoder.decode(chunk);
|
|
132
|
+
* await decoder.flush();
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare class AudioDecoder {
|
|
136
|
+
/**
|
|
137
|
+
* Create a new AudioDecoder with init dictionary (per WebCodecs spec)
|
|
138
|
+
*
|
|
139
|
+
* @param init - Init dictionary containing output and error callbacks
|
|
140
|
+
*/
|
|
141
|
+
constructor(init: { output: (data: AudioData) => void; error: (error: Error) => void })
|
|
142
|
+
/** Get decoder state */
|
|
143
|
+
get state(): CodecState
|
|
144
|
+
/** Get number of pending decode operations (per WebCodecs spec) */
|
|
145
|
+
get decodeQueueSize(): number
|
|
146
|
+
/**
|
|
147
|
+
* Set the dequeue event handler (per WebCodecs spec)
|
|
148
|
+
*
|
|
149
|
+
* The dequeue event fires when decodeQueueSize decreases,
|
|
150
|
+
* allowing backpressure management.
|
|
151
|
+
*/
|
|
152
|
+
set ondequeue(callback?: (() => unknown) | undefined | null)
|
|
153
|
+
/** Get the dequeue event handler (per WebCodecs spec) */
|
|
154
|
+
get ondequeue(): (() => unknown) | null
|
|
155
|
+
/** Configure the decoder */
|
|
156
|
+
configure(config: AudioDecoderConfig): void
|
|
157
|
+
/** Decode an encoded audio chunk */
|
|
158
|
+
decode(chunk: EncodedAudioChunk): void
|
|
159
|
+
/**
|
|
160
|
+
* Flush the decoder
|
|
161
|
+
* Returns a Promise that resolves when flushing is complete
|
|
162
|
+
*
|
|
163
|
+
* Uses spawn_future_with_callback to check abort flag synchronously in the resolver.
|
|
164
|
+
* This ensures that if reset() is called from a callback, the abort flag is checked
|
|
165
|
+
* AFTER the callback returns, allowing flush() to return AbortError.
|
|
166
|
+
*/
|
|
167
|
+
flush(): Promise<void>
|
|
168
|
+
/** Reset the decoder */
|
|
169
|
+
reset(): void
|
|
170
|
+
/** Close the decoder */
|
|
171
|
+
close(): void
|
|
172
|
+
/**
|
|
173
|
+
* Check if a configuration is supported
|
|
174
|
+
* Returns a Promise that resolves with support information
|
|
175
|
+
*
|
|
176
|
+
* W3C WebCodecs spec: Rejects with TypeError for invalid configs,
|
|
177
|
+
* returns { supported: false } for valid but unsupported configs.
|
|
178
|
+
*/
|
|
179
|
+
static isConfigSupported(config: AudioDecoderConfig): Promise<AudioDecoderSupport>
|
|
180
|
+
/** Add an event listener for the specified event type */
|
|
181
|
+
addEventListener(
|
|
182
|
+
eventType: string,
|
|
183
|
+
callback: () => unknown,
|
|
184
|
+
options?: AudioDecoderAddEventListenerOptions | undefined | null,
|
|
185
|
+
): void
|
|
186
|
+
/** Remove an event listener for the specified event type */
|
|
187
|
+
removeEventListener(
|
|
188
|
+
eventType: string,
|
|
189
|
+
callback: () => unknown,
|
|
190
|
+
options?: AudioDecoderEventListenerOptions | undefined | null,
|
|
191
|
+
): void
|
|
192
|
+
/** Dispatch an event to all registered listeners */
|
|
193
|
+
dispatchEvent(eventType: string): boolean
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* AudioEncoder - WebCodecs-compliant audio encoder
|
|
198
|
+
*
|
|
199
|
+
* Encodes AudioData objects into EncodedAudioChunk objects using FFmpeg.
|
|
200
|
+
*
|
|
201
|
+
* Per the WebCodecs spec, the constructor takes an init dictionary with callbacks.
|
|
202
|
+
*
|
|
203
|
+
* Example:
|
|
204
|
+
* ```javascript
|
|
205
|
+
* const encoder = new AudioEncoder({
|
|
206
|
+
* output: (chunk, metadata) => { console.log('encoded chunk', chunk); },
|
|
207
|
+
* error: (e) => { console.error('error', e); }
|
|
208
|
+
* });
|
|
209
|
+
*
|
|
210
|
+
* encoder.configure({
|
|
211
|
+
* codec: 'opus',
|
|
212
|
+
* sampleRate: 48000,
|
|
213
|
+
* numberOfChannels: 2
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* encoder.encode(audioData);
|
|
217
|
+
* await encoder.flush();
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare class AudioEncoder {
|
|
221
|
+
/**
|
|
222
|
+
* Create a new AudioEncoder with init dictionary (per WebCodecs spec)
|
|
223
|
+
*
|
|
224
|
+
* @param init - Init dictionary containing output and error callbacks
|
|
225
|
+
*/
|
|
226
|
+
constructor(init: {
|
|
227
|
+
output: (chunk: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadata) => void
|
|
228
|
+
error: (error: Error) => void
|
|
229
|
+
})
|
|
230
|
+
/** Get encoder state */
|
|
231
|
+
get state(): CodecState
|
|
232
|
+
/** Get number of pending encode operations (per WebCodecs spec) */
|
|
233
|
+
get encodeQueueSize(): number
|
|
234
|
+
/**
|
|
235
|
+
* Set the dequeue event handler (per WebCodecs spec)
|
|
236
|
+
*
|
|
237
|
+
* The dequeue event fires when encodeQueueSize decreases,
|
|
238
|
+
* allowing backpressure management.
|
|
239
|
+
*/
|
|
240
|
+
set ondequeue(callback?: (() => unknown) | undefined | null)
|
|
241
|
+
/** Get the dequeue event handler (per WebCodecs spec) */
|
|
242
|
+
get ondequeue(): (() => unknown) | null
|
|
243
|
+
/** Configure the encoder */
|
|
244
|
+
configure(config: AudioEncoderConfig): void
|
|
245
|
+
/** Encode audio data */
|
|
246
|
+
encode(data: AudioData): void
|
|
247
|
+
/**
|
|
248
|
+
* Flush the encoder
|
|
249
|
+
* Returns a Promise that resolves when flushing is complete
|
|
250
|
+
*
|
|
251
|
+
* Uses spawn_future_with_callback to check abort flag synchronously in the resolver.
|
|
252
|
+
* This ensures that if reset() is called from a callback, the abort flag is checked
|
|
253
|
+
* AFTER the callback returns, allowing flush() to return AbortError.
|
|
254
|
+
*/
|
|
255
|
+
flush(): Promise<void>
|
|
256
|
+
/** Reset the encoder */
|
|
257
|
+
reset(): void
|
|
258
|
+
/** Close the encoder */
|
|
259
|
+
close(): void
|
|
260
|
+
/**
|
|
261
|
+
* Check if a configuration is supported
|
|
262
|
+
* Returns a Promise that resolves with support information
|
|
263
|
+
*
|
|
264
|
+
* W3C WebCodecs spec: Rejects with TypeError for invalid configs,
|
|
265
|
+
* returns { supported: false } for valid but unsupported configs.
|
|
266
|
+
*/
|
|
267
|
+
static isConfigSupported(config: AudioEncoderConfig): Promise<AudioEncoderSupport>
|
|
268
|
+
/**
|
|
269
|
+
* Add an event listener for the specified event type
|
|
270
|
+
* Uses separate RwLock to avoid blocking on encode operations
|
|
271
|
+
*/
|
|
272
|
+
addEventListener(
|
|
273
|
+
eventType: string,
|
|
274
|
+
callback: () => unknown,
|
|
275
|
+
options?: AudioEncoderAddEventListenerOptions | undefined | null,
|
|
276
|
+
): void
|
|
277
|
+
/** Remove an event listener for the specified event type */
|
|
278
|
+
removeEventListener(
|
|
279
|
+
eventType: string,
|
|
280
|
+
callback: () => unknown,
|
|
281
|
+
options?: AudioEncoderEventListenerOptions | undefined | null,
|
|
282
|
+
): void
|
|
283
|
+
/** Dispatch an event to all registered listeners */
|
|
284
|
+
dispatchEvent(eventType: string): boolean
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* DOMRectReadOnly - W3C WebCodecs spec compliant rect class
|
|
289
|
+
* Used for codedRect and visibleRect properties
|
|
290
|
+
*/
|
|
291
|
+
export declare class DOMRectReadOnly {
|
|
292
|
+
/** Create a new DOMRectReadOnly */
|
|
293
|
+
constructor(
|
|
294
|
+
x?: number | undefined | null,
|
|
295
|
+
y?: number | undefined | null,
|
|
296
|
+
width?: number | undefined | null,
|
|
297
|
+
height?: number | undefined | null,
|
|
298
|
+
)
|
|
299
|
+
/** X coordinate */
|
|
300
|
+
get x(): number
|
|
301
|
+
/** Y coordinate */
|
|
302
|
+
get y(): number
|
|
303
|
+
/** Width */
|
|
304
|
+
get width(): number
|
|
305
|
+
/** Height */
|
|
306
|
+
get height(): number
|
|
307
|
+
/** Top edge (same as y) */
|
|
308
|
+
get top(): number
|
|
309
|
+
/** Right edge (x + width) */
|
|
310
|
+
get right(): number
|
|
311
|
+
/** Bottom edge (y + height) */
|
|
312
|
+
get bottom(): number
|
|
313
|
+
/** Left edge (same as x) */
|
|
314
|
+
get left(): number
|
|
315
|
+
/** Convert to JSON (W3C spec uses toJSON) */
|
|
316
|
+
toJSON(): DOMRectInit
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* EncodedAudioChunk - represents encoded audio data
|
|
321
|
+
*
|
|
322
|
+
* This is a WebCodecs-compliant EncodedAudioChunk implementation.
|
|
323
|
+
*/
|
|
324
|
+
export declare class EncodedAudioChunk {
|
|
325
|
+
/** Create a new EncodedAudioChunk */
|
|
326
|
+
constructor(init: import('./standard').EncodedAudioChunkInit)
|
|
327
|
+
/** Get the chunk type */
|
|
328
|
+
get type(): EncodedAudioChunkType
|
|
329
|
+
/** Get the timestamp in microseconds */
|
|
330
|
+
get timestamp(): number
|
|
331
|
+
/** Get the duration in microseconds */
|
|
332
|
+
get duration(): number | null
|
|
333
|
+
/** Get the byte length of the encoded data */
|
|
334
|
+
get byteLength(): number
|
|
335
|
+
/**
|
|
336
|
+
* Copy the encoded data to a BufferSource
|
|
337
|
+
* W3C spec: throws TypeError if destination is too small
|
|
338
|
+
*/
|
|
339
|
+
copyTo(destination: import('./standard').BufferSource): void
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* EncodedVideoChunk - represents encoded video data
|
|
344
|
+
*
|
|
345
|
+
* This is a WebCodecs-compliant EncodedVideoChunk implementation.
|
|
346
|
+
*/
|
|
347
|
+
export declare class EncodedVideoChunk {
|
|
348
|
+
/** Create a new EncodedVideoChunk */
|
|
349
|
+
constructor(init: import('./standard').EncodedVideoChunkInit)
|
|
350
|
+
/** Get the chunk type */
|
|
351
|
+
get type(): EncodedVideoChunkType
|
|
352
|
+
/** Get the timestamp in microseconds */
|
|
353
|
+
get timestamp(): number
|
|
354
|
+
/** Get the duration in microseconds */
|
|
355
|
+
get duration(): number | null
|
|
356
|
+
/** Get the byte length of the encoded data */
|
|
357
|
+
get byteLength(): number
|
|
358
|
+
/**
|
|
359
|
+
* Copy the encoded data to a BufferSource
|
|
360
|
+
* W3C spec: throws TypeError if destination is too small
|
|
361
|
+
*/
|
|
362
|
+
copyTo(destination: import('./standard').BufferSource): void
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* ImageDecoder - WebCodecs-compliant image decoder
|
|
367
|
+
*
|
|
368
|
+
* Decodes image data (JPEG, PNG, WebP, GIF, BMP) into VideoFrame objects.
|
|
369
|
+
*
|
|
370
|
+
* Example:
|
|
371
|
+
* ```javascript
|
|
372
|
+
* const decoder = new ImageDecoder({
|
|
373
|
+
* data: imageBytes,
|
|
374
|
+
* type: 'image/png'
|
|
375
|
+
* });
|
|
376
|
+
*
|
|
377
|
+
* const result = await decoder.decode();
|
|
378
|
+
* const frame = result.image;
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
export declare class ImageDecoder {
|
|
382
|
+
/**
|
|
383
|
+
* Create a new ImageDecoder
|
|
384
|
+
* Supports both Uint8Array and ReadableStream as data source per W3C spec
|
|
385
|
+
*/
|
|
386
|
+
constructor(init: ImageDecoderInit)
|
|
387
|
+
/** Whether the data is fully buffered */
|
|
388
|
+
get complete(): boolean
|
|
389
|
+
/**
|
|
390
|
+
* Promise that resolves when data is fully loaded (per WebCodecs spec)
|
|
391
|
+
* Returns a new promise chained from the stored promise (allows multiple accesses)
|
|
392
|
+
*/
|
|
393
|
+
get completed(): Promise<undefined>
|
|
394
|
+
/** Get the MIME type */
|
|
395
|
+
get type(): string
|
|
396
|
+
/** Get the track list */
|
|
397
|
+
get tracks(): ImageTrackList
|
|
398
|
+
/** Decode the image (or a specific frame) */
|
|
399
|
+
decode(this: this, options?: ImageDecodeOptions | undefined | null): Promise<ImageDecodeResult>
|
|
400
|
+
/**
|
|
401
|
+
* Reset the decoder
|
|
402
|
+
* Clears cached frames - next decode() will re-decode from stored data
|
|
403
|
+
*/
|
|
404
|
+
reset(): void
|
|
405
|
+
/** Close the decoder */
|
|
406
|
+
close(): void
|
|
407
|
+
/** Whether this ImageDecoder has been closed (W3C WebCodecs spec) */
|
|
408
|
+
get closed(): boolean
|
|
409
|
+
/** Check if a MIME type is supported */
|
|
410
|
+
static isTypeSupported(mimeType: string): Promise<boolean>
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Image decode result
|
|
415
|
+
* Note: W3C spec defines this as a dictionary, but NAPI-RS doesn't support
|
|
416
|
+
* class instances in objects, so we use a class with the same properties.
|
|
417
|
+
*/
|
|
418
|
+
export declare class ImageDecodeResult {
|
|
419
|
+
/** Get the decoded image */
|
|
420
|
+
get image(): VideoFrame
|
|
421
|
+
/** Get whether the decode is complete */
|
|
422
|
+
get complete(): boolean
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Image track information (W3C spec - class with writable selected property) */
|
|
426
|
+
export declare class ImageTrack {
|
|
427
|
+
/** Whether this track is animated */
|
|
428
|
+
get animated(): boolean
|
|
429
|
+
/** Number of frames in this track */
|
|
430
|
+
get frameCount(): number
|
|
431
|
+
/** Number of times the animation repeats (Infinity for infinite) */
|
|
432
|
+
get repetitionCount(): number
|
|
433
|
+
/** Whether this track is currently selected (W3C spec - writable) */
|
|
434
|
+
get selected(): boolean
|
|
435
|
+
/**
|
|
436
|
+
* Set whether this track is selected (W3C spec - writable)
|
|
437
|
+
* Setting to true deselects all other tracks
|
|
438
|
+
*/
|
|
439
|
+
set selected(value: boolean)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** Image track list (W3C spec) */
|
|
443
|
+
export declare class ImageTrackList {
|
|
444
|
+
/** Get the number of tracks */
|
|
445
|
+
get length(): number
|
|
446
|
+
/** Get the currently selected track (if any) */
|
|
447
|
+
get selectedTrack(): ImageTrack | null
|
|
448
|
+
/** Get the selected track index (W3C spec: returns -1 if no track selected) */
|
|
449
|
+
get selectedIndex(): number
|
|
450
|
+
/** Promise that resolves when track metadata is available (W3C spec) */
|
|
451
|
+
get ready(): Promise<void>
|
|
452
|
+
/** Get track at specified index (W3C spec) */
|
|
453
|
+
item(index: number): ImageTrack | null
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** Video color space parameters (WebCodecs spec) - as a class per spec */
|
|
457
|
+
export declare class VideoColorSpace {
|
|
458
|
+
/** Create a new VideoColorSpace */
|
|
459
|
+
constructor(init?: import('./standard').VideoColorSpaceInit)
|
|
460
|
+
/** Get color primaries */
|
|
461
|
+
get primaries(): VideoColorPrimaries | null
|
|
462
|
+
/** Get transfer characteristics */
|
|
463
|
+
get transfer(): VideoTransferCharacteristics | null
|
|
464
|
+
/** Get matrix coefficients */
|
|
465
|
+
get matrix(): VideoMatrixCoefficients | null
|
|
466
|
+
/** Get full range flag */
|
|
467
|
+
get fullRange(): boolean | null
|
|
468
|
+
/**
|
|
469
|
+
* Convert to JSON-compatible object (W3C spec uses toJSON)
|
|
470
|
+
*
|
|
471
|
+
* Per W3C spec, toJSON() returns explicit null for unset fields.
|
|
472
|
+
*/
|
|
473
|
+
toJSON(): object
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* VideoDecoder - WebCodecs-compliant video decoder
|
|
478
|
+
*
|
|
479
|
+
* Decodes EncodedVideoChunk objects into VideoFrame objects using FFmpeg.
|
|
480
|
+
*
|
|
481
|
+
* Per the WebCodecs spec, the constructor takes an init dictionary with callbacks.
|
|
482
|
+
*
|
|
483
|
+
* Example:
|
|
484
|
+
* ```javascript
|
|
485
|
+
* const decoder = new VideoDecoder({
|
|
486
|
+
* output: (frame) => { console.log('decoded frame', frame); },
|
|
487
|
+
* error: (e) => { console.error('error', e); }
|
|
488
|
+
* });
|
|
489
|
+
*
|
|
490
|
+
* decoder.configure({
|
|
491
|
+
* codec: 'avc1.42001E'
|
|
492
|
+
* });
|
|
493
|
+
*
|
|
494
|
+
* decoder.decode(chunk);
|
|
495
|
+
* await decoder.flush();
|
|
496
|
+
* ```
|
|
497
|
+
*/
|
|
498
|
+
export declare class VideoDecoder {
|
|
499
|
+
/**
|
|
500
|
+
* Create a new VideoDecoder with init dictionary (per WebCodecs spec)
|
|
501
|
+
*
|
|
502
|
+
* @param init - Init dictionary containing output and error callbacks
|
|
503
|
+
*/
|
|
504
|
+
constructor(init: { output: (frame: VideoFrame) => void; error: (error: Error) => void })
|
|
505
|
+
/** Get decoder state */
|
|
506
|
+
get state(): CodecState
|
|
507
|
+
/** Get number of pending decode operations (per WebCodecs spec) */
|
|
508
|
+
get decodeQueueSize(): number
|
|
509
|
+
/**
|
|
510
|
+
* Set the dequeue event handler (per WebCodecs spec)
|
|
511
|
+
*
|
|
512
|
+
* The dequeue event fires when decodeQueueSize decreases,
|
|
513
|
+
* allowing backpressure management.
|
|
514
|
+
*/
|
|
515
|
+
set ondequeue(callback?: (() => unknown) | undefined | null)
|
|
516
|
+
/** Get the dequeue event handler (per WebCodecs spec) */
|
|
517
|
+
get ondequeue(): (() => unknown) | null
|
|
518
|
+
/**
|
|
519
|
+
* Configure the decoder
|
|
520
|
+
*
|
|
521
|
+
* Implements Chromium-aligned hardware acceleration behavior:
|
|
522
|
+
* - `prefer-hardware`: Try hardware only, report error if fails
|
|
523
|
+
* - `no-preference`: Try hardware first, silently fall back to software
|
|
524
|
+
* - `prefer-software`: Use software only
|
|
525
|
+
*/
|
|
526
|
+
configure(config: VideoDecoderConfig): void
|
|
527
|
+
/** Decode an encoded video chunk */
|
|
528
|
+
decode(chunk: EncodedVideoChunk): void
|
|
529
|
+
/**
|
|
530
|
+
* Flush the decoder
|
|
531
|
+
* Returns a Promise that resolves when flushing is complete
|
|
532
|
+
*
|
|
533
|
+
* Uses spawn_future_with_callback to check abort flag synchronously in the resolver.
|
|
534
|
+
* This ensures that if reset() is called from a callback, the abort flag is checked
|
|
535
|
+
* AFTER the callback returns, allowing flush() to return AbortError.
|
|
536
|
+
*/
|
|
537
|
+
flush(): Promise<void>
|
|
538
|
+
/** Reset the decoder */
|
|
539
|
+
reset(): void
|
|
540
|
+
/** Close the decoder */
|
|
541
|
+
close(): void
|
|
542
|
+
/**
|
|
543
|
+
* Check if a configuration is supported
|
|
544
|
+
* Returns a Promise that resolves with support information
|
|
545
|
+
*
|
|
546
|
+
* W3C WebCodecs spec: Throws TypeError for invalid configs,
|
|
547
|
+
* returns { supported: false } for valid but unsupported configs.
|
|
548
|
+
*/
|
|
549
|
+
static isConfigSupported(config: VideoDecoderConfig): Promise<VideoDecoderSupport>
|
|
550
|
+
/**
|
|
551
|
+
* Add an event listener for the specified event type
|
|
552
|
+
* Uses separate RwLock to avoid blocking on decode operations
|
|
553
|
+
*/
|
|
554
|
+
addEventListener(
|
|
555
|
+
eventType: string,
|
|
556
|
+
callback: () => unknown,
|
|
557
|
+
options?: VideoDecoderAddEventListenerOptions | undefined | null,
|
|
558
|
+
): void
|
|
559
|
+
/** Remove an event listener for the specified event type */
|
|
560
|
+
removeEventListener(
|
|
561
|
+
eventType: string,
|
|
562
|
+
callback: () => unknown,
|
|
563
|
+
options?: VideoDecoderEventListenerOptions | undefined | null,
|
|
564
|
+
): void
|
|
565
|
+
/** Dispatch an event to all registered listeners */
|
|
566
|
+
dispatchEvent(eventType: string): boolean
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* VideoEncoder - WebCodecs-compliant video encoder
|
|
571
|
+
*
|
|
572
|
+
* Encodes VideoFrame objects into EncodedVideoChunk objects using FFmpeg.
|
|
573
|
+
*
|
|
574
|
+
* Per the WebCodecs spec, the constructor takes an init dictionary with callbacks.
|
|
575
|
+
*
|
|
576
|
+
* Example:
|
|
577
|
+
* ```javascript
|
|
578
|
+
* const encoder = new VideoEncoder({
|
|
579
|
+
* output: (chunk, metadata) => { console.log('encoded chunk', chunk); },
|
|
580
|
+
* error: (e) => { console.error('error', e); }
|
|
581
|
+
* });
|
|
582
|
+
*
|
|
583
|
+
* encoder.configure({
|
|
584
|
+
* codec: 'avc1.42001E',
|
|
585
|
+
* width: 1920,
|
|
586
|
+
* height: 1080,
|
|
587
|
+
* bitrate: 5_000_000
|
|
588
|
+
* });
|
|
589
|
+
*
|
|
590
|
+
* encoder.encode(frame);
|
|
591
|
+
* await encoder.flush();
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
export declare class VideoEncoder {
|
|
595
|
+
/**
|
|
596
|
+
* Create a new VideoEncoder with init dictionary (per WebCodecs spec)
|
|
597
|
+
*
|
|
598
|
+
* @param init - Init dictionary containing output and error callbacks
|
|
599
|
+
*/
|
|
600
|
+
constructor(init: {
|
|
601
|
+
output: (chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadata) => void
|
|
602
|
+
error: (error: Error) => void
|
|
603
|
+
})
|
|
604
|
+
/** Get encoder state */
|
|
605
|
+
get state(): CodecState
|
|
606
|
+
/** Get number of pending encode operations (per WebCodecs spec) */
|
|
607
|
+
get encodeQueueSize(): number
|
|
608
|
+
/**
|
|
609
|
+
* Set the dequeue event handler (per WebCodecs spec)
|
|
610
|
+
*
|
|
611
|
+
* The dequeue event fires when encodeQueueSize decreases,
|
|
612
|
+
* allowing backpressure management.
|
|
613
|
+
*/
|
|
614
|
+
set ondequeue(callback?: (() => unknown) | undefined | null)
|
|
615
|
+
/** Get the dequeue event handler (per WebCodecs spec) */
|
|
616
|
+
get ondequeue(): (() => unknown) | null
|
|
617
|
+
/** Configure the encoder */
|
|
618
|
+
configure(config: VideoEncoderConfig): void
|
|
619
|
+
/** Encode a frame */
|
|
620
|
+
encode(frame: VideoFrame, options?: VideoEncoderEncodeOptions | undefined | null): void
|
|
621
|
+
/**
|
|
622
|
+
* Flush the encoder
|
|
623
|
+
* Returns a Promise that resolves when flushing is complete
|
|
624
|
+
*
|
|
625
|
+
* Uses spawn_future_with_callback to check abort flag synchronously in the resolver.
|
|
626
|
+
* This ensures that if reset() is called from a callback, the abort flag is checked
|
|
627
|
+
* AFTER the callback returns, allowing flush() to return AbortError.
|
|
628
|
+
*/
|
|
629
|
+
flush(): Promise<void>
|
|
630
|
+
/** Reset the encoder */
|
|
631
|
+
reset(): void
|
|
632
|
+
/** Close the encoder */
|
|
633
|
+
close(): void
|
|
634
|
+
/**
|
|
635
|
+
* Add an event listener for the specified event type
|
|
636
|
+
* Uses separate RwLock to avoid blocking on encode operations
|
|
637
|
+
*/
|
|
638
|
+
addEventListener(
|
|
639
|
+
eventType: string,
|
|
640
|
+
callback: () => unknown,
|
|
641
|
+
options?: AddEventListenerOptions | undefined | null,
|
|
642
|
+
): void
|
|
643
|
+
/** Remove an event listener for the specified event type */
|
|
644
|
+
removeEventListener(
|
|
645
|
+
eventType: string,
|
|
646
|
+
callback: () => unknown,
|
|
647
|
+
options?: EventListenerOptions | undefined | null,
|
|
648
|
+
): void
|
|
649
|
+
/** Dispatch an event to all registered listeners */
|
|
650
|
+
dispatchEvent(eventType: string): boolean
|
|
651
|
+
/**
|
|
652
|
+
* Check if a configuration is supported
|
|
653
|
+
* Returns a Promise that resolves with support information
|
|
654
|
+
*
|
|
655
|
+
* W3C WebCodecs spec: Throws TypeError for invalid configs,
|
|
656
|
+
* returns { supported: false } for valid but unsupported configs.
|
|
657
|
+
*
|
|
658
|
+
* Note: The config parameter is validated via FromNapiValue which throws
|
|
659
|
+
* native TypeError for missing required fields.
|
|
660
|
+
*/
|
|
661
|
+
static isConfigSupported(config: VideoEncoderConfig): Promise<VideoEncoderSupport>
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* VideoFrame - represents a frame of video
|
|
666
|
+
*
|
|
667
|
+
* This is a WebCodecs-compliant VideoFrame implementation backed by FFmpeg.
|
|
668
|
+
*/
|
|
669
|
+
export declare class VideoFrame {
|
|
670
|
+
/**
|
|
671
|
+
* Create a new VideoFrame from buffer data or another VideoFrame (W3C WebCodecs spec)
|
|
672
|
+
*
|
|
673
|
+
* Two constructor forms per W3C spec:
|
|
674
|
+
* 1. `new VideoFrame(data, init)` - from BufferSource with VideoFrameBufferInit
|
|
675
|
+
* 2. `new VideoFrame(source, init?)` - from another VideoFrame with optional VideoFrameInit
|
|
676
|
+
*/
|
|
677
|
+
constructor(source: VideoFrame | Uint8Array, init?: VideoFrameBufferInit | VideoFrameInit)
|
|
678
|
+
/** Get the pixel format */
|
|
679
|
+
get format(): VideoPixelFormat | null
|
|
680
|
+
/** Get the coded width in pixels (returns 0 when closed per W3C spec) */
|
|
681
|
+
get codedWidth(): number
|
|
682
|
+
/** Get the coded height in pixels (returns 0 when closed per W3C spec) */
|
|
683
|
+
get codedHeight(): number
|
|
684
|
+
/** Get the display width in pixels (returns 0 when closed per W3C spec) */
|
|
685
|
+
get displayWidth(): number
|
|
686
|
+
/** Get the display height in pixels (returns 0 when closed per W3C spec) */
|
|
687
|
+
get displayHeight(): number
|
|
688
|
+
/**
|
|
689
|
+
* Get the coded rect (the region containing valid pixel data)
|
|
690
|
+
* Returns DOMRectReadOnly per W3C WebCodecs spec
|
|
691
|
+
* Throws InvalidStateError if the VideoFrame is closed
|
|
692
|
+
*/
|
|
693
|
+
get codedRect(): DOMRectReadOnly
|
|
694
|
+
/**
|
|
695
|
+
* Get the visible rect (the region of coded data that should be displayed)
|
|
696
|
+
* Returns DOMRectReadOnly per W3C WebCodecs spec
|
|
697
|
+
* Throws InvalidStateError if the VideoFrame is closed
|
|
698
|
+
*/
|
|
699
|
+
get visibleRect(): DOMRectReadOnly
|
|
700
|
+
/**
|
|
701
|
+
* Get the presentation timestamp in microseconds
|
|
702
|
+
* Per W3C spec: "The timestamp getter steps are to return [[timestamp]]"
|
|
703
|
+
* The timestamp is preserved even after close() - only resource reference is cleared
|
|
704
|
+
*/
|
|
705
|
+
get timestamp(): number
|
|
706
|
+
/**
|
|
707
|
+
* Get the duration in microseconds
|
|
708
|
+
* Per W3C spec: "The duration getter steps are to return [[duration]]"
|
|
709
|
+
* The duration is preserved even after close() - only resource reference is cleared
|
|
710
|
+
*/
|
|
711
|
+
get duration(): number | null
|
|
712
|
+
/** Get the color space parameters */
|
|
713
|
+
get colorSpace(): VideoColorSpace
|
|
714
|
+
/** Get whether this VideoFrame has been closed (W3C WebCodecs spec) */
|
|
715
|
+
get closed(): boolean
|
|
716
|
+
/**
|
|
717
|
+
* Get the number of planes in this VideoFrame (W3C WebCodecs spec)
|
|
718
|
+
* The number depends on the pixel format:
|
|
719
|
+
* - RGBA, RGBX, BGRA, BGRX: 1 plane
|
|
720
|
+
* - NV12, NV21: 2 planes
|
|
721
|
+
* - I420, I422, I444: 3 planes
|
|
722
|
+
* - I420A, I422A, I444A: 4 planes
|
|
723
|
+
*/
|
|
724
|
+
get numberOfPlanes(): number
|
|
725
|
+
/** Get the rotation in degrees clockwise (0, 90, 180, 270) - W3C WebCodecs spec */
|
|
726
|
+
get rotation(): number
|
|
727
|
+
/** Get whether horizontal flip is applied - W3C WebCodecs spec */
|
|
728
|
+
get flip(): boolean
|
|
729
|
+
/**
|
|
730
|
+
* Get the metadata associated with this VideoFrame - W3C WebCodecs spec
|
|
731
|
+
* Currently returns an empty metadata object as members are defined in the registry
|
|
732
|
+
*/
|
|
733
|
+
metadata(): VideoFrameMetadata
|
|
734
|
+
/** Calculate the allocation size needed for copyTo */
|
|
735
|
+
allocationSize(options?: VideoFrameCopyToOptions | undefined | null): number
|
|
736
|
+
/**
|
|
737
|
+
* Copy frame data to a Uint8Array
|
|
738
|
+
*
|
|
739
|
+
* Returns a Promise that resolves with an array of PlaneLayout objects.
|
|
740
|
+
* Options can specify target format and rect for cropped copy.
|
|
741
|
+
*/
|
|
742
|
+
copyTo(destination: Uint8Array, options?: VideoFrameCopyToOptions | undefined | null): Promise<Array<PlaneLayout>>
|
|
743
|
+
/** Clone this VideoFrame */
|
|
744
|
+
clone(): VideoFrame
|
|
745
|
+
/**
|
|
746
|
+
* Close and release resources
|
|
747
|
+
* Per W3C spec "Close VideoFrame" algorithm:
|
|
748
|
+
* 1. Assign null to frame's [[resource reference]]
|
|
749
|
+
* 2. Assign true to frame's [[Detached]]
|
|
750
|
+
* Note: Metadata (timestamp, duration, etc.) remains accessible after close
|
|
751
|
+
*/
|
|
752
|
+
close(): void
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/** AAC bitstream format (W3C WebCodecs AAC Registration) */
|
|
756
|
+
export type AacBitstreamFormat = /** Raw AAC frames - metadata in description */
|
|
757
|
+
| 'aac'
|
|
758
|
+
/** ADTS frames - metadata in each frame */
|
|
759
|
+
| 'adts'
|
|
760
|
+
|
|
761
|
+
/** AAC encoder configuration (W3C WebCodecs AAC Registration) */
|
|
762
|
+
export interface AacEncoderConfig {
|
|
763
|
+
/** Bitstream format (default: "aac") */
|
|
764
|
+
format?: AacBitstreamFormat
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/** Options for addEventListener (W3C DOM spec) */
|
|
768
|
+
export interface AddEventListenerOptions {
|
|
769
|
+
capture?: boolean
|
|
770
|
+
once?: boolean
|
|
771
|
+
passive?: boolean
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Alpha channel handling option (W3C WebCodecs spec)
|
|
776
|
+
* Default is "discard" per spec
|
|
777
|
+
*/
|
|
778
|
+
export type AlphaOption = /** Keep alpha channel if present */
|
|
779
|
+
| 'keep'
|
|
780
|
+
/** Discard alpha channel (default per W3C spec) */
|
|
781
|
+
| 'discard'
|
|
782
|
+
|
|
783
|
+
/** Options for copyTo operation */
|
|
784
|
+
export interface AudioDataCopyToOptions {
|
|
785
|
+
/** The index of the audio plane to copy */
|
|
786
|
+
planeIndex: number
|
|
787
|
+
/** The offset in frames to start copying from (optional) */
|
|
788
|
+
frameOffset?: number
|
|
789
|
+
/** The number of frames to copy (optional, defaults to all remaining) */
|
|
790
|
+
frameCount?: number
|
|
791
|
+
/** Target format for conversion (optional) */
|
|
792
|
+
format?: AudioSampleFormat
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/** Options for addEventListener (W3C DOM spec) */
|
|
796
|
+
export interface AudioDecoderAddEventListenerOptions {
|
|
797
|
+
capture?: boolean
|
|
798
|
+
once?: boolean
|
|
799
|
+
passive?: boolean
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/** Decoder configuration output (for passing to decoder) */
|
|
803
|
+
export interface AudioDecoderConfigOutput {
|
|
804
|
+
/** Codec string */
|
|
805
|
+
codec: string
|
|
806
|
+
/** Sample rate - W3C spec uses float */
|
|
807
|
+
sampleRate?: number
|
|
808
|
+
/** Number of channels */
|
|
809
|
+
numberOfChannels?: number
|
|
810
|
+
/** Codec description (e.g., AudioSpecificConfig for AAC) - Uint8Array per spec */
|
|
811
|
+
description?: Uint8Array
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/** Options for removeEventListener (W3C DOM spec) */
|
|
815
|
+
export interface AudioDecoderEventListenerOptions {
|
|
816
|
+
capture?: boolean
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** Audio decoder support information */
|
|
820
|
+
export interface AudioDecoderSupport {
|
|
821
|
+
/** Whether the configuration is supported */
|
|
822
|
+
supported: boolean
|
|
823
|
+
/** The configuration that was tested */
|
|
824
|
+
config: AudioDecoderConfig
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/** Options for addEventListener (W3C DOM spec) */
|
|
828
|
+
export interface AudioEncoderAddEventListenerOptions {
|
|
829
|
+
capture?: boolean
|
|
830
|
+
once?: boolean
|
|
831
|
+
passive?: boolean
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/** Encode options for audio */
|
|
835
|
+
export interface AudioEncoderEncodeOptions {}
|
|
836
|
+
|
|
837
|
+
/** Options for removeEventListener (W3C DOM spec) */
|
|
838
|
+
export interface AudioEncoderEventListenerOptions {
|
|
839
|
+
capture?: boolean
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/** Audio encoder support information */
|
|
843
|
+
export interface AudioEncoderSupport {
|
|
844
|
+
/** Whether the configuration is supported */
|
|
845
|
+
supported: boolean
|
|
846
|
+
/** The configuration that was tested */
|
|
847
|
+
config: AudioEncoderConfig
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** Audio sample format (WebCodecs spec) */
|
|
851
|
+
export type AudioSampleFormat = /** Unsigned 8-bit integer samples| interleaved */
|
|
852
|
+
| 'u8'
|
|
853
|
+
/** Signed 16-bit integer samples| interleaved */
|
|
854
|
+
| 's16'
|
|
855
|
+
/** Signed 32-bit integer samples| interleaved */
|
|
856
|
+
| 's32'
|
|
857
|
+
/** 32-bit float samples| interleaved */
|
|
858
|
+
| 'f32'
|
|
859
|
+
/** Unsigned 8-bit integer samples| planar */
|
|
860
|
+
| 'u8-planar'
|
|
861
|
+
/** Signed 16-bit integer samples| planar */
|
|
862
|
+
| 's16-planar'
|
|
863
|
+
/** Signed 32-bit integer samples| planar */
|
|
864
|
+
| 's32-planar'
|
|
865
|
+
/** 32-bit float samples| planar */
|
|
866
|
+
| 'f32-planar'
|
|
867
|
+
|
|
868
|
+
/** AVC (H.264) bitstream format (W3C WebCodecs AVC Registration) */
|
|
869
|
+
export type AvcBitstreamFormat = /** AVC format with parameter sets in description (ISO 14496-15) */
|
|
870
|
+
| 'avc'
|
|
871
|
+
/** Annex B format with parameter sets in bitstream */
|
|
872
|
+
| 'annexb'
|
|
873
|
+
|
|
874
|
+
/** AVC (H.264) encoder configuration (W3C WebCodecs AVC Registration) */
|
|
875
|
+
export interface AvcEncoderConfig {
|
|
876
|
+
/** Bitstream format (default: "avc") */
|
|
877
|
+
format?: AvcBitstreamFormat
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/** Bitrate mode for audio encoding (W3C WebCodecs spec) */
|
|
881
|
+
export type BitrateMode = /** Variable bitrate (default) */
|
|
882
|
+
| 'variable'
|
|
883
|
+
/** Constant bitrate */
|
|
884
|
+
| 'constant'
|
|
885
|
+
|
|
886
|
+
/** Encoder state per WebCodecs spec */
|
|
887
|
+
export type CodecState = /** Encoder not configured */
|
|
888
|
+
| 'unconfigured'
|
|
889
|
+
/** Encoder configured and ready */
|
|
890
|
+
| 'configured'
|
|
891
|
+
/** Encoder closed */
|
|
892
|
+
| 'closed'
|
|
893
|
+
|
|
894
|
+
/** ColorSpaceConversion for ImageDecoder (W3C WebCodecs spec) */
|
|
895
|
+
export type ColorSpaceConversion = /** Apply default color space conversion (spec default) */
|
|
896
|
+
| 'default'
|
|
897
|
+
/** No color space conversion */
|
|
898
|
+
| 'none'
|
|
899
|
+
|
|
900
|
+
/** DOMRectInit for specifying regions */
|
|
901
|
+
export interface DOMRectInit {
|
|
902
|
+
x?: number
|
|
903
|
+
y?: number
|
|
904
|
+
width?: number
|
|
905
|
+
height?: number
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/** Output callback metadata for audio */
|
|
909
|
+
export interface EncodedAudioChunkMetadata {
|
|
910
|
+
/** Decoder configuration for this chunk */
|
|
911
|
+
decoderConfig?: AudioDecoderConfigOutput
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/** Type of encoded audio chunk */
|
|
915
|
+
export type EncodedAudioChunkType = /** Key chunk - can be decoded independently */
|
|
916
|
+
| 'key'
|
|
917
|
+
/** Delta chunk - depends on previous chunks */
|
|
918
|
+
| 'delta'
|
|
919
|
+
|
|
920
|
+
/** Output callback metadata per WebCodecs spec */
|
|
921
|
+
export interface EncodedVideoChunkMetadata {
|
|
922
|
+
/** Decoder configuration for this chunk (only present for keyframes) */
|
|
923
|
+
decoderConfig?: VideoDecoderConfigOutput
|
|
924
|
+
/** SVC metadata (temporal layer info) */
|
|
925
|
+
svc?: SvcOutputMetadata
|
|
926
|
+
/** Alpha channel side data (when alpha option is "keep") */
|
|
927
|
+
alphaSideData?: Uint8Array
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** Type of encoded video chunk */
|
|
931
|
+
export type EncodedVideoChunkType = /** Keyframe - can be decoded independently */
|
|
932
|
+
| 'key'
|
|
933
|
+
/** Delta frame - depends on previous frames */
|
|
934
|
+
| 'delta'
|
|
935
|
+
|
|
936
|
+
/** Options for removeEventListener (W3C DOM spec) */
|
|
937
|
+
export interface EventListenerOptions {
|
|
938
|
+
capture?: boolean
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** FLAC encoder configuration (W3C WebCodecs FLAC Registration) */
|
|
942
|
+
export interface FlacEncoderConfig {
|
|
943
|
+
/** Block size (0 = auto, default: 0) */
|
|
944
|
+
blockSize?: number
|
|
945
|
+
/** Compression level 0-8 (default: 5) */
|
|
946
|
+
compressLevel?: number
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/** Get available hardware accelerators (only those that can be used) */
|
|
950
|
+
export declare function getAvailableHardwareAccelerators(): Array<string>
|
|
951
|
+
|
|
952
|
+
/** Get list of all known hardware accelerators and their availability */
|
|
953
|
+
export declare function getHardwareAccelerators(): Array<HardwareAccelerator>
|
|
954
|
+
|
|
955
|
+
/** Get the preferred hardware accelerator for the current platform */
|
|
956
|
+
export declare function getPreferredHardwareAccelerator(): string | null
|
|
957
|
+
|
|
958
|
+
/** Hardware acceleration preference (W3C WebCodecs spec) */
|
|
959
|
+
export type HardwareAcceleration = /** No preference - may use hardware or software */
|
|
960
|
+
| 'no-preference'
|
|
961
|
+
/** Prefer hardware acceleration */
|
|
962
|
+
| 'prefer-hardware'
|
|
963
|
+
/** Prefer software implementation */
|
|
964
|
+
| 'prefer-software'
|
|
965
|
+
|
|
966
|
+
/** Hardware accelerator information */
|
|
967
|
+
export interface HardwareAccelerator {
|
|
968
|
+
/** Internal name (e.g., "videotoolbox", "cuda", "vaapi") */
|
|
969
|
+
name: string
|
|
970
|
+
/** Human-readable description */
|
|
971
|
+
description: string
|
|
972
|
+
/** Whether this accelerator is available on this system */
|
|
973
|
+
available: boolean
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/** HEVC (H.265) bitstream format (W3C WebCodecs HEVC Registration) */
|
|
977
|
+
export type HevcBitstreamFormat = /** HEVC format with parameter sets in description (ISO 14496-15) */
|
|
978
|
+
| 'hevc'
|
|
979
|
+
/** Annex B format with parameter sets in bitstream */
|
|
980
|
+
| 'annexb'
|
|
981
|
+
|
|
982
|
+
/** HEVC (H.265) encoder configuration (W3C WebCodecs HEVC Registration) */
|
|
983
|
+
export interface HevcEncoderConfig {
|
|
984
|
+
/** Bitstream format (default: "hevc") */
|
|
985
|
+
format?: HevcBitstreamFormat
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/** Image decode options */
|
|
989
|
+
export interface ImageDecodeOptions {
|
|
990
|
+
/** Frame index to decode (for animated images) */
|
|
991
|
+
frameIndex?: number
|
|
992
|
+
/** Whether to only decode complete frames */
|
|
993
|
+
completeFramesOnly?: boolean
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/** Check if a specific hardware accelerator is available */
|
|
997
|
+
export declare function isHardwareAcceleratorAvailable(name: string): boolean
|
|
998
|
+
|
|
999
|
+
/** Latency mode for video encoding (W3C WebCodecs spec) */
|
|
1000
|
+
export type LatencyMode = /** Optimize for quality (default) */
|
|
1001
|
+
| 'quality'
|
|
1002
|
+
/** Optimize for low latency */
|
|
1003
|
+
| 'realtime'
|
|
1004
|
+
|
|
1005
|
+
/** Opus application mode (W3C WebCodecs Opus Registration) */
|
|
1006
|
+
export type OpusApplication = /** Optimize for VoIP (speech intelligibility) */
|
|
1007
|
+
| 'voip'
|
|
1008
|
+
/** Optimize for audio fidelity (default) */
|
|
1009
|
+
| 'audio'
|
|
1010
|
+
/** Minimize coding delay */
|
|
1011
|
+
| 'lowdelay'
|
|
1012
|
+
|
|
1013
|
+
/** Opus bitstream format (W3C WebCodecs Opus Registration) */
|
|
1014
|
+
export type OpusBitstreamFormat = /** Opus packets (RFC 6716) - no metadata needed for decoding */
|
|
1015
|
+
| 'opus'
|
|
1016
|
+
/** Ogg encapsulation (RFC 7845) - metadata in description */
|
|
1017
|
+
| 'ogg'
|
|
1018
|
+
|
|
1019
|
+
/** Opus encoder configuration (W3C WebCodecs Opus Registration) */
|
|
1020
|
+
export interface OpusEncoderConfig {
|
|
1021
|
+
/** Bitstream format (default: "opus") */
|
|
1022
|
+
format?: OpusBitstreamFormat
|
|
1023
|
+
/** Signal type hint (default: "auto") */
|
|
1024
|
+
signal?: OpusSignal
|
|
1025
|
+
/** Application mode (default: "audio") */
|
|
1026
|
+
application?: OpusApplication
|
|
1027
|
+
/**
|
|
1028
|
+
* Frame duration in microseconds (default: 20000)
|
|
1029
|
+
* Note: W3C spec uses unsigned long long, but NAPI-RS uses f64 for JS compatibility
|
|
1030
|
+
*/
|
|
1031
|
+
frameDuration?: number
|
|
1032
|
+
/** Encoder complexity 0-10 (default: 5 mobile, 9 desktop) */
|
|
1033
|
+
complexity?: number
|
|
1034
|
+
/** Expected packet loss percentage 0-100 (default: 0) */
|
|
1035
|
+
packetlossperc?: number
|
|
1036
|
+
/** Enable in-band FEC (default: false) */
|
|
1037
|
+
useinbandfec?: boolean
|
|
1038
|
+
/** Enable DTX (default: false) */
|
|
1039
|
+
usedtx?: boolean
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/** Opus signal type hint (W3C WebCodecs Opus Registration) */
|
|
1043
|
+
export type OpusSignal = /** Auto-detect signal type */
|
|
1044
|
+
| 'auto'
|
|
1045
|
+
/** Music signal */
|
|
1046
|
+
| 'music'
|
|
1047
|
+
/** Voice/speech signal */
|
|
1048
|
+
| 'voice'
|
|
1049
|
+
|
|
1050
|
+
/** Layout information for a single plane per WebCodecs spec */
|
|
1051
|
+
export interface PlaneLayout {
|
|
1052
|
+
/** Byte offset from the start of the buffer to the start of the plane */
|
|
1053
|
+
offset: number
|
|
1054
|
+
/** Number of bytes per row (stride) */
|
|
1055
|
+
stride: number
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* Reset all hardware fallback state.
|
|
1060
|
+
*
|
|
1061
|
+
* This clears all failure counts and re-enables hardware acceleration.
|
|
1062
|
+
* Useful for:
|
|
1063
|
+
* - Test isolation (call in beforeEach)
|
|
1064
|
+
* - Error recovery after fixing hardware issues
|
|
1065
|
+
* - Manual reset by users
|
|
1066
|
+
*/
|
|
1067
|
+
export declare function resetHardwareFallbackState(): void
|
|
1068
|
+
|
|
1069
|
+
/** SVC (Scalable Video Coding) output metadata (W3C WebCodecs spec) */
|
|
1070
|
+
export interface SvcOutputMetadata {
|
|
1071
|
+
/** Temporal layer ID for this frame */
|
|
1072
|
+
temporalLayerId?: number
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/** Video color primaries (W3C WebCodecs spec) */
|
|
1076
|
+
export type VideoColorPrimaries = /** BT.709 / sRGB primaries */
|
|
1077
|
+
| 'bt709'
|
|
1078
|
+
/** BT.470 BG (PAL) */
|
|
1079
|
+
| 'bt470bg'
|
|
1080
|
+
/** SMPTE 170M (NTSC) */
|
|
1081
|
+
| 'smpte170m'
|
|
1082
|
+
/** BT.2020 (UHD) */
|
|
1083
|
+
| 'bt2020'
|
|
1084
|
+
/** SMPTE 432 (DCI-P3) */
|
|
1085
|
+
| 'smpte432'
|
|
1086
|
+
|
|
1087
|
+
/** Options for addEventListener (W3C DOM spec) */
|
|
1088
|
+
export interface VideoDecoderAddEventListenerOptions {
|
|
1089
|
+
capture?: boolean
|
|
1090
|
+
once?: boolean
|
|
1091
|
+
passive?: boolean
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/** Decoder configuration output (for passing to decoder) */
|
|
1095
|
+
export interface VideoDecoderConfigOutput {
|
|
1096
|
+
/** Codec string */
|
|
1097
|
+
codec: string
|
|
1098
|
+
/** Coded width */
|
|
1099
|
+
codedWidth?: number
|
|
1100
|
+
/** Coded height */
|
|
1101
|
+
codedHeight?: number
|
|
1102
|
+
/** Codec description (e.g., avcC for H.264) - Uint8Array per spec */
|
|
1103
|
+
description?: Uint8Array
|
|
1104
|
+
/** Color space information for the video content */
|
|
1105
|
+
colorSpace?: VideoColorSpaceInit
|
|
1106
|
+
/** Display aspect width (for non-square pixels) */
|
|
1107
|
+
displayAspectWidth?: number
|
|
1108
|
+
/** Display aspect height (for non-square pixels) */
|
|
1109
|
+
displayAspectHeight?: number
|
|
1110
|
+
/** Rotation in degrees clockwise (0, 90, 180, 270) per W3C spec */
|
|
1111
|
+
rotation?: number
|
|
1112
|
+
/** Horizontal flip per W3C spec */
|
|
1113
|
+
flip?: boolean
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/** Options for removeEventListener (W3C DOM spec) */
|
|
1117
|
+
export interface VideoDecoderEventListenerOptions {
|
|
1118
|
+
capture?: boolean
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/** Result of isConfigSupported per WebCodecs spec */
|
|
1122
|
+
export interface VideoDecoderSupport {
|
|
1123
|
+
/** Whether the configuration is supported */
|
|
1124
|
+
supported: boolean
|
|
1125
|
+
/** The configuration that was checked */
|
|
1126
|
+
config: VideoDecoderConfig
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/** Bitrate mode for video encoding (W3C WebCodecs spec) */
|
|
1130
|
+
export type VideoEncoderBitrateMode = /** Variable bitrate (default) */
|
|
1131
|
+
| 'variable'
|
|
1132
|
+
/** Constant bitrate */
|
|
1133
|
+
| 'constant'
|
|
1134
|
+
/** Use quantizer parameter from codec-specific options */
|
|
1135
|
+
| 'quantizer'
|
|
1136
|
+
|
|
1137
|
+
/** Encode options per WebCodecs spec */
|
|
1138
|
+
export interface VideoEncoderEncodeOptions {
|
|
1139
|
+
/** Force this frame to be a keyframe */
|
|
1140
|
+
keyFrame?: boolean
|
|
1141
|
+
/** AVC (H.264) codec-specific options */
|
|
1142
|
+
avc?: VideoEncoderEncodeOptionsForAvc
|
|
1143
|
+
/** HEVC (H.265) codec-specific options */
|
|
1144
|
+
hevc?: VideoEncoderEncodeOptionsForHevc
|
|
1145
|
+
/** VP9 codec-specific options */
|
|
1146
|
+
vp9?: VideoEncoderEncodeOptionsForVp9
|
|
1147
|
+
/** AV1 codec-specific options */
|
|
1148
|
+
av1?: VideoEncoderEncodeOptionsForAv1
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/** AV1 encode options (W3C WebCodecs AV1 Registration) */
|
|
1152
|
+
export interface VideoEncoderEncodeOptionsForAv1 {
|
|
1153
|
+
/** Per-frame quantizer (0-63, lower = higher quality) */
|
|
1154
|
+
quantizer?: number
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/** AVC (H.264) encode options (W3C WebCodecs AVC Registration) */
|
|
1158
|
+
export interface VideoEncoderEncodeOptionsForAvc {
|
|
1159
|
+
/** Per-frame quantizer (0-51, lower = higher quality) */
|
|
1160
|
+
quantizer?: number
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/** HEVC (H.265) encode options (W3C WebCodecs HEVC Registration) */
|
|
1164
|
+
export interface VideoEncoderEncodeOptionsForHevc {
|
|
1165
|
+
/** Per-frame quantizer (0-51, lower = higher quality) */
|
|
1166
|
+
quantizer?: number
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
/** VP9 encode options (W3C WebCodecs VP9 Registration) */
|
|
1170
|
+
export interface VideoEncoderEncodeOptionsForVp9 {
|
|
1171
|
+
/** Per-frame quantizer (0-63, lower = higher quality) */
|
|
1172
|
+
quantizer?: number
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/** Result of isConfigSupported per WebCodecs spec */
|
|
1176
|
+
export interface VideoEncoderSupport {
|
|
1177
|
+
/** Whether the configuration is supported */
|
|
1178
|
+
supported: boolean
|
|
1179
|
+
/** The configuration that was checked */
|
|
1180
|
+
config: VideoEncoderConfig
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
/** Options for copyTo operation */
|
|
1184
|
+
export interface VideoFrameCopyToOptions {
|
|
1185
|
+
/** Target pixel format (for format conversion) */
|
|
1186
|
+
format?: VideoPixelFormat
|
|
1187
|
+
/** Region to copy (not yet implemented) */
|
|
1188
|
+
rect?: DOMRectInit
|
|
1189
|
+
/** Layout for output planes */
|
|
1190
|
+
layout?: Array<PlaneLayout>
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/** Options for creating a VideoFrame from an image source (VideoFrameInit per spec) */
|
|
1194
|
+
export interface VideoFrameInit {
|
|
1195
|
+
/** Timestamp in microseconds (required per spec when creating from VideoFrame) */
|
|
1196
|
+
timestamp?: number
|
|
1197
|
+
/** Duration in microseconds (optional) */
|
|
1198
|
+
duration?: number
|
|
1199
|
+
/** Alpha handling: "keep" (default) or "discard" */
|
|
1200
|
+
alpha?: string
|
|
1201
|
+
/** Visible rect (optional) */
|
|
1202
|
+
visibleRect?: DOMRectInit
|
|
1203
|
+
/** Rotation in degrees clockwise (0, 90, 180, 270) - default 0 */
|
|
1204
|
+
rotation?: number
|
|
1205
|
+
/** Horizontal flip - default false */
|
|
1206
|
+
flip?: boolean
|
|
1207
|
+
/** Display width (optional) */
|
|
1208
|
+
displayWidth?: number
|
|
1209
|
+
/** Display height (optional) */
|
|
1210
|
+
displayHeight?: number
|
|
1211
|
+
/** Metadata associated with the frame */
|
|
1212
|
+
metadata?: VideoFrameMetadata
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* VideoFrameMetadata - metadata associated with a VideoFrame (W3C spec)
|
|
1217
|
+
* Members defined in VideoFrame Metadata Registry - currently empty per spec
|
|
1218
|
+
*/
|
|
1219
|
+
export interface VideoFrameMetadata {}
|
|
1220
|
+
|
|
1221
|
+
/** Rectangle for specifying a region */
|
|
1222
|
+
export interface VideoFrameRect {
|
|
1223
|
+
x: number
|
|
1224
|
+
y: number
|
|
1225
|
+
width: number
|
|
1226
|
+
height: number
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/** Video matrix coefficients (W3C WebCodecs spec) */
|
|
1230
|
+
export type VideoMatrixCoefficients = /** RGB (identity matrix) */
|
|
1231
|
+
| 'rgb'
|
|
1232
|
+
/** BT.709 */
|
|
1233
|
+
| 'bt709'
|
|
1234
|
+
/** BT.470 BG */
|
|
1235
|
+
| 'bt470bg'
|
|
1236
|
+
/** SMPTE 170M */
|
|
1237
|
+
| 'smpte170m'
|
|
1238
|
+
/** BT.2020 non-constant luminance */
|
|
1239
|
+
| 'bt2020-ncl'
|
|
1240
|
+
|
|
1241
|
+
/** Video pixel format (WebCodecs spec) */
|
|
1242
|
+
export type VideoPixelFormat = /** Planar YUV 4:2:0| 12bpp| (1 Cr & Cb sample per 2x2 Y samples) */
|
|
1243
|
+
| 'I420'
|
|
1244
|
+
/** Planar YUV 4:2:0| 12bpp| with alpha plane */
|
|
1245
|
+
| 'I420A'
|
|
1246
|
+
/** Planar YUV 4:2:2| 16bpp */
|
|
1247
|
+
| 'I422'
|
|
1248
|
+
/** Planar YUV 4:2:2| 16bpp| with alpha plane */
|
|
1249
|
+
| 'I422A'
|
|
1250
|
+
/** Planar YUV 4:4:4| 24bpp */
|
|
1251
|
+
| 'I444'
|
|
1252
|
+
/** Planar YUV 4:4:4| 24bpp| with alpha plane */
|
|
1253
|
+
| 'I444A'
|
|
1254
|
+
/** Planar YUV 4:2:0| 10-bit */
|
|
1255
|
+
| 'I420P10'
|
|
1256
|
+
/** Planar YUV 4:2:0| 10-bit| with alpha plane */
|
|
1257
|
+
| 'I420AP10'
|
|
1258
|
+
/** Planar YUV 4:2:2| 10-bit */
|
|
1259
|
+
| 'I422P10'
|
|
1260
|
+
/** Planar YUV 4:2:2| 10-bit| with alpha plane */
|
|
1261
|
+
| 'I422AP10'
|
|
1262
|
+
/** Planar YUV 4:4:4| 10-bit */
|
|
1263
|
+
| 'I444P10'
|
|
1264
|
+
/** Planar YUV 4:4:4| 10-bit| with alpha plane */
|
|
1265
|
+
| 'I444AP10'
|
|
1266
|
+
/** Planar YUV 4:2:0| 12-bit */
|
|
1267
|
+
| 'I420P12'
|
|
1268
|
+
/** Planar YUV 4:2:2| 12-bit */
|
|
1269
|
+
| 'I422P12'
|
|
1270
|
+
/** Planar YUV 4:4:4| 12-bit */
|
|
1271
|
+
| 'I444P12'
|
|
1272
|
+
/** Semi-planar YUV 4:2:0| 12bpp (Y plane + interleaved UV) */
|
|
1273
|
+
| 'NV12'
|
|
1274
|
+
/** Semi-planar YUV 4:2:0| 12bpp (Y plane + interleaved VU) - per W3C WebCodecs spec */
|
|
1275
|
+
| 'NV21'
|
|
1276
|
+
/** RGBA 32bpp */
|
|
1277
|
+
| 'RGBA'
|
|
1278
|
+
/** RGBX 32bpp (alpha ignored) */
|
|
1279
|
+
| 'RGBX'
|
|
1280
|
+
/** BGRA 32bpp */
|
|
1281
|
+
| 'BGRA'
|
|
1282
|
+
/** BGRX 32bpp (alpha ignored) */
|
|
1283
|
+
| 'BGRX'
|
|
1284
|
+
|
|
1285
|
+
/** Video transfer characteristics (W3C WebCodecs spec) */
|
|
1286
|
+
export type VideoTransferCharacteristics = /** BT.709 transfer */
|
|
1287
|
+
| 'bt709'
|
|
1288
|
+
/** SMPTE 170M transfer */
|
|
1289
|
+
| 'smpte170m'
|
|
1290
|
+
/** IEC 61966-2-1 (sRGB) - technical name */
|
|
1291
|
+
| 'iec61966-2-1'
|
|
1292
|
+
/** sRGB transfer (alias for iec61966-2-1) */
|
|
1293
|
+
| 'srgb'
|
|
1294
|
+
/** Linear transfer */
|
|
1295
|
+
| 'linear'
|
|
1296
|
+
/** Perceptual Quantizer (HDR) */
|
|
1297
|
+
| 'pq'
|
|
1298
|
+
/** Hybrid Log-Gamma (HDR) */
|
|
1299
|
+
| 'hlg'
|