-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.d.ts
More file actions
2029 lines (1911 loc) · 62.8 KB
/
index.d.ts
File metadata and controls
2029 lines (1911 loc) · 62.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Import types from standard.d.ts for use in index.d.ts
import type {
VideoDecoderConfig,
VideoEncoderConfig,
AudioEncoderConfig,
AudioDecoderConfig,
VideoFrameBufferInit,
EncodedVideoChunkInit,
EncodedAudioChunkInit,
AudioDataInit,
VideoColorSpaceInit,
ImageDecoderInit,
BufferSource,
AllowSharedBufferSource,
} from './standard'
// Re-export types from standard.d.ts
export {
// Config types
VideoDecoderConfig,
VideoEncoderConfig,
AudioEncoderConfig,
AudioDecoderConfig,
VideoFrameBufferInit,
// Init types (used by constructors)
EncodedVideoChunkInit,
EncodedAudioChunkInit,
AudioDataInit,
VideoColorSpaceInit,
ImageDecoderInit,
// Buffer types
BufferSource,
AllowSharedBufferSource,
} from './standard'
/**
* Interface for Canvas-like objects compatible with VideoFrame constructor.
* Compatible with @napi-rs/canvas Canvas class.
*
* @napi-rs/canvas is an optional peer dependency. If installed, Canvas objects
* can be used as VideoFrame sources. The Canvas pixel data is copied (RGBA format).
*/
export interface CanvasLike {
readonly width: number
readonly height: number
/** Returns raw RGBA pixel data as a Buffer */
data(): Uint8Array
}
// ============================================================================
// Muxer/Demuxer Types
// ============================================================================
/** Demuxer state */
export type DemuxerState = 'unloaded' | 'ready' | 'demuxing' | 'ended' | 'closed'
/** Muxer state */
export type MuxerState = 'configuring' | 'muxing' | 'finalized' | 'closed'
/** Init options for Mp4Demuxer */
export interface Mp4DemuxerInit {
/** Callback for video chunks */
videoOutput?: (chunk: EncodedVideoChunk) => void
/** Callback for audio chunks */
audioOutput?: (chunk: EncodedAudioChunk) => void
/** Error callback (required) */
error: (error: Error) => void
}
/** Init options for WebMDemuxer */
export interface WebMDemuxerInit {
/** Callback for video chunks */
videoOutput?: (chunk: EncodedVideoChunk) => void
/** Callback for audio chunks */
audioOutput?: (chunk: EncodedAudioChunk) => void
/** Error callback (required) */
error: (error: Error) => void
}
/** Init options for MkvDemuxer */
export interface MkvDemuxerInit {
/** Callback for video chunks */
videoOutput?: (chunk: EncodedVideoChunk) => void
/** Callback for audio chunks */
audioOutput?: (chunk: EncodedAudioChunk) => void
/** Error callback (required) */
error: (error: Error) => void
}
/** Video track config for muxer */
export interface MuxerVideoTrackConfig {
/** Codec string */
codec: string
/** Video width */
width: number
/** Video height */
height: number
/** Codec description (e.g., avcC for H.264) */
description?: Uint8Array
}
/** Audio track config for muxer */
export interface MuxerAudioTrackConfig {
/** Codec string */
codec: string
/** Sample rate */
sampleRate: number
/** Number of channels */
numberOfChannels: number
/** Codec description */
description?: Uint8Array
}
/** Init options for Mp4Muxer */
export interface Mp4MuxerInit {
/** Move moov atom to beginning (not compatible with streaming) */
fastStart?: boolean
/** Use fragmented MP4 for streaming */
fragmented?: boolean
/** Enable streaming output mode */
streaming?: { bufferCapacity?: number }
}
/** Init options for WebMMuxer */
export interface WebMMuxerInit {
/** Enable live streaming mode */
live?: boolean
/** Enable streaming output mode */
streaming?: { bufferCapacity?: number }
}
/** Init options for MkvMuxer */
export interface MkvMuxerInit {
/** Enable live streaming mode */
live?: boolean
/** Enable streaming output mode */
streaming?: { bufferCapacity?: number }
}
// ============================================================================
// Async Iterator Types
// ============================================================================
/**
* Chunk yielded by demuxer async iterator.
*
* Contains either a video or audio chunk. Use the `chunkType` property
* to determine which type of chunk is present.
*
* @example
* ```typescript
* for await (const chunk of demuxer) {
* if (chunk.chunkType === 'video') {
* videoDecoder.decode(chunk.videoChunk!)
* } else {
* audioDecoder.decode(chunk.audioChunk!)
* }
* }
* ```
*/
export interface DemuxerChunk {
/** Type of chunk: 'video' or 'audio' */
chunkType: 'video' | 'audio'
/** Video chunk (present when chunkType is 'video') */
videoChunk?: EncodedVideoChunk
/** Audio chunk (present when chunkType is 'audio') */
audioChunk?: EncodedAudioChunk
}
/**
* Adds async iterator support to Mp4Demuxer.
* Declaration merging allows using `for await...of` with the demuxer.
*/
export interface Mp4Demuxer {
[Symbol.asyncIterator](): AsyncGenerator<DemuxerChunk, void, void>
}
/**
* Adds async iterator support to WebMDemuxer.
* Declaration merging allows using `for await...of` with the demuxer.
*/
export interface WebMDemuxer {
[Symbol.asyncIterator](): AsyncGenerator<DemuxerChunk, void, void>
}
/**
* Adds async iterator support to MkvDemuxer.
* Declaration merging allows using `for await...of` with the demuxer.
*/
export interface MkvDemuxer {
[Symbol.asyncIterator](): AsyncGenerator<DemuxerChunk, void, void>
}
export type TypedArray =
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array
| BigInt64Array
| BigUint64Array
/**
* AudioData - represents uncompressed audio data
*
* This is a WebCodecs-compliant AudioData implementation backed by FFmpeg.
*/
export declare class AudioData {
/**
* Create a new AudioData (W3C WebCodecs spec)
* Per spec, the constructor takes a single init object containing all parameters including data
*/
constructor(init: AudioDataInit)
/** Get sample format */
get format(): AudioSampleFormat | null
/**
* Get sample rate in Hz (W3C spec uses float)
* Returns 0 after close per W3C spec
*/
get sampleRate(): number
/**
* Get number of frames (samples per channel)
* Returns 0 after close per W3C spec
*/
get numberOfFrames(): number
/**
* Get number of channels
* Returns 0 after close per W3C spec
*/
get numberOfChannels(): number
/**
* Get duration in microseconds
* Returns 0 after close per W3C spec
*/
get duration(): number
/**
* Get timestamp in microseconds
* Timestamp is preserved after close per W3C spec
*/
get timestamp(): number
/** Get whether this AudioData has been closed (W3C WebCodecs spec) */
get closed(): boolean
/**
* Get the number of planes in this AudioData (W3C WebCodecs spec)
* For interleaved formats: 1
* For planar formats: numberOfChannels
*/
get numberOfPlanes(): number
/**
* Get the buffer size required for copyTo (W3C WebCodecs spec)
* Note: options is REQUIRED per spec
*/
allocationSize(options: AudioDataCopyToOptions): number
/**
* Copy audio data to a buffer (W3C WebCodecs spec)
* Note: Per spec, this is SYNCHRONOUS and returns undefined
* Accepts AllowSharedBufferSource (any TypedArray, DataView, or ArrayBuffer)
*/
copyTo(destination: AllowSharedBufferSource, options: AudioDataCopyToOptions): void
/** Create a copy of this AudioData */
clone(): AudioData
/** Close and release resources */
close(): void
}
/**
* AudioDecoder - WebCodecs-compliant audio decoder
*
* Decodes EncodedAudioChunk objects into AudioData objects using FFmpeg.
*
* Per the WebCodecs spec, the constructor takes an init dictionary with callbacks.
*
* Example:
* ```javascript
* const decoder = new AudioDecoder({
* output: (data) => { console.log('decoded audio', data); },
* error: (e) => { console.error('error', e); }
* });
*
* decoder.configure({
* codec: 'opus',
* sampleRate: 48000,
* numberOfChannels: 2
* });
*
* decoder.decode(chunk);
* await decoder.flush();
* ```
*/
export declare class AudioDecoder {
/**
* Create a new AudioDecoder with init dictionary (per WebCodecs spec)
*
* @param init - Init dictionary containing output and error callbacks
*/
constructor(init: { output: (data: AudioData) => void; error: (error: Error) => void })
/** Get decoder state */
get state(): CodecState
/** Get number of pending decode operations (per WebCodecs spec) */
get decodeQueueSize(): number
/**
* Set the dequeue event handler (per WebCodecs spec)
*
* The dequeue event fires when decodeQueueSize decreases,
* allowing backpressure management.
*/
set ondequeue(callback: (() => unknown) | undefined | null)
/** Get the dequeue event handler (per WebCodecs spec) */
get ondequeue(): (() => unknown) | null
/** Configure the decoder */
configure(config: AudioDecoderConfig): void
/** Decode an encoded audio chunk */
decode(chunk: EncodedAudioChunk): void
/**
* Flush the decoder
* Returns a Promise that resolves when flushing is complete
*
* Uses spawn_future_with_callback to check abort flag synchronously in the resolver.
* This ensures that if reset() is called from a callback, the abort flag is checked
* AFTER the callback returns, allowing flush() to return AbortError.
*/
flush(): Promise<void>
/** Reset the decoder */
reset(): void
/** Close the decoder */
close(): void
/**
* Check if a configuration is supported
* Returns a Promise that resolves with support information
*
* W3C WebCodecs spec: Rejects with TypeError for invalid configs,
* returns { supported: false } for valid but unsupported configs.
*/
static isConfigSupported(config: AudioDecoderConfig): Promise<AudioDecoderSupport>
/** Add an event listener for the specified event type */
addEventListener(
eventType: string,
callback: () => unknown,
options?: AudioDecoderAddEventListenerOptions | undefined | null,
): void
/** Remove an event listener for the specified event type */
removeEventListener(
eventType: string,
callback: () => unknown,
options?: AudioDecoderEventListenerOptions | undefined | null,
): void
/** Dispatch an event to all registered listeners */
dispatchEvent(eventType: string): boolean
}
/**
* AudioEncoder - WebCodecs-compliant audio encoder
*
* Encodes AudioData objects into EncodedAudioChunk objects using FFmpeg.
*
* Per the WebCodecs spec, the constructor takes an init dictionary with callbacks.
*
* Example:
* ```javascript
* const encoder = new AudioEncoder({
* output: (chunk, metadata) => { console.log('encoded chunk', chunk); },
* error: (e) => { console.error('error', e); }
* });
*
* encoder.configure({
* codec: 'opus',
* sampleRate: 48000,
* numberOfChannels: 2
* });
*
* encoder.encode(audioData);
* await encoder.flush();
* ```
*/
export declare class AudioEncoder {
/**
* Create a new AudioEncoder with init dictionary (per WebCodecs spec)
*
* @param init - Init dictionary containing output and error callbacks
*/
constructor(init: {
output: (chunk: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadata) => void
error: (error: Error) => void
})
/** Get encoder state */
get state(): CodecState
/** Get number of pending encode operations (per WebCodecs spec) */
get encodeQueueSize(): number
/**
* Set the dequeue event handler (per WebCodecs spec)
*
* The dequeue event fires when encodeQueueSize decreases,
* allowing backpressure management.
*/
set ondequeue(callback: (() => unknown) | undefined | null)
/** Get the dequeue event handler (per WebCodecs spec) */
get ondequeue(): (() => unknown) | null
/** Configure the encoder */
configure(config: AudioEncoderConfig): void
/** Encode audio data */
encode(data: AudioData): void
/**
* Flush the encoder
* Returns a Promise that resolves when flushing is complete
*
* Uses spawn_future_with_callback to check abort flag synchronously in the resolver.
* This ensures that if reset() is called from a callback, the abort flag is checked
* AFTER the callback returns, allowing flush() to return AbortError.
*/
flush(): Promise<void>
/** Reset the encoder */
reset(): void
/** Close the encoder */
close(): void
/**
* Check if a configuration is supported
* Returns a Promise that resolves with support information
*
* W3C WebCodecs spec: Rejects with TypeError for invalid configs,
* returns { supported: false } for valid but unsupported configs.
*/
static isConfigSupported(config: AudioEncoderConfig): Promise<AudioEncoderSupport>
/**
* Add an event listener for the specified event type
* Uses separate RwLock to avoid blocking on encode operations
*/
addEventListener(
eventType: string,
callback: () => unknown,
options?: AudioEncoderAddEventListenerOptions | undefined | null,
): void
/** Remove an event listener for the specified event type */
removeEventListener(
eventType: string,
callback: () => unknown,
options?: AudioEncoderEventListenerOptions | undefined | null,
): void
/** Dispatch an event to all registered listeners */
dispatchEvent(eventType: string): boolean
}
/**
* DOMRectReadOnly - W3C WebCodecs spec compliant rect class
* Used for codedRect and visibleRect properties
*/
export declare class DOMRectReadOnly {
/** Create a new DOMRectReadOnly */
constructor(
x?: number | undefined | null,
y?: number | undefined | null,
width?: number | undefined | null,
height?: number | undefined | null,
)
/** X coordinate */
get x(): number
/** Y coordinate */
get y(): number
/** Width */
get width(): number
/** Height */
get height(): number
/** Top edge (same as y) */
get top(): number
/** Right edge (x + width) */
get right(): number
/** Bottom edge (y + height) */
get bottom(): number
/** Left edge (same as x) */
get left(): number
/** Convert to JSON (W3C spec uses toJSON) */
toJSON(): DOMRectInit
}
/**
* EncodedAudioChunk - represents encoded audio data
*
* This is a WebCodecs-compliant EncodedAudioChunk implementation.
*/
export declare class EncodedAudioChunk {
/** Create a new EncodedAudioChunk */
constructor(init: EncodedAudioChunkInit)
/** Get the chunk type */
get type(): EncodedAudioChunkType
/** Get the timestamp in microseconds */
get timestamp(): number
/** Get the duration in microseconds */
get duration(): number | null
/** Get the byte length of the encoded data */
get byteLength(): number
/**
* Copy the encoded data to a BufferSource
* W3C spec: throws TypeError if destination is too small
*/
copyTo(destination: BufferSource): void
}
/**
* EncodedVideoChunk - represents encoded video data
*
* This is a WebCodecs-compliant EncodedVideoChunk implementation.
*/
export declare class EncodedVideoChunk {
/** Create a new EncodedVideoChunk */
constructor(init: EncodedVideoChunkInit)
/** Get the chunk type */
get type(): EncodedVideoChunkType
/** Get the timestamp in microseconds */
get timestamp(): number
/** Get the duration in microseconds */
get duration(): number | null
/** Get the byte length of the encoded data */
get byteLength(): number
/**
* Copy the encoded data to a BufferSource
* W3C spec: throws TypeError if destination is too small
*/
copyTo(destination: BufferSource): void
}
/**
* ImageDecoder - WebCodecs-compliant image decoder
*
* Decodes image data (JPEG, PNG, WebP, GIF, BMP) into VideoFrame objects.
*
* Example:
* ```javascript
* const decoder = new ImageDecoder({
* data: imageBytes,
* type: 'image/png'
* });
*
* const result = await decoder.decode();
* const frame = result.image;
* ```
*/
export declare class ImageDecoder {
/**
* Create a new ImageDecoder
* Supports both Uint8Array and ReadableStream as data source per W3C spec
*/
constructor(init: ImageDecoderInit)
/** Whether the data is fully buffered */
get complete(): boolean
/**
* Promise that resolves when data is fully loaded (per WebCodecs spec)
* Returns a new promise chained from the stored promise (allows multiple accesses)
*/
get completed(): Promise<undefined>
/** Get the MIME type */
get type(): string
/** Get the track list */
get tracks(): ImageTrackList
/** Decode the image (or a specific frame) */
decode(this: this, options?: ImageDecodeOptions | undefined | null): Promise<ImageDecodeResult>
/**
* Reset the decoder
* Clears cached frames - next decode() will re-decode from stored data
*/
reset(): void
/** Close the decoder */
close(): void
/** Whether this ImageDecoder has been closed (W3C WebCodecs spec) */
get closed(): boolean
/** Check if a MIME type is supported */
static isTypeSupported(mimeType: string): Promise<boolean>
}
/**
* Image decode result
* Note: W3C spec defines this as a dictionary, but NAPI-RS doesn't support
* class instances in objects, so we use a class with the same properties.
*/
export declare class ImageDecodeResult {
/** Get the decoded image */
get image(): VideoFrame
/** Get whether the decode is complete */
get complete(): boolean
}
/** Image track information (W3C spec - class with writable selected property) */
export declare class ImageTrack {
/** Whether this track is animated */
get animated(): boolean
/** Number of frames in this track */
get frameCount(): number
/** Number of times the animation repeats (Infinity for infinite) */
get repetitionCount(): number
/** Whether this track is currently selected (W3C spec - writable) */
get selected(): boolean
/**
* Set whether this track is selected (W3C spec - writable)
* Setting to true deselects all other tracks
*/
set selected(value: boolean)
}
/** Image track list (W3C spec) */
export declare class ImageTrackList {
/** Get the number of tracks */
get length(): number
/** Get the currently selected track (if any) */
get selectedTrack(): ImageTrack | null
/** Get the selected track index (W3C spec: returns -1 if no track selected) */
get selectedIndex(): number
/** Promise that resolves when track metadata is available (W3C spec) */
get ready(): Promise<void>
/** Get track at specified index (W3C spec) */
item(index: number): ImageTrack | null
}
/**
* MKV Demuxer for reading encoded video and audio from Matroska container
*
* MKV supports almost any video and audio codec.
*
* This type implements JavaScript's async iterable protocol.
* It can be used with `for await...of` loops.
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
*/
export declare class MkvDemuxer {
constructor(init: MkvDemuxerInit)
load(path: string): Promise<void>
/**
* Load an MKV from a buffer
*
* This method uses zero-copy buffer loading - the Uint8Array data is passed
* directly to the demuxer without an intermediate copy.
*/
loadBuffer(data: Uint8Array): Promise<void>
get tracks(): Array<DemuxerTrackInfo>
get duration(): number | null
get videoDecoderConfig(): DemuxerVideoDecoderConfig | null
get audioDecoderConfig(): DemuxerAudioDecoderConfig | null
selectVideoTrack(trackIndex: number): void
selectAudioTrack(trackIndex: number): void
demux(count?: number | undefined | null): void
/** Demux packets asynchronously (awaitable version of demux) */
demuxAsync(count?: number | undefined | null): Promise<void>
seek(timestampUs: number): void
close(): void
get state(): string
}
/**
* MKV Muxer for combining encoded video and audio into Matroska container
*
* MKV (Matroska) supports virtually all video and audio codecs.
*
* Usage:
* ```javascript
* const muxer = new MkvMuxer();
* muxer.addVideoTrack({ codec: 'avc1.42001E', width: 1920, height: 1080 });
* muxer.addAudioTrack({ codec: 'opus', sampleRate: 48000, numberOfChannels: 2 });
*
* // Add encoded chunks from VideoEncoder/AudioEncoder
* encoder.configure({
* output: (chunk, metadata) => muxer.addVideoChunk(chunk, metadata)
* });
*
* // Finalize and get MKV data
* const mkvData = muxer.finalize();
* ```
*/
export declare class MkvMuxer {
/** Create a new MKV muxer */
constructor(options?: MkvMuxerOptions | undefined | null)
/**
* Add a video track to the muxer
*
* MKV supports H.264, H.265, VP8, VP9, AV1, and many other video codecs.
*/
addVideoTrack(config: MkvVideoTrackConfig): void
/**
* Add an audio track to the muxer
*
* MKV supports AAC, Opus, Vorbis, FLAC, MP3, AC3, and many other audio codecs.
*/
addAudioTrack(config: MkvAudioTrackConfig): void
/** Add an encoded video chunk to the muxer */
addVideoChunk(chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadataJs | undefined | null): void
/** Add an encoded audio chunk to the muxer */
addAudioChunk(chunk: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadataJs | undefined | null): void
/** Flush any buffered data */
flush(): void
/** Finalize the muxer and return the MKV data */
finalize(): Uint8Array
/**
* Read available data from streaming buffer (streaming mode only)
*
* Returns available data, or null if no data is ready yet.
* Returns empty Uint8Array when streaming is finished.
*/
read(): Uint8Array | null
/** Check if muxer is in streaming mode */
get isStreaming(): boolean
/** Check if streaming is finished (streaming mode only) */
get isFinished(): boolean
/** Close the muxer and release resources */
close(): void
/** Get the current state of the muxer */
get state(): string
}
/**
* MP4 Demuxer for reading encoded video and audio from MP4 container
*
* Usage:
* ```javascript
* const demuxer = new Mp4Demuxer({
* videoOutput: (chunk) => videoDecoder.decode(chunk),
* audioOutput: (chunk) => audioDecoder.decode(chunk),
* error: (err) => console.error(err)
* });
*
* await demuxer.load('./video.mp4');
*
* // Get decoder configs
* const videoConfig = demuxer.videoDecoderConfig;
* const audioConfig = demuxer.audioDecoderConfig;
*
* // Configure decoders
* videoDecoder.configure(videoConfig);
* audioDecoder.configure(audioConfig);
*
* // Start demuxing
* demuxer.demux();
*
* // Seek to 5 seconds
* demuxer.seek(5_000_000);
*
* demuxer.close();
* ```
*
* This type implements JavaScript's async iterable protocol.
* It can be used with `for await...of` loops.
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
*/
export declare class Mp4Demuxer {
/** Create a new MP4 demuxer */
constructor(init: Mp4DemuxerInit)
/** Load an MP4 file from a path */
load(path: string): Promise<void>
/**
* Load an MP4 from a buffer
*
* This method uses zero-copy buffer loading - the Uint8Array data is passed
* directly to the demuxer without an intermediate copy.
*/
loadBuffer(data: Uint8Array): Promise<void>
/** Get all tracks */
get tracks(): Array<DemuxerTrackInfo>
/** Get container duration in microseconds */
get duration(): number | null
/** Get video decoder configuration for the selected video track */
get videoDecoderConfig(): DemuxerVideoDecoderConfig | null
/** Get audio decoder configuration for the selected audio track */
get audioDecoderConfig(): DemuxerAudioDecoderConfig | null
/** Select a video track by index */
selectVideoTrack(trackIndex: number): void
/** Select an audio track by index */
selectAudioTrack(trackIndex: number): void
/**
* Start demuxing packets
*
* If count is specified, reads up to that many packets.
* Otherwise, reads all packets until end of stream.
*/
demux(count?: number | undefined | null): void
/**
* Demux packets asynchronously (awaitable version of demux)
*
* If count is specified, reads up to that many packets.
* Otherwise, reads all packets until end of stream.
* Returns a Promise that resolves when demuxing is complete.
*
* This method is useful when you want to wait for demuxing to finish
* before proceeding with other operations.
*
* Note: For streaming use cases, prefer the async iterator pattern:
* `for await (const chunk of demuxer) { ... }`
*/
demuxAsync(count?: number | undefined | null): Promise<void>
/** Seek to a timestamp in microseconds */
seek(timestampUs: number): void
/** Close the demuxer and release resources */
close(): void
/** Get the current state of the demuxer */
get state(): string
}
/**
* MP4 Muxer for combining encoded video and audio into MP4 container
*
* Usage:
* ```javascript
* const muxer = new Mp4Muxer({ fastStart: true });
* muxer.addVideoTrack({ codec: 'avc1.42001E', width: 1920, height: 1080 });
* muxer.addAudioTrack({ codec: 'mp4a.40.2', sampleRate: 48000, numberOfChannels: 2 });
*
* // Add encoded chunks from VideoEncoder/AudioEncoder
* encoder.configure({
* output: (chunk, metadata) => muxer.addVideoChunk(chunk, metadata)
* });
*
* // Finalize and get MP4 data
* const mp4Data = muxer.finalize();
* ```
*/
export declare class Mp4Muxer {
/** Create a new MP4 muxer */
constructor(options?: Mp4MuxerOptions | undefined | null)
/**
* Add a video track to the muxer
*
* Must be called before adding any chunks.
*/
addVideoTrack(config: Mp4VideoTrackConfig): void
/**
* Add an audio track to the muxer
*
* Must be called before adding any chunks.
*/
addAudioTrack(config: Mp4AudioTrackConfig): void
/**
* Add an encoded video chunk to the muxer
*
* The chunk should come from a VideoEncoder's output callback.
* If metadata contains decoderConfig.description, it will be used to update
* the codec extradata (useful for extracting avcC/hvcC from the encoder).
*/
addVideoChunk(chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadataJs | undefined | null): void
/**
* Add an encoded audio chunk to the muxer
*
* The chunk should come from an AudioEncoder's output callback.
*/
addAudioChunk(chunk: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadataJs | undefined | null): void
/** Flush any buffered data */
flush(): void
/**
* Finalize the muxer and return the MP4 data
*
* After calling this, no more chunks can be added.
* Returns the complete MP4 file as a Uint8Array.
*/
finalize(): Uint8Array
/**
* Read available data from streaming buffer (streaming mode only)
*
* Returns available data, or null if no data is ready yet.
* Returns empty Uint8Array when streaming is finished.
*/
read(): Uint8Array | null
/** Check if muxer is in streaming mode */
get isStreaming(): boolean
/** Check if streaming is finished (streaming mode only) */
get isFinished(): boolean
/**
* Close the muxer and release resources
*
* This is called automatically when the muxer is garbage collected,
* but can be called explicitly to release resources early.
*/
close(): void
/** Get the current state of the muxer */
get state(): string
}
/** Video color space parameters (WebCodecs spec) - as a class per spec */
export declare class VideoColorSpace {
/** Create a new VideoColorSpace */
constructor(init?: VideoColorSpaceInit | undefined | null)
/** Get color primaries */
get primaries(): VideoColorPrimaries | null
/** Get transfer characteristics */
get transfer(): VideoTransferCharacteristics | null
/** Get matrix coefficients */
get matrix(): VideoMatrixCoefficients | null
/** Get full range flag */
get fullRange(): boolean | null
/**
* Convert to JSON-compatible object (W3C spec uses toJSON)
*
* Per W3C spec, toJSON() returns explicit null for unset fields.
*/
toJSON(): object
}
/**
* VideoDecoder - WebCodecs-compliant video decoder
*
* Decodes EncodedVideoChunk objects into VideoFrame objects using FFmpeg.
*
* Per the WebCodecs spec, the constructor takes an init dictionary with callbacks.
*
* Example:
* ```javascript
* const decoder = new VideoDecoder({
* output: (frame) => { console.log('decoded frame', frame); },
* error: (e) => { console.error('error', e); }
* });
*
* decoder.configure({
* codec: 'avc1.42001E'
* });
*
* decoder.decode(chunk);
* await decoder.flush();
* ```
*/
export declare class VideoDecoder {
/**
* Create a new VideoDecoder with init dictionary (per WebCodecs spec)
*
* @param init - Init dictionary containing output and error callbacks
*/
constructor(init: { output: (frame: VideoFrame) => void; error: (error: Error) => void })
/** Get decoder state */
get state(): CodecState
/** Get number of pending decode operations (per WebCodecs spec) */
get decodeQueueSize(): number
/**
* Set the dequeue event handler (per WebCodecs spec)
*
* The dequeue event fires when decodeQueueSize decreases,
* allowing backpressure management.
*/
set ondequeue(callback: (() => unknown) | undefined | null)
/** Get the dequeue event handler (per WebCodecs spec) */
get ondequeue(): (() => unknown) | null
/**
* Configure the decoder
*
* Implements Chromium-aligned hardware acceleration behavior:
* - `prefer-hardware`: Try hardware only, report error if fails
* - `no-preference`: Try hardware first, silently fall back to software
* - `prefer-software`: Use software only
*/
configure(config: VideoDecoderConfig): void
/** Decode an encoded video chunk */
decode(chunk: EncodedVideoChunk): void
/**
* Flush the decoder
* Returns a Promise that resolves when flushing is complete
*
* Uses spawn_future_with_callback to check abort flag synchronously in the resolver.
* This ensures that if reset() is called from a callback, the abort flag is checked
* AFTER the callback returns, allowing flush() to return AbortError.
*/
flush(): Promise<void>
/** Reset the decoder */
reset(): void
/** Close the decoder */
close(): void
/**
* Check if a configuration is supported
* Returns a Promise that resolves with support information
*
* W3C WebCodecs spec: Throws TypeError for invalid configs,
* returns { supported: false } for valid but unsupported configs.
*/
static isConfigSupported(config: VideoDecoderConfig): Promise<VideoDecoderSupport>
/**
* Add an event listener for the specified event type
* Uses separate RwLock to avoid blocking on decode operations
*/
addEventListener(
eventType: string,
callback: () => unknown,
options?: VideoDecoderAddEventListenerOptions | undefined | null,
): void
/** Remove an event listener for the specified event type */
removeEventListener(
eventType: string,
callback: () => unknown,
options?: VideoDecoderEventListenerOptions | undefined | null,
): void
/** Dispatch an event to all registered listeners */
dispatchEvent(eventType: string): boolean
}
/**
* VideoEncoder - WebCodecs-compliant video encoder
*
* Encodes VideoFrame objects into EncodedVideoChunk objects using FFmpeg.
*
* Per the WebCodecs spec, the constructor takes an init dictionary with callbacks.
*
* Example:
* ```javascript
* const encoder = new VideoEncoder({
* output: (chunk, metadata) => { console.log('encoded chunk', chunk); },
* error: (e) => { console.error('error', e); }
* });
*