@napi-rs/webcodecs 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -1
- package/index.d.ts +620 -24
- package/index.js +58 -52
- package/package.json +12 -11
package/index.d.ts
CHANGED
|
@@ -33,19 +33,6 @@ export {
|
|
|
33
33
|
AllowSharedBufferSource,
|
|
34
34
|
} from './standard'
|
|
35
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
36
|
/**
|
|
50
37
|
* Interface for Canvas-like objects compatible with VideoFrame constructor.
|
|
51
38
|
* Compatible with @napi-rs/canvas Canvas class.
|
|
@@ -60,6 +47,96 @@ export interface CanvasLike {
|
|
|
60
47
|
data(): Uint8Array
|
|
61
48
|
}
|
|
62
49
|
|
|
50
|
+
// ============================================================================
|
|
51
|
+
// Muxer/Demuxer Types
|
|
52
|
+
// ============================================================================
|
|
53
|
+
|
|
54
|
+
/** Demuxer state */
|
|
55
|
+
export type DemuxerState = 'unloaded' | 'ready' | 'demuxing' | 'ended' | 'closed'
|
|
56
|
+
|
|
57
|
+
/** Muxer state */
|
|
58
|
+
export type MuxerState = 'configuring' | 'muxing' | 'finalized' | 'closed'
|
|
59
|
+
|
|
60
|
+
/** Init options for Mp4Demuxer */
|
|
61
|
+
export interface Mp4DemuxerInit {
|
|
62
|
+
/** Callback for video chunks */
|
|
63
|
+
videoOutput?: (chunk: EncodedVideoChunk) => void
|
|
64
|
+
/** Callback for audio chunks */
|
|
65
|
+
audioOutput?: (chunk: EncodedAudioChunk) => void
|
|
66
|
+
/** Error callback (required) */
|
|
67
|
+
error: (error: Error) => void
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Init options for WebMDemuxer */
|
|
71
|
+
export interface WebMDemuxerInit {
|
|
72
|
+
/** Callback for video chunks */
|
|
73
|
+
videoOutput?: (chunk: EncodedVideoChunk) => void
|
|
74
|
+
/** Callback for audio chunks */
|
|
75
|
+
audioOutput?: (chunk: EncodedAudioChunk) => void
|
|
76
|
+
/** Error callback (required) */
|
|
77
|
+
error: (error: Error) => void
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Init options for MkvDemuxer */
|
|
81
|
+
export interface MkvDemuxerInit {
|
|
82
|
+
/** Callback for video chunks */
|
|
83
|
+
videoOutput?: (chunk: EncodedVideoChunk) => void
|
|
84
|
+
/** Callback for audio chunks */
|
|
85
|
+
audioOutput?: (chunk: EncodedAudioChunk) => void
|
|
86
|
+
/** Error callback (required) */
|
|
87
|
+
error: (error: Error) => void
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Video track config for muxer */
|
|
91
|
+
export interface MuxerVideoTrackConfig {
|
|
92
|
+
/** Codec string */
|
|
93
|
+
codec: string
|
|
94
|
+
/** Video width */
|
|
95
|
+
width: number
|
|
96
|
+
/** Video height */
|
|
97
|
+
height: number
|
|
98
|
+
/** Codec description (e.g., avcC for H.264) */
|
|
99
|
+
description?: Uint8Array
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Audio track config for muxer */
|
|
103
|
+
export interface MuxerAudioTrackConfig {
|
|
104
|
+
/** Codec string */
|
|
105
|
+
codec: string
|
|
106
|
+
/** Sample rate */
|
|
107
|
+
sampleRate: number
|
|
108
|
+
/** Number of channels */
|
|
109
|
+
numberOfChannels: number
|
|
110
|
+
/** Codec description */
|
|
111
|
+
description?: Uint8Array
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Init options for Mp4Muxer */
|
|
115
|
+
export interface Mp4MuxerInit {
|
|
116
|
+
/** Move moov atom to beginning (not compatible with streaming) */
|
|
117
|
+
fastStart?: boolean
|
|
118
|
+
/** Use fragmented MP4 for streaming */
|
|
119
|
+
fragmented?: boolean
|
|
120
|
+
/** Enable streaming output mode */
|
|
121
|
+
streaming?: { bufferCapacity?: number }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Init options for WebMMuxer */
|
|
125
|
+
export interface WebMMuxerInit {
|
|
126
|
+
/** Enable live streaming mode */
|
|
127
|
+
live?: boolean
|
|
128
|
+
/** Enable streaming output mode */
|
|
129
|
+
streaming?: { bufferCapacity?: number }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Init options for MkvMuxer */
|
|
133
|
+
export interface MkvMuxerInit {
|
|
134
|
+
/** Enable live streaming mode */
|
|
135
|
+
live?: boolean
|
|
136
|
+
/** Enable streaming output mode */
|
|
137
|
+
streaming?: { bufferCapacity?: number }
|
|
138
|
+
}
|
|
139
|
+
|
|
63
140
|
export type TypedArray =
|
|
64
141
|
| Int8Array
|
|
65
142
|
| Uint8Array
|
|
@@ -82,7 +159,7 @@ export declare class AudioData {
|
|
|
82
159
|
* Create a new AudioData (W3C WebCodecs spec)
|
|
83
160
|
* Per spec, the constructor takes a single init object containing all parameters including data
|
|
84
161
|
*/
|
|
85
|
-
constructor(init:
|
|
162
|
+
constructor(init: AudioDataInit)
|
|
86
163
|
/** Get sample format */
|
|
87
164
|
get format(): AudioSampleFormat | null
|
|
88
165
|
/**
|
|
@@ -128,7 +205,7 @@ export declare class AudioData {
|
|
|
128
205
|
* Note: Per spec, this is SYNCHRONOUS and returns undefined
|
|
129
206
|
* Accepts AllowSharedBufferSource (any TypedArray, DataView, or ArrayBuffer)
|
|
130
207
|
*/
|
|
131
|
-
copyTo(destination:
|
|
208
|
+
copyTo(destination: AllowSharedBufferSource, options: AudioDataCopyToOptions): void
|
|
132
209
|
/** Create a copy of this AudioData */
|
|
133
210
|
clone(): AudioData
|
|
134
211
|
/** Close and release resources */
|
|
@@ -176,7 +253,7 @@ export declare class AudioDecoder {
|
|
|
176
253
|
* The dequeue event fires when decodeQueueSize decreases,
|
|
177
254
|
* allowing backpressure management.
|
|
178
255
|
*/
|
|
179
|
-
set ondequeue(callback
|
|
256
|
+
set ondequeue(callback: (() => unknown) | undefined | null)
|
|
180
257
|
/** Get the dequeue event handler (per WebCodecs spec) */
|
|
181
258
|
get ondequeue(): (() => unknown) | null
|
|
182
259
|
/** Configure the decoder */
|
|
@@ -264,7 +341,7 @@ export declare class AudioEncoder {
|
|
|
264
341
|
* The dequeue event fires when encodeQueueSize decreases,
|
|
265
342
|
* allowing backpressure management.
|
|
266
343
|
*/
|
|
267
|
-
set ondequeue(callback
|
|
344
|
+
set ondequeue(callback: (() => unknown) | undefined | null)
|
|
268
345
|
/** Get the dequeue event handler (per WebCodecs spec) */
|
|
269
346
|
get ondequeue(): (() => unknown) | null
|
|
270
347
|
/** Configure the encoder */
|
|
@@ -350,7 +427,7 @@ export declare class DOMRectReadOnly {
|
|
|
350
427
|
*/
|
|
351
428
|
export declare class EncodedAudioChunk {
|
|
352
429
|
/** Create a new EncodedAudioChunk */
|
|
353
|
-
constructor(init:
|
|
430
|
+
constructor(init: EncodedAudioChunkInit)
|
|
354
431
|
/** Get the chunk type */
|
|
355
432
|
get type(): EncodedAudioChunkType
|
|
356
433
|
/** Get the timestamp in microseconds */
|
|
@@ -363,7 +440,7 @@ export declare class EncodedAudioChunk {
|
|
|
363
440
|
* Copy the encoded data to a BufferSource
|
|
364
441
|
* W3C spec: throws TypeError if destination is too small
|
|
365
442
|
*/
|
|
366
|
-
copyTo(destination:
|
|
443
|
+
copyTo(destination: BufferSource): void
|
|
367
444
|
}
|
|
368
445
|
|
|
369
446
|
/**
|
|
@@ -373,7 +450,7 @@ export declare class EncodedAudioChunk {
|
|
|
373
450
|
*/
|
|
374
451
|
export declare class EncodedVideoChunk {
|
|
375
452
|
/** Create a new EncodedVideoChunk */
|
|
376
|
-
constructor(init:
|
|
453
|
+
constructor(init: EncodedVideoChunkInit)
|
|
377
454
|
/** Get the chunk type */
|
|
378
455
|
get type(): EncodedVideoChunkType
|
|
379
456
|
/** Get the timestamp in microseconds */
|
|
@@ -386,7 +463,7 @@ export declare class EncodedVideoChunk {
|
|
|
386
463
|
* Copy the encoded data to a BufferSource
|
|
387
464
|
* W3C spec: throws TypeError if destination is too small
|
|
388
465
|
*/
|
|
389
|
-
copyTo(destination:
|
|
466
|
+
copyTo(destination: BufferSource): void
|
|
390
467
|
}
|
|
391
468
|
|
|
392
469
|
/**
|
|
@@ -480,10 +557,244 @@ export declare class ImageTrackList {
|
|
|
480
557
|
item(index: number): ImageTrack | null
|
|
481
558
|
}
|
|
482
559
|
|
|
560
|
+
/**
|
|
561
|
+
* MKV Demuxer for reading encoded video and audio from Matroska container
|
|
562
|
+
*
|
|
563
|
+
* MKV supports almost any video and audio codec.
|
|
564
|
+
*/
|
|
565
|
+
export declare class MkvDemuxer {
|
|
566
|
+
constructor(init: MkvDemuxerInit)
|
|
567
|
+
load(path: string): Promise<void>
|
|
568
|
+
/**
|
|
569
|
+
* Load an MKV from a buffer
|
|
570
|
+
*
|
|
571
|
+
* This method uses zero-copy buffer loading - the Uint8Array data is passed
|
|
572
|
+
* directly to the demuxer without an intermediate copy.
|
|
573
|
+
*/
|
|
574
|
+
loadBuffer(data: Uint8Array): Promise<void>
|
|
575
|
+
get tracks(): Array<DemuxerTrackInfo>
|
|
576
|
+
get duration(): number | null
|
|
577
|
+
get videoDecoderConfig(): DemuxerVideoDecoderConfig | null
|
|
578
|
+
get audioDecoderConfig(): DemuxerAudioDecoderConfig | null
|
|
579
|
+
selectVideoTrack(trackIndex: number): void
|
|
580
|
+
selectAudioTrack(trackIndex: number): void
|
|
581
|
+
demux(count?: number | undefined | null): void
|
|
582
|
+
seek(timestampUs: number): void
|
|
583
|
+
close(): void
|
|
584
|
+
get state(): string
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* MKV Muxer for combining encoded video and audio into Matroska container
|
|
589
|
+
*
|
|
590
|
+
* MKV (Matroska) supports virtually all video and audio codecs.
|
|
591
|
+
*
|
|
592
|
+
* Usage:
|
|
593
|
+
* ```javascript
|
|
594
|
+
* const muxer = new MkvMuxer();
|
|
595
|
+
* muxer.addVideoTrack({ codec: 'avc1.42001E', width: 1920, height: 1080 });
|
|
596
|
+
* muxer.addAudioTrack({ codec: 'opus', sampleRate: 48000, numberOfChannels: 2 });
|
|
597
|
+
*
|
|
598
|
+
* // Add encoded chunks from VideoEncoder/AudioEncoder
|
|
599
|
+
* encoder.configure({
|
|
600
|
+
* output: (chunk, metadata) => muxer.addVideoChunk(chunk, metadata)
|
|
601
|
+
* });
|
|
602
|
+
*
|
|
603
|
+
* // Finalize and get MKV data
|
|
604
|
+
* const mkvData = muxer.finalize();
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
export declare class MkvMuxer {
|
|
608
|
+
/** Create a new MKV muxer */
|
|
609
|
+
constructor(options?: MkvMuxerOptions | undefined | null)
|
|
610
|
+
/**
|
|
611
|
+
* Add a video track to the muxer
|
|
612
|
+
*
|
|
613
|
+
* MKV supports H.264, H.265, VP8, VP9, AV1, and many other video codecs.
|
|
614
|
+
*/
|
|
615
|
+
addVideoTrack(config: MkvVideoTrackConfig): void
|
|
616
|
+
/**
|
|
617
|
+
* Add an audio track to the muxer
|
|
618
|
+
*
|
|
619
|
+
* MKV supports AAC, Opus, Vorbis, FLAC, MP3, AC3, and many other audio codecs.
|
|
620
|
+
*/
|
|
621
|
+
addAudioTrack(config: MkvAudioTrackConfig): void
|
|
622
|
+
/** Add an encoded video chunk to the muxer */
|
|
623
|
+
addVideoChunk(chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadataJs | undefined | null): void
|
|
624
|
+
/** Add an encoded audio chunk to the muxer */
|
|
625
|
+
addAudioChunk(chunk: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadataJs | undefined | null): void
|
|
626
|
+
/** Flush any buffered data */
|
|
627
|
+
flush(): void
|
|
628
|
+
/** Finalize the muxer and return the MKV data */
|
|
629
|
+
finalize(): Uint8Array
|
|
630
|
+
/**
|
|
631
|
+
* Read available data from streaming buffer (streaming mode only)
|
|
632
|
+
*
|
|
633
|
+
* Returns available data, or null if no data is ready yet.
|
|
634
|
+
* Returns empty Uint8Array when streaming is finished.
|
|
635
|
+
*/
|
|
636
|
+
read(): Uint8Array | null
|
|
637
|
+
/** Check if muxer is in streaming mode */
|
|
638
|
+
get isStreaming(): boolean
|
|
639
|
+
/** Check if streaming is finished (streaming mode only) */
|
|
640
|
+
get isFinished(): boolean
|
|
641
|
+
/** Close the muxer and release resources */
|
|
642
|
+
close(): void
|
|
643
|
+
/** Get the current state of the muxer */
|
|
644
|
+
get state(): string
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* MP4 Demuxer for reading encoded video and audio from MP4 container
|
|
649
|
+
*
|
|
650
|
+
* Usage:
|
|
651
|
+
* ```javascript
|
|
652
|
+
* const demuxer = new Mp4Demuxer({
|
|
653
|
+
* videoOutput: (chunk) => videoDecoder.decode(chunk),
|
|
654
|
+
* audioOutput: (chunk) => audioDecoder.decode(chunk),
|
|
655
|
+
* error: (err) => console.error(err)
|
|
656
|
+
* });
|
|
657
|
+
*
|
|
658
|
+
* await demuxer.load('./video.mp4');
|
|
659
|
+
*
|
|
660
|
+
* // Get decoder configs
|
|
661
|
+
* const videoConfig = demuxer.videoDecoderConfig;
|
|
662
|
+
* const audioConfig = demuxer.audioDecoderConfig;
|
|
663
|
+
*
|
|
664
|
+
* // Configure decoders
|
|
665
|
+
* videoDecoder.configure(videoConfig);
|
|
666
|
+
* audioDecoder.configure(audioConfig);
|
|
667
|
+
*
|
|
668
|
+
* // Start demuxing
|
|
669
|
+
* demuxer.demux();
|
|
670
|
+
*
|
|
671
|
+
* // Seek to 5 seconds
|
|
672
|
+
* demuxer.seek(5_000_000);
|
|
673
|
+
*
|
|
674
|
+
* demuxer.close();
|
|
675
|
+
* ```
|
|
676
|
+
*/
|
|
677
|
+
export declare class Mp4Demuxer {
|
|
678
|
+
/** Create a new MP4 demuxer */
|
|
679
|
+
constructor(init: Mp4DemuxerInit)
|
|
680
|
+
/** Load an MP4 file from a path */
|
|
681
|
+
load(path: string): Promise<void>
|
|
682
|
+
/**
|
|
683
|
+
* Load an MP4 from a buffer
|
|
684
|
+
*
|
|
685
|
+
* This method uses zero-copy buffer loading - the Uint8Array data is passed
|
|
686
|
+
* directly to the demuxer without an intermediate copy.
|
|
687
|
+
*/
|
|
688
|
+
loadBuffer(data: Uint8Array): Promise<void>
|
|
689
|
+
/** Get all tracks */
|
|
690
|
+
get tracks(): Array<DemuxerTrackInfo>
|
|
691
|
+
/** Get container duration in microseconds */
|
|
692
|
+
get duration(): number | null
|
|
693
|
+
/** Get video decoder configuration for the selected video track */
|
|
694
|
+
get videoDecoderConfig(): DemuxerVideoDecoderConfig | null
|
|
695
|
+
/** Get audio decoder configuration for the selected audio track */
|
|
696
|
+
get audioDecoderConfig(): DemuxerAudioDecoderConfig | null
|
|
697
|
+
/** Select a video track by index */
|
|
698
|
+
selectVideoTrack(trackIndex: number): void
|
|
699
|
+
/** Select an audio track by index */
|
|
700
|
+
selectAudioTrack(trackIndex: number): void
|
|
701
|
+
/**
|
|
702
|
+
* Start demuxing packets
|
|
703
|
+
*
|
|
704
|
+
* If count is specified, reads up to that many packets.
|
|
705
|
+
* Otherwise, reads all packets until end of stream.
|
|
706
|
+
*/
|
|
707
|
+
demux(count?: number | undefined | null): void
|
|
708
|
+
/** Seek to a timestamp in microseconds */
|
|
709
|
+
seek(timestampUs: number): void
|
|
710
|
+
/** Close the demuxer and release resources */
|
|
711
|
+
close(): void
|
|
712
|
+
/** Get the current state of the demuxer */
|
|
713
|
+
get state(): string
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* MP4 Muxer for combining encoded video and audio into MP4 container
|
|
718
|
+
*
|
|
719
|
+
* Usage:
|
|
720
|
+
* ```javascript
|
|
721
|
+
* const muxer = new Mp4Muxer({ fastStart: true });
|
|
722
|
+
* muxer.addVideoTrack({ codec: 'avc1.42001E', width: 1920, height: 1080 });
|
|
723
|
+
* muxer.addAudioTrack({ codec: 'mp4a.40.2', sampleRate: 48000, numberOfChannels: 2 });
|
|
724
|
+
*
|
|
725
|
+
* // Add encoded chunks from VideoEncoder/AudioEncoder
|
|
726
|
+
* encoder.configure({
|
|
727
|
+
* output: (chunk, metadata) => muxer.addVideoChunk(chunk, metadata)
|
|
728
|
+
* });
|
|
729
|
+
*
|
|
730
|
+
* // Finalize and get MP4 data
|
|
731
|
+
* const mp4Data = muxer.finalize();
|
|
732
|
+
* ```
|
|
733
|
+
*/
|
|
734
|
+
export declare class Mp4Muxer {
|
|
735
|
+
/** Create a new MP4 muxer */
|
|
736
|
+
constructor(options?: Mp4MuxerOptions | undefined | null)
|
|
737
|
+
/**
|
|
738
|
+
* Add a video track to the muxer
|
|
739
|
+
*
|
|
740
|
+
* Must be called before adding any chunks.
|
|
741
|
+
*/
|
|
742
|
+
addVideoTrack(config: Mp4VideoTrackConfig): void
|
|
743
|
+
/**
|
|
744
|
+
* Add an audio track to the muxer
|
|
745
|
+
*
|
|
746
|
+
* Must be called before adding any chunks.
|
|
747
|
+
*/
|
|
748
|
+
addAudioTrack(config: Mp4AudioTrackConfig): void
|
|
749
|
+
/**
|
|
750
|
+
* Add an encoded video chunk to the muxer
|
|
751
|
+
*
|
|
752
|
+
* The chunk should come from a VideoEncoder's output callback.
|
|
753
|
+
* If metadata contains decoderConfig.description, it will be used to update
|
|
754
|
+
* the codec extradata (useful for extracting avcC/hvcC from the encoder).
|
|
755
|
+
*/
|
|
756
|
+
addVideoChunk(chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadataJs | undefined | null): void
|
|
757
|
+
/**
|
|
758
|
+
* Add an encoded audio chunk to the muxer
|
|
759
|
+
*
|
|
760
|
+
* The chunk should come from an AudioEncoder's output callback.
|
|
761
|
+
*/
|
|
762
|
+
addAudioChunk(chunk: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadataJs | undefined | null): void
|
|
763
|
+
/** Flush any buffered data */
|
|
764
|
+
flush(): void
|
|
765
|
+
/**
|
|
766
|
+
* Finalize the muxer and return the MP4 data
|
|
767
|
+
*
|
|
768
|
+
* After calling this, no more chunks can be added.
|
|
769
|
+
* Returns the complete MP4 file as a Uint8Array.
|
|
770
|
+
*/
|
|
771
|
+
finalize(): Uint8Array
|
|
772
|
+
/**
|
|
773
|
+
* Read available data from streaming buffer (streaming mode only)
|
|
774
|
+
*
|
|
775
|
+
* Returns available data, or null if no data is ready yet.
|
|
776
|
+
* Returns empty Uint8Array when streaming is finished.
|
|
777
|
+
*/
|
|
778
|
+
read(): Uint8Array | null
|
|
779
|
+
/** Check if muxer is in streaming mode */
|
|
780
|
+
get isStreaming(): boolean
|
|
781
|
+
/** Check if streaming is finished (streaming mode only) */
|
|
782
|
+
get isFinished(): boolean
|
|
783
|
+
/**
|
|
784
|
+
* Close the muxer and release resources
|
|
785
|
+
*
|
|
786
|
+
* This is called automatically when the muxer is garbage collected,
|
|
787
|
+
* but can be called explicitly to release resources early.
|
|
788
|
+
*/
|
|
789
|
+
close(): void
|
|
790
|
+
/** Get the current state of the muxer */
|
|
791
|
+
get state(): string
|
|
792
|
+
}
|
|
793
|
+
|
|
483
794
|
/** Video color space parameters (WebCodecs spec) - as a class per spec */
|
|
484
795
|
export declare class VideoColorSpace {
|
|
485
796
|
/** Create a new VideoColorSpace */
|
|
486
|
-
constructor(init?:
|
|
797
|
+
constructor(init?: VideoColorSpaceInit | undefined | null)
|
|
487
798
|
/** Get color primaries */
|
|
488
799
|
get primaries(): VideoColorPrimaries | null
|
|
489
800
|
/** Get transfer characteristics */
|
|
@@ -539,7 +850,7 @@ export declare class VideoDecoder {
|
|
|
539
850
|
* The dequeue event fires when decodeQueueSize decreases,
|
|
540
851
|
* allowing backpressure management.
|
|
541
852
|
*/
|
|
542
|
-
set ondequeue(callback
|
|
853
|
+
set ondequeue(callback: (() => unknown) | undefined | null)
|
|
543
854
|
/** Get the dequeue event handler (per WebCodecs spec) */
|
|
544
855
|
get ondequeue(): (() => unknown) | null
|
|
545
856
|
/**
|
|
@@ -638,7 +949,7 @@ export declare class VideoEncoder {
|
|
|
638
949
|
* The dequeue event fires when encodeQueueSize decreases,
|
|
639
950
|
* allowing backpressure management.
|
|
640
951
|
*/
|
|
641
|
-
set ondequeue(callback
|
|
952
|
+
set ondequeue(callback: (() => unknown) | undefined | null)
|
|
642
953
|
/** Get the dequeue event handler (per WebCodecs spec) */
|
|
643
954
|
get ondequeue(): (() => unknown) | null
|
|
644
955
|
/** Configure the encoder */
|
|
@@ -780,6 +1091,93 @@ export declare class VideoFrame {
|
|
|
780
1091
|
close(): void
|
|
781
1092
|
}
|
|
782
1093
|
|
|
1094
|
+
/**
|
|
1095
|
+
* WebM Demuxer for reading encoded video and audio from WebM container
|
|
1096
|
+
*
|
|
1097
|
+
* WebM typically contains VP8, VP9, or AV1 video with Opus or Vorbis audio.
|
|
1098
|
+
*/
|
|
1099
|
+
export declare class WebMDemuxer {
|
|
1100
|
+
constructor(init: WebMDemuxerInit)
|
|
1101
|
+
load(path: string): Promise<void>
|
|
1102
|
+
/**
|
|
1103
|
+
* Load a WebM from a buffer
|
|
1104
|
+
*
|
|
1105
|
+
* This method uses zero-copy buffer loading - the Uint8Array data is passed
|
|
1106
|
+
* directly to the demuxer without an intermediate copy.
|
|
1107
|
+
*/
|
|
1108
|
+
loadBuffer(data: Uint8Array): Promise<void>
|
|
1109
|
+
get tracks(): Array<DemuxerTrackInfo>
|
|
1110
|
+
get duration(): number | null
|
|
1111
|
+
get videoDecoderConfig(): DemuxerVideoDecoderConfig | null
|
|
1112
|
+
get audioDecoderConfig(): DemuxerAudioDecoderConfig | null
|
|
1113
|
+
selectVideoTrack(trackIndex: number): void
|
|
1114
|
+
selectAudioTrack(trackIndex: number): void
|
|
1115
|
+
demux(count?: number | undefined | null): void
|
|
1116
|
+
seek(timestampUs: number): void
|
|
1117
|
+
close(): void
|
|
1118
|
+
get state(): string
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* WebM Muxer for combining encoded video and audio into WebM container
|
|
1123
|
+
*
|
|
1124
|
+
* WebM supports VP8, VP9, AV1 video codecs and Opus, Vorbis audio codecs.
|
|
1125
|
+
*
|
|
1126
|
+
* Usage:
|
|
1127
|
+
* ```javascript
|
|
1128
|
+
* const muxer = new WebMMuxer();
|
|
1129
|
+
* muxer.addVideoTrack({ codec: 'vp09.00.10.08', width: 1920, height: 1080 });
|
|
1130
|
+
* muxer.addAudioTrack({ codec: 'opus', sampleRate: 48000, numberOfChannels: 2 });
|
|
1131
|
+
*
|
|
1132
|
+
* // Add encoded chunks from VideoEncoder/AudioEncoder
|
|
1133
|
+
* encoder.configure({
|
|
1134
|
+
* output: (chunk, metadata) => muxer.addVideoChunk(chunk, metadata)
|
|
1135
|
+
* });
|
|
1136
|
+
*
|
|
1137
|
+
* // Finalize and get WebM data
|
|
1138
|
+
* const webmData = muxer.finalize();
|
|
1139
|
+
* ```
|
|
1140
|
+
*/
|
|
1141
|
+
export declare class WebMMuxer {
|
|
1142
|
+
/** Create a new WebM muxer */
|
|
1143
|
+
constructor(options?: WebMMuxerOptions | undefined | null)
|
|
1144
|
+
/**
|
|
1145
|
+
* Add a video track to the muxer
|
|
1146
|
+
*
|
|
1147
|
+
* WebM supports VP8, VP9, and AV1 video codecs.
|
|
1148
|
+
*/
|
|
1149
|
+
addVideoTrack(config: WebMVideoTrackConfig): void
|
|
1150
|
+
/**
|
|
1151
|
+
* Add an audio track to the muxer
|
|
1152
|
+
*
|
|
1153
|
+
* WebM supports Opus and Vorbis audio codecs.
|
|
1154
|
+
*/
|
|
1155
|
+
addAudioTrack(config: WebMAudioTrackConfig): void
|
|
1156
|
+
/** Add an encoded video chunk to the muxer */
|
|
1157
|
+
addVideoChunk(chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadataJs | undefined | null): void
|
|
1158
|
+
/** Add an encoded audio chunk to the muxer */
|
|
1159
|
+
addAudioChunk(chunk: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadataJs | undefined | null): void
|
|
1160
|
+
/** Flush any buffered data */
|
|
1161
|
+
flush(): void
|
|
1162
|
+
/** Finalize the muxer and return the WebM data */
|
|
1163
|
+
finalize(): Uint8Array
|
|
1164
|
+
/**
|
|
1165
|
+
* Read available data from streaming buffer (streaming mode only)
|
|
1166
|
+
*
|
|
1167
|
+
* Returns available data, or null if no data is ready yet.
|
|
1168
|
+
* Returns empty Uint8Array when streaming is finished.
|
|
1169
|
+
*/
|
|
1170
|
+
read(): Uint8Array | null
|
|
1171
|
+
/** Check if muxer is in streaming mode */
|
|
1172
|
+
get isStreaming(): boolean
|
|
1173
|
+
/** Check if streaming is finished (streaming mode only) */
|
|
1174
|
+
get isFinished(): boolean
|
|
1175
|
+
/** Close the muxer and release resources */
|
|
1176
|
+
close(): void
|
|
1177
|
+
/** Get the current state of the muxer */
|
|
1178
|
+
get state(): string
|
|
1179
|
+
}
|
|
1180
|
+
|
|
783
1181
|
/** AAC bitstream format (W3C WebCodecs AAC Registration) */
|
|
784
1182
|
export type AacBitstreamFormat = /** Raw AAC frames - metadata in description */
|
|
785
1183
|
| 'aac'
|
|
@@ -827,6 +1225,18 @@ export interface AudioDecoderAddEventListenerOptions {
|
|
|
827
1225
|
passive?: boolean
|
|
828
1226
|
}
|
|
829
1227
|
|
|
1228
|
+
/** JavaScript-facing audio decoder config type */
|
|
1229
|
+
export interface AudioDecoderConfigJs {
|
|
1230
|
+
/** Codec string */
|
|
1231
|
+
codec?: string
|
|
1232
|
+
/** Sample rate */
|
|
1233
|
+
sampleRate?: number
|
|
1234
|
+
/** Number of channels */
|
|
1235
|
+
numberOfChannels?: number
|
|
1236
|
+
/** Codec-specific description */
|
|
1237
|
+
description?: Uint8Array
|
|
1238
|
+
}
|
|
1239
|
+
|
|
830
1240
|
/** Decoder configuration output (for passing to decoder) */
|
|
831
1241
|
export interface AudioDecoderConfigOutput {
|
|
832
1242
|
/** Codec string */
|
|
@@ -925,6 +1335,50 @@ export type ColorSpaceConversion = /** Apply default color space conversion (spe
|
|
|
925
1335
|
/** No color space conversion */
|
|
926
1336
|
| 'none'
|
|
927
1337
|
|
|
1338
|
+
/** Audio decoder configuration exposed to JavaScript */
|
|
1339
|
+
export interface DemuxerAudioDecoderConfig {
|
|
1340
|
+
/** Codec string */
|
|
1341
|
+
codec: string
|
|
1342
|
+
/** Sample rate */
|
|
1343
|
+
sampleRate: number
|
|
1344
|
+
/** Number of channels */
|
|
1345
|
+
numberOfChannels: number
|
|
1346
|
+
/** Codec-specific description data */
|
|
1347
|
+
description?: Uint8Array
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/** Track information exposed to JavaScript */
|
|
1351
|
+
export interface DemuxerTrackInfo {
|
|
1352
|
+
/** Track index */
|
|
1353
|
+
index: number
|
|
1354
|
+
/** Track type ("video" or "audio") */
|
|
1355
|
+
trackType: string
|
|
1356
|
+
/** Codec string (WebCodecs format) */
|
|
1357
|
+
codec: string
|
|
1358
|
+
/** Duration in microseconds */
|
|
1359
|
+
duration?: number
|
|
1360
|
+
/** Coded width (video only) */
|
|
1361
|
+
codedWidth?: number
|
|
1362
|
+
/** Coded height (video only) */
|
|
1363
|
+
codedHeight?: number
|
|
1364
|
+
/** Sample rate (audio only) */
|
|
1365
|
+
sampleRate?: number
|
|
1366
|
+
/** Number of channels (audio only) */
|
|
1367
|
+
numberOfChannels?: number
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
/** Video decoder configuration exposed to JavaScript */
|
|
1371
|
+
export interface DemuxerVideoDecoderConfig {
|
|
1372
|
+
/** Codec string */
|
|
1373
|
+
codec: string
|
|
1374
|
+
/** Coded width */
|
|
1375
|
+
codedWidth: number
|
|
1376
|
+
/** Coded height */
|
|
1377
|
+
codedHeight: number
|
|
1378
|
+
/** Codec-specific description data (avcC/hvcC) */
|
|
1379
|
+
description?: Uint8Array
|
|
1380
|
+
}
|
|
1381
|
+
|
|
928
1382
|
/** DOMRectInit for specifying regions */
|
|
929
1383
|
export interface DOMRectInit {
|
|
930
1384
|
x?: number
|
|
@@ -939,6 +1393,12 @@ export interface EncodedAudioChunkMetadata {
|
|
|
939
1393
|
decoderConfig?: AudioDecoderConfigOutput
|
|
940
1394
|
}
|
|
941
1395
|
|
|
1396
|
+
/** JavaScript-facing metadata type for audio chunks */
|
|
1397
|
+
export interface EncodedAudioChunkMetadataJs {
|
|
1398
|
+
/** Decoder configuration from encoder */
|
|
1399
|
+
decoderConfig?: AudioDecoderConfigJs
|
|
1400
|
+
}
|
|
1401
|
+
|
|
942
1402
|
/** Type of encoded audio chunk */
|
|
943
1403
|
export type EncodedAudioChunkType = /** Key chunk - can be decoded independently */
|
|
944
1404
|
| 'key'
|
|
@@ -955,6 +1415,14 @@ export interface EncodedVideoChunkMetadata {
|
|
|
955
1415
|
alphaSideData?: Uint8Array
|
|
956
1416
|
}
|
|
957
1417
|
|
|
1418
|
+
/** JavaScript-facing metadata type for video chunks */
|
|
1419
|
+
export interface EncodedVideoChunkMetadataJs {
|
|
1420
|
+
/** Decoder configuration from encoder */
|
|
1421
|
+
decoderConfig?: VideoDecoderConfigJs
|
|
1422
|
+
/** SVC output metadata */
|
|
1423
|
+
svc?: SvcOutputMetadataJs
|
|
1424
|
+
}
|
|
1425
|
+
|
|
958
1426
|
/** Type of encoded video chunk */
|
|
959
1427
|
export type EncodedVideoChunkType = /** Keyframe - can be decoded independently */
|
|
960
1428
|
| 'key'
|
|
@@ -1030,6 +1498,78 @@ export type LatencyMode = /** Optimize for quality (default) */
|
|
|
1030
1498
|
/** Optimize for low latency */
|
|
1031
1499
|
| 'realtime'
|
|
1032
1500
|
|
|
1501
|
+
/** Audio track configuration for MKV muxer */
|
|
1502
|
+
export interface MkvAudioTrackConfig {
|
|
1503
|
+
/** Codec string (e.g., "mp4a.40.2", "opus", "flac", "vorbis", "ac3") */
|
|
1504
|
+
codec: string
|
|
1505
|
+
/** Sample rate in Hz */
|
|
1506
|
+
sampleRate: number
|
|
1507
|
+
/** Number of audio channels */
|
|
1508
|
+
numberOfChannels: number
|
|
1509
|
+
/** Codec-specific description data */
|
|
1510
|
+
description?: Uint8Array
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/** MKV muxer options */
|
|
1514
|
+
export interface MkvMuxerOptions {
|
|
1515
|
+
/** Enable live streaming mode */
|
|
1516
|
+
live?: boolean
|
|
1517
|
+
/** Enable streaming output mode */
|
|
1518
|
+
streaming?: StreamingMuxerOptions
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
/** Video track configuration for MKV muxer */
|
|
1522
|
+
export interface MkvVideoTrackConfig {
|
|
1523
|
+
/** Codec string (e.g., "avc1.42001E", "hev1.1.6.L93.B0", "vp09.00.10.08", "av01.0.04M.08") */
|
|
1524
|
+
codec: string
|
|
1525
|
+
/** Video width in pixels */
|
|
1526
|
+
width: number
|
|
1527
|
+
/** Video height in pixels */
|
|
1528
|
+
height: number
|
|
1529
|
+
/** Codec-specific description data */
|
|
1530
|
+
description?: Uint8Array
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
/** Audio track configuration for MP4 muxer */
|
|
1534
|
+
export interface Mp4AudioTrackConfig {
|
|
1535
|
+
/** Codec string (e.g., "mp4a.40.2" for AAC-LC, "opus") */
|
|
1536
|
+
codec: string
|
|
1537
|
+
/** Sample rate in Hz */
|
|
1538
|
+
sampleRate: number
|
|
1539
|
+
/** Number of audio channels */
|
|
1540
|
+
numberOfChannels: number
|
|
1541
|
+
/** Codec-specific description data (esds for AAC, etc.) */
|
|
1542
|
+
description?: Uint8Array
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
/** MP4 muxer options */
|
|
1546
|
+
export interface Mp4MuxerOptions {
|
|
1547
|
+
/**
|
|
1548
|
+
* Move moov atom to beginning for better streaming (default: false)
|
|
1549
|
+
* Note: Not compatible with streaming output mode
|
|
1550
|
+
*/
|
|
1551
|
+
fastStart?: boolean
|
|
1552
|
+
/**
|
|
1553
|
+
* Use fragmented MP4 for streaming output
|
|
1554
|
+
* When true, uses frag_keyframe+empty_moov+default_base_moof
|
|
1555
|
+
*/
|
|
1556
|
+
fragmented?: boolean
|
|
1557
|
+
/** Enable streaming output mode */
|
|
1558
|
+
streaming?: StreamingMuxerOptions
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
/** Video track configuration for MP4 muxer */
|
|
1562
|
+
export interface Mp4VideoTrackConfig {
|
|
1563
|
+
/** Codec string (e.g., "avc1.42001E", "hev1.1.6.L93.B0", "av01.0.04M.08") */
|
|
1564
|
+
codec: string
|
|
1565
|
+
/** Video width in pixels */
|
|
1566
|
+
width: number
|
|
1567
|
+
/** Video height in pixels */
|
|
1568
|
+
height: number
|
|
1569
|
+
/** Codec-specific description data (avcC/hvcC/av1C from encoder metadata) */
|
|
1570
|
+
description?: Uint8Array
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1033
1573
|
/** Opus application mode (W3C WebCodecs Opus Registration) */
|
|
1034
1574
|
export type OpusApplication = /** Optimize for VoIP (speech intelligibility) */
|
|
1035
1575
|
| 'voip'
|
|
@@ -1094,12 +1634,24 @@ export interface PlaneLayout {
|
|
|
1094
1634
|
*/
|
|
1095
1635
|
export declare function resetHardwareFallbackState(): void
|
|
1096
1636
|
|
|
1637
|
+
/** Streaming mode options for muxers */
|
|
1638
|
+
export interface StreamingMuxerOptions {
|
|
1639
|
+
/** Buffer capacity for streaming output (default: 256KB) */
|
|
1640
|
+
bufferCapacity?: number
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1097
1643
|
/** SVC (Scalable Video Coding) output metadata (W3C WebCodecs spec) */
|
|
1098
1644
|
export interface SvcOutputMetadata {
|
|
1099
1645
|
/** Temporal layer ID for this frame */
|
|
1100
1646
|
temporalLayerId?: number
|
|
1101
1647
|
}
|
|
1102
1648
|
|
|
1649
|
+
/** JavaScript-facing SVC metadata */
|
|
1650
|
+
export interface SvcOutputMetadataJs {
|
|
1651
|
+
/** Temporal layer ID */
|
|
1652
|
+
temporalLayerId?: number
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1103
1655
|
/** Video color primaries (W3C WebCodecs spec) */
|
|
1104
1656
|
export type VideoColorPrimaries = /** BT.709 / sRGB primaries */
|
|
1105
1657
|
| 'bt709'
|
|
@@ -1119,6 +1671,18 @@ export interface VideoDecoderAddEventListenerOptions {
|
|
|
1119
1671
|
passive?: boolean
|
|
1120
1672
|
}
|
|
1121
1673
|
|
|
1674
|
+
/** JavaScript-facing decoder config type */
|
|
1675
|
+
export interface VideoDecoderConfigJs {
|
|
1676
|
+
/** Codec string */
|
|
1677
|
+
codec?: string
|
|
1678
|
+
/** Codec-specific description */
|
|
1679
|
+
description?: Uint8Array
|
|
1680
|
+
/** Coded width */
|
|
1681
|
+
codedWidth?: number
|
|
1682
|
+
/** Coded height */
|
|
1683
|
+
codedHeight?: number
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1122
1686
|
/** Decoder configuration output (for passing to decoder) */
|
|
1123
1687
|
export interface VideoDecoderConfigOutput {
|
|
1124
1688
|
/** Codec string */
|
|
@@ -1325,3 +1889,35 @@ export type VideoTransferCharacteristics = /** BT.709 transfer */
|
|
|
1325
1889
|
| 'pq'
|
|
1326
1890
|
/** Hybrid Log-Gamma (HDR) */
|
|
1327
1891
|
| 'hlg'
|
|
1892
|
+
|
|
1893
|
+
/** Audio track configuration for WebM muxer */
|
|
1894
|
+
export interface WebMAudioTrackConfig {
|
|
1895
|
+
/** Codec string (e.g., "opus", "vorbis") */
|
|
1896
|
+
codec: string
|
|
1897
|
+
/** Sample rate in Hz */
|
|
1898
|
+
sampleRate: number
|
|
1899
|
+
/** Number of audio channels */
|
|
1900
|
+
numberOfChannels: number
|
|
1901
|
+
/** Codec-specific description data */
|
|
1902
|
+
description?: Uint8Array
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
/** WebM muxer options */
|
|
1906
|
+
export interface WebMMuxerOptions {
|
|
1907
|
+
/** Enable live streaming mode (cluster-at-a-time output) */
|
|
1908
|
+
live?: boolean
|
|
1909
|
+
/** Enable streaming output mode */
|
|
1910
|
+
streaming?: StreamingMuxerOptions
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
/** Video track configuration for WebM muxer */
|
|
1914
|
+
export interface WebMVideoTrackConfig {
|
|
1915
|
+
/** Codec string (e.g., "vp8", "vp09.00.10.08", "av01.0.04M.08") */
|
|
1916
|
+
codec: string
|
|
1917
|
+
/** Video width in pixels */
|
|
1918
|
+
width: number
|
|
1919
|
+
/** Video height in pixels */
|
|
1920
|
+
height: number
|
|
1921
|
+
/** Codec-specific description data */
|
|
1922
|
+
description?: Uint8Array
|
|
1923
|
+
}
|