@napi-rs/webcodecs 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +17 -0
  2. package/index.d.ts +61 -190
  3. package/index.js +196 -85
  4. package/package.json +39 -53
package/README.md CHANGED
@@ -168,6 +168,11 @@ result.image.close()
168
168
  decoder.close()
169
169
  ```
170
170
 
171
+ When `data` is a `ReadableStream`, `ImageDecoder` accumulates every chunk so it
172
+ can re-probe the growing input. This buffer currently has no fixed limit, so
173
+ applications should bound or reject unexpectedly large streams before passing
174
+ them to the decoder.
175
+
171
176
  ### Container Demuxing
172
177
 
173
178
  Read encoded video/audio from MP4, WebM, or MKV containers:
@@ -283,6 +288,7 @@ import { Mp4Muxer } from '@napi-rs/webcodecs'
283
288
 
284
289
  const muxer = new Mp4Muxer({
285
290
  fragmented: true, // Required for MP4 streaming
291
+ // Maximum bytes returned by each read(); this is not a memory limit.
286
292
  streaming: { bufferCapacity: 256 * 1024 },
287
293
  })
288
294
 
@@ -303,6 +309,12 @@ if (muxer.isFinished) {
303
309
  }
304
310
  ```
305
311
 
312
+ Streaming writes are queued in a growable native buffer so `addVideoChunk()`
313
+ and `addAudioChunk()` never wait for JavaScript to call `read()`. Applications
314
+ must drain `read()` regularly; an indefinitely stalled consumer can retain the
315
+ entire muxed output in memory. `bufferCapacity` controls only the maximum size
316
+ of each returned read chunk.
317
+
306
318
  ### VideoFrame from Canvas
307
319
 
308
320
  Create VideoFrames from `@napi-rs/canvas` for graphics, text rendering, or image compositing:
@@ -683,6 +695,11 @@ For full API documentation, see the [W3C WebCodecs specification](https://w3c.gi
683
695
  - Node.js 18+
684
696
  - pnpm
685
697
 
698
+ The build downloads the pinned FFmpeg 9.0 release by default. If you opt out
699
+ of that download or set `FFMPEG_DIR`, the supplied FFmpeg headers and libraries
700
+ must be from FFmpeg 9.x; FFmpeg 8.x system/Homebrew installations are rejected
701
+ by the ABI guard.
702
+
686
703
  ### Build
687
704
 
688
705
  ```bash
package/index.d.ts CHANGED
@@ -111,32 +111,6 @@ export interface MuxerAudioTrackConfig {
111
111
  description?: Uint8Array
112
112
  }
113
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
-
140
114
  // ============================================================================
141
115
  // Async Iterator Types
142
116
  // ============================================================================
@@ -203,6 +177,7 @@ export type TypedArray =
203
177
  | Float64Array
204
178
  | BigInt64Array
205
179
  | BigUint64Array
180
+
206
181
  /**
207
182
  * AudioData - represents uncompressed audio data
208
183
  *
@@ -296,7 +271,7 @@ export declare class AudioDecoder {
296
271
  *
297
272
  * @param init - Init dictionary containing output and error callbacks
298
273
  */
299
- constructor(init: { output: (data: AudioData) => void; error: (error: Error) => void })
274
+ constructor(init: { output: (data: AudioData) => void; error: (error: DOMException) => void })
300
275
  /** Get decoder state */
301
276
  get state(): CodecState
302
277
  /** Get number of pending decode operations (per WebCodecs spec) */
@@ -307,9 +282,9 @@ export declare class AudioDecoder {
307
282
  * The dequeue event fires when decodeQueueSize decreases,
308
283
  * allowing backpressure management.
309
284
  */
310
- set ondequeue(callback: (() => unknown) | undefined | null)
285
+ set ondequeue(callback: ((event: Event) => unknown) | undefined | null)
311
286
  /** Get the dequeue event handler (per WebCodecs spec) */
312
- get ondequeue(): (() => unknown) | null
287
+ get ondequeue(): ((event: Event) => unknown) | null
313
288
  /** Configure the decoder */
314
289
  configure(config: AudioDecoderConfig): void
315
290
  /** Decode an encoded audio chunk */
@@ -335,16 +310,19 @@ export declare class AudioDecoder {
335
310
  * returns { supported: false } for valid but unsupported configs.
336
311
  */
337
312
  static isConfigSupported(config: AudioDecoderConfig): Promise<AudioDecoderSupport>
338
- /** Add an event listener for the specified event type */
313
+ /**
314
+ * Add an event listener for the specified event type
315
+ * Uses separate RwLock to avoid blocking on decode operations
316
+ */
339
317
  addEventListener(
340
318
  eventType: string,
341
- callback: () => unknown,
319
+ callback: (event: Event) => unknown,
342
320
  options?: AudioDecoderAddEventListenerOptions | undefined | null,
343
321
  ): void
344
322
  /** Remove an event listener for the specified event type */
345
323
  removeEventListener(
346
324
  eventType: string,
347
- callback: () => unknown,
325
+ callback: (event: Event) => unknown,
348
326
  options?: AudioDecoderEventListenerOptions | undefined | null,
349
327
  ): void
350
328
  /** Dispatch an event to all registered listeners */
@@ -383,7 +361,7 @@ export declare class AudioEncoder {
383
361
  */
384
362
  constructor(init: {
385
363
  output: (chunk: EncodedAudioChunk, metadata?: EncodedAudioChunkMetadata) => void
386
- error: (error: Error) => void
364
+ error: (error: DOMException) => void
387
365
  })
388
366
  /** Get encoder state */
389
367
  get state(): CodecState
@@ -395,9 +373,9 @@ export declare class AudioEncoder {
395
373
  * The dequeue event fires when encodeQueueSize decreases,
396
374
  * allowing backpressure management.
397
375
  */
398
- set ondequeue(callback: (() => unknown) | undefined | null)
376
+ set ondequeue(callback: ((event: Event) => unknown) | undefined | null)
399
377
  /** Get the dequeue event handler (per WebCodecs spec) */
400
- get ondequeue(): (() => unknown) | null
378
+ get ondequeue(): ((event: Event) => unknown) | null
401
379
  /** Configure the encoder */
402
380
  configure(config: AudioEncoderConfig): void
403
381
  /** Encode audio data */
@@ -429,13 +407,13 @@ export declare class AudioEncoder {
429
407
  */
430
408
  addEventListener(
431
409
  eventType: string,
432
- callback: () => unknown,
410
+ callback: (event: Event) => unknown,
433
411
  options?: AudioEncoderAddEventListenerOptions | undefined | null,
434
412
  ): void
435
413
  /** Remove an event listener for the specified event type */
436
414
  removeEventListener(
437
415
  eventType: string,
438
- callback: () => unknown,
416
+ callback: (event: Event) => unknown,
439
417
  options?: AudioEncoderEventListenerOptions | undefined | null,
440
418
  ): void
441
419
  /** Dispatch an event to all registered listeners */
@@ -539,7 +517,8 @@ export declare class EncodedVideoChunk {
539
517
  export declare class ImageDecoder {
540
518
  /**
541
519
  * Create a new ImageDecoder
542
- * Supports both Uint8Array and ReadableStream as data source per W3C spec
520
+ * Supports both Uint8Array and ReadableStream as data source per W3C spec.
521
+ * ReadableStream input is buffered without a fixed size limit.
543
522
  */
544
523
  constructor(init: ImageDecoderInit)
545
524
  /** Whether the data is fully buffered */
@@ -919,7 +898,7 @@ export declare class VideoDecoder {
919
898
  *
920
899
  * @param init - Init dictionary containing output and error callbacks
921
900
  */
922
- constructor(init: { output: (frame: VideoFrame) => void; error: (error: Error) => void })
901
+ constructor(init: { output: (frame: VideoFrame) => void; error: (error: DOMException) => void })
923
902
  /** Get decoder state */
924
903
  get state(): CodecState
925
904
  /** Get number of pending decode operations (per WebCodecs spec) */
@@ -930,9 +909,9 @@ export declare class VideoDecoder {
930
909
  * The dequeue event fires when decodeQueueSize decreases,
931
910
  * allowing backpressure management.
932
911
  */
933
- set ondequeue(callback: (() => unknown) | undefined | null)
912
+ set ondequeue(callback: ((event: Event) => unknown) | undefined | null)
934
913
  /** Get the dequeue event handler (per WebCodecs spec) */
935
- get ondequeue(): (() => unknown) | null
914
+ get ondequeue(): ((event: Event) => unknown) | null
936
915
  /**
937
916
  * Configure the decoder
938
917
  *
@@ -971,13 +950,13 @@ export declare class VideoDecoder {
971
950
  */
972
951
  addEventListener(
973
952
  eventType: string,
974
- callback: () => unknown,
953
+ callback: (event: Event) => unknown,
975
954
  options?: VideoDecoderAddEventListenerOptions | undefined | null,
976
955
  ): void
977
956
  /** Remove an event listener for the specified event type */
978
957
  removeEventListener(
979
958
  eventType: string,
980
- callback: () => unknown,
959
+ callback: (event: Event) => unknown,
981
960
  options?: VideoDecoderEventListenerOptions | undefined | null,
982
961
  ): void
983
962
  /** Dispatch an event to all registered listeners */
@@ -1017,7 +996,7 @@ export declare class VideoEncoder {
1017
996
  */
1018
997
  constructor(init: {
1019
998
  output: (chunk: EncodedVideoChunk, metadata?: EncodedVideoChunkMetadata) => void
1020
- error: (error: Error) => void
999
+ error: (error: DOMException) => void
1021
1000
  })
1022
1001
  /** Get encoder state */
1023
1002
  get state(): CodecState
@@ -1029,9 +1008,9 @@ export declare class VideoEncoder {
1029
1008
  * The dequeue event fires when encodeQueueSize decreases,
1030
1009
  * allowing backpressure management.
1031
1010
  */
1032
- set ondequeue(callback: (() => unknown) | undefined | null)
1011
+ set ondequeue(callback: ((event: Event) => unknown) | undefined | null)
1033
1012
  /** Get the dequeue event handler (per WebCodecs spec) */
1034
- get ondequeue(): (() => unknown) | null
1013
+ get ondequeue(): ((event: Event) => unknown) | null
1035
1014
  /** Configure the encoder */
1036
1015
  configure(config: VideoEncoderConfig): void
1037
1016
  /** Encode a frame */
@@ -1055,13 +1034,13 @@ export declare class VideoEncoder {
1055
1034
  */
1056
1035
  addEventListener(
1057
1036
  eventType: string,
1058
- callback: () => unknown,
1037
+ callback: (event: Event) => unknown,
1059
1038
  options?: AddEventListenerOptions | undefined | null,
1060
1039
  ): void
1061
1040
  /** Remove an event listener for the specified event type */
1062
1041
  removeEventListener(
1063
1042
  eventType: string,
1064
- callback: () => unknown,
1043
+ callback: (event: Event) => unknown,
1065
1044
  options?: EventListenerOptions | undefined | null,
1066
1045
  ): void
1067
1046
  /** Dispatch an event to all registered listeners */
@@ -1271,10 +1250,7 @@ export declare class WebMMuxer {
1271
1250
  }
1272
1251
 
1273
1252
  /** AAC bitstream format (W3C WebCodecs AAC Registration) */
1274
- export type AacBitstreamFormat = /** Raw AAC frames - metadata in description */
1275
- | 'aac'
1276
- /** ADTS frames - metadata in each frame */
1277
- | 'adts'
1253
+ export type AacBitstreamFormat = 'aac' | 'adts'
1278
1254
 
1279
1255
  /** AAC encoder configuration (W3C WebCodecs AAC Registration) */
1280
1256
  export interface AacEncoderConfig {
@@ -1293,10 +1269,7 @@ export interface AddEventListenerOptions {
1293
1269
  * Alpha channel handling option (W3C WebCodecs spec)
1294
1270
  * Default is "discard" per spec
1295
1271
  */
1296
- export type AlphaOption = /** Keep alpha channel if present */
1297
- | 'keep'
1298
- /** Discard alpha channel (default per W3C spec) */
1299
- | 'discard'
1272
+ export type AlphaOption = 'keep' | 'discard'
1300
1273
 
1301
1274
  /** Options for copyTo operation */
1302
1275
  export interface AudioDataCopyToOptions {
@@ -1378,28 +1351,10 @@ export interface AudioEncoderSupport {
1378
1351
  }
1379
1352
 
1380
1353
  /** Audio sample format (WebCodecs spec) */
1381
- export type AudioSampleFormat = /** Unsigned 8-bit integer samples| interleaved */
1382
- | 'u8'
1383
- /** Signed 16-bit integer samples| interleaved */
1384
- | 's16'
1385
- /** Signed 32-bit integer samples| interleaved */
1386
- | 's32'
1387
- /** 32-bit float samples| interleaved */
1388
- | 'f32'
1389
- /** Unsigned 8-bit integer samples| planar */
1390
- | 'u8-planar'
1391
- /** Signed 16-bit integer samples| planar */
1392
- | 's16-planar'
1393
- /** Signed 32-bit integer samples| planar */
1394
- | 's32-planar'
1395
- /** 32-bit float samples| planar */
1396
- | 'f32-planar'
1354
+ export type AudioSampleFormat = 'u8' | 's16' | 's32' | 'f32' | 'u8-planar' | 's16-planar' | 's32-planar' | 'f32-planar'
1397
1355
 
1398
1356
  /** AVC (H.264) bitstream format (W3C WebCodecs AVC Registration) */
1399
- export type AvcBitstreamFormat = /** AVC format with parameter sets in description (ISO 14496-15) */
1400
- | 'avc'
1401
- /** Annex B format with parameter sets in bitstream */
1402
- | 'annexb'
1357
+ export type AvcBitstreamFormat = 'avc' | 'annexb'
1403
1358
 
1404
1359
  /** AVC (H.264) encoder configuration (W3C WebCodecs AVC Registration) */
1405
1360
  export interface AvcEncoderConfig {
@@ -1408,24 +1363,13 @@ export interface AvcEncoderConfig {
1408
1363
  }
1409
1364
 
1410
1365
  /** Bitrate mode for audio encoding (W3C WebCodecs spec) */
1411
- export type BitrateMode = /** Variable bitrate (default) */
1412
- | 'variable'
1413
- /** Constant bitrate */
1414
- | 'constant'
1366
+ export type BitrateMode = 'variable' | 'constant'
1415
1367
 
1416
1368
  /** Encoder state per WebCodecs spec */
1417
- export type CodecState = /** Encoder not configured */
1418
- | 'unconfigured'
1419
- /** Encoder configured and ready */
1420
- | 'configured'
1421
- /** Encoder closed */
1422
- | 'closed'
1369
+ export type CodecState = 'unconfigured' | 'configured' | 'closed'
1423
1370
 
1424
1371
  /** ColorSpaceConversion for ImageDecoder (W3C WebCodecs spec) */
1425
- export type ColorSpaceConversion = /** Apply default color space conversion (spec default) */
1426
- | 'default'
1427
- /** No color space conversion */
1428
- | 'none'
1372
+ export type ColorSpaceConversion = 'default' | 'none'
1429
1373
 
1430
1374
  /** Audio decoder configuration exposed to JavaScript */
1431
1375
  export interface DemuxerAudioDecoderConfig {
@@ -1492,10 +1436,7 @@ export interface EncodedAudioChunkMetadataJs {
1492
1436
  }
1493
1437
 
1494
1438
  /** Type of encoded audio chunk */
1495
- export type EncodedAudioChunkType = /** Key chunk - can be decoded independently */
1496
- | 'key'
1497
- /** Delta chunk - depends on previous chunks */
1498
- | 'delta'
1439
+ export type EncodedAudioChunkType = 'key' | 'delta'
1499
1440
 
1500
1441
  /** Output callback metadata per WebCodecs spec */
1501
1442
  export interface EncodedVideoChunkMetadata {
@@ -1522,10 +1463,7 @@ export interface EncodedVideoChunkMetadataJs {
1522
1463
  }
1523
1464
 
1524
1465
  /** Type of encoded video chunk */
1525
- export type EncodedVideoChunkType = /** Keyframe - can be decoded independently */
1526
- | 'key'
1527
- /** Delta frame - depends on previous frames */
1528
- | 'delta'
1466
+ export type EncodedVideoChunkType = 'key' | 'delta'
1529
1467
 
1530
1468
  /** Options for removeEventListener (W3C DOM spec) */
1531
1469
  export interface EventListenerOptions {
@@ -1550,12 +1488,7 @@ export declare function getHardwareAccelerators(): Array<HardwareAccelerator>
1550
1488
  export declare function getPreferredHardwareAccelerator(): string | null
1551
1489
 
1552
1490
  /** Hardware acceleration preference (W3C WebCodecs spec) */
1553
- export type HardwareAcceleration = /** No preference - may use hardware or software */
1554
- | 'no-preference'
1555
- /** Prefer hardware acceleration */
1556
- | 'prefer-hardware'
1557
- /** Prefer software implementation */
1558
- | 'prefer-software'
1491
+ export type HardwareAcceleration = 'no-preference' | 'prefer-hardware' | 'prefer-software'
1559
1492
 
1560
1493
  /** Hardware accelerator information */
1561
1494
  export interface HardwareAccelerator {
@@ -1568,10 +1501,7 @@ export interface HardwareAccelerator {
1568
1501
  }
1569
1502
 
1570
1503
  /** HEVC (H.265) bitstream format (W3C WebCodecs HEVC Registration) */
1571
- export type HevcBitstreamFormat = /** HEVC format with parameter sets in description (ISO 14496-15) */
1572
- | 'hevc'
1573
- /** Annex B format with parameter sets in bitstream */
1574
- | 'annexb'
1504
+ export type HevcBitstreamFormat = 'hevc' | 'annexb'
1575
1505
 
1576
1506
  /** HEVC (H.265) encoder configuration (W3C WebCodecs HEVC Registration) */
1577
1507
  export interface HevcEncoderConfig {
@@ -1579,6 +1509,9 @@ export interface HevcEncoderConfig {
1579
1509
  format?: HevcBitstreamFormat
1580
1510
  }
1581
1511
 
1512
+ /** HEVC sample-entry override for the MP4 muxer */
1513
+ export type HevcSampleEntryJs = 'hvc1' | 'hev1'
1514
+
1582
1515
  /** Image decode options */
1583
1516
  export interface ImageDecodeOptions {
1584
1517
  /** Frame index to decode (for animated images) */
@@ -1591,10 +1524,7 @@ export interface ImageDecodeOptions {
1591
1524
  export declare function isHardwareAcceleratorAvailable(name: string): boolean
1592
1525
 
1593
1526
  /** Latency mode for video encoding (W3C WebCodecs spec) */
1594
- export type LatencyMode = /** Optimize for quality (default) */
1595
- | 'quality'
1596
- /** Optimize for low latency */
1597
- | 'realtime'
1527
+ export type LatencyMode = 'quality' | 'realtime'
1598
1528
 
1599
1529
  /** Audio track configuration for MKV muxer */
1600
1530
  export interface MkvAudioTrackConfig {
@@ -1670,21 +1600,20 @@ export interface Mp4VideoTrackConfig {
1670
1600
  framerate?: number
1671
1601
  /** Codec-specific description data (avcC/hvcC/av1C from encoder metadata) */
1672
1602
  description?: Uint8Array
1603
+ /**
1604
+ * HEVC sample-entry override. Default picks "hvc1" when the hvcC
1605
+ * description is well-formed, single-layer, and complete; "hev1" permits
1606
+ * in-band parameter sets (e.g. remuxing hev1 streams with parameter-set
1607
+ * updates); "hvc1" forces the tag and requires a qualifying description.
1608
+ */
1609
+ sampleEntry?: HevcSampleEntryJs
1673
1610
  }
1674
1611
 
1675
1612
  /** Opus application mode (W3C WebCodecs Opus Registration) */
1676
- export type OpusApplication = /** Optimize for VoIP (speech intelligibility) */
1677
- | 'voip'
1678
- /** Optimize for audio fidelity (default) */
1679
- | 'audio'
1680
- /** Minimize coding delay */
1681
- | 'lowdelay'
1613
+ export type OpusApplication = 'voip' | 'audio' | 'lowdelay'
1682
1614
 
1683
1615
  /** Opus bitstream format (W3C WebCodecs Opus Registration) */
1684
- export type OpusBitstreamFormat = /** Opus packets (RFC 6716) - no metadata needed for decoding */
1685
- | 'opus'
1686
- /** Ogg encapsulation (RFC 7845) - metadata in description */
1687
- | 'ogg'
1616
+ export type OpusBitstreamFormat = 'opus' | 'ogg'
1688
1617
 
1689
1618
  /** Opus encoder configuration (W3C WebCodecs Opus Registration) */
1690
1619
  export interface OpusEncoderConfig {
@@ -1710,12 +1639,7 @@ export interface OpusEncoderConfig {
1710
1639
  }
1711
1640
 
1712
1641
  /** Opus signal type hint (W3C WebCodecs Opus Registration) */
1713
- export type OpusSignal = /** Auto-detect signal type */
1714
- | 'auto'
1715
- /** Music signal */
1716
- | 'music'
1717
- /** Voice/speech signal */
1718
- | 'voice'
1642
+ export type OpusSignal = 'auto' | 'music' | 'voice'
1719
1643
 
1720
1644
  /** Layout information for a single plane per WebCodecs spec */
1721
1645
  export interface PlaneLayout {
@@ -1738,7 +1662,10 @@ export declare function resetHardwareFallbackState(): void
1738
1662
 
1739
1663
  /** Streaming mode options for muxers */
1740
1664
  export interface StreamingMuxerOptions {
1741
- /** Buffer capacity for streaming output (default: 256KB) */
1665
+ /**
1666
+ * Maximum bytes returned by each streaming read (default: 256KB).
1667
+ * Muxer writes are queued without blocking the JavaScript consumer.
1668
+ */
1742
1669
  bufferCapacity?: number
1743
1670
  }
1744
1671
 
@@ -1755,16 +1682,7 @@ export interface SvcOutputMetadataJs {
1755
1682
  }
1756
1683
 
1757
1684
  /** Video color primaries (W3C WebCodecs spec) */
1758
- export type VideoColorPrimaries = /** BT.709 / sRGB primaries */
1759
- | 'bt709'
1760
- /** BT.470 BG (PAL) */
1761
- | 'bt470bg'
1762
- /** SMPTE 170M (NTSC) */
1763
- | 'smpte170m'
1764
- /** BT.2020 (UHD) */
1765
- | 'bt2020'
1766
- /** SMPTE 432 (DCI-P3) */
1767
- | 'smpte432'
1685
+ export type VideoColorPrimaries = 'bt709' | 'bt470bg' | 'smpte170m' | 'bt2020' | 'smpte432'
1768
1686
 
1769
1687
  /** Options for addEventListener (W3C DOM spec) */
1770
1688
  export interface VideoDecoderAddEventListenerOptions {
@@ -1821,12 +1739,7 @@ export interface VideoDecoderSupport {
1821
1739
  }
1822
1740
 
1823
1741
  /** Bitrate mode for video encoding (W3C WebCodecs spec) */
1824
- export type VideoEncoderBitrateMode = /** Variable bitrate (default) */
1825
- | 'variable'
1826
- /** Constant bitrate */
1827
- | 'constant'
1828
- /** Use quantizer parameter from codec-specific options */
1829
- | 'quantizer'
1742
+ export type VideoEncoderBitrateMode = 'variable' | 'constant' | 'quantizer'
1830
1743
 
1831
1744
  /** Encode options per WebCodecs spec */
1832
1745
  export interface VideoEncoderEncodeOptions {
@@ -1921,76 +1834,34 @@ export interface VideoFrameRect {
1921
1834
  }
1922
1835
 
1923
1836
  /** Video matrix coefficients (W3C WebCodecs spec) */
1924
- export type VideoMatrixCoefficients = /** RGB (identity matrix) */
1925
- | 'rgb'
1926
- /** BT.709 */
1927
- | 'bt709'
1928
- /** BT.470 BG */
1929
- | 'bt470bg'
1930
- /** SMPTE 170M */
1931
- | 'smpte170m'
1932
- /** BT.2020 non-constant luminance */
1933
- | 'bt2020-ncl'
1837
+ export type VideoMatrixCoefficients = 'rgb' | 'bt709' | 'bt470bg' | 'smpte170m' | 'bt2020-ncl'
1934
1838
 
1935
1839
  /** Video pixel format (WebCodecs spec) */
1936
- export type VideoPixelFormat = /** Planar YUV 4:2:0| 12bpp| (1 Cr & Cb sample per 2x2 Y samples) */
1840
+ export type VideoPixelFormat =
1937
1841
  | 'I420'
1938
- /** Planar YUV 4:2:0| 12bpp| with alpha plane */
1939
1842
  | 'I420A'
1940
- /** Planar YUV 4:2:2| 16bpp */
1941
1843
  | 'I422'
1942
- /** Planar YUV 4:2:2| 16bpp| with alpha plane */
1943
1844
  | 'I422A'
1944
- /** Planar YUV 4:4:4| 24bpp */
1945
1845
  | 'I444'
1946
- /** Planar YUV 4:4:4| 24bpp| with alpha plane */
1947
1846
  | 'I444A'
1948
- /** Planar YUV 4:2:0| 10-bit */
1949
1847
  | 'I420P10'
1950
- /** Planar YUV 4:2:0| 10-bit| with alpha plane */
1951
1848
  | 'I420AP10'
1952
- /** Planar YUV 4:2:2| 10-bit */
1953
1849
  | 'I422P10'
1954
- /** Planar YUV 4:2:2| 10-bit| with alpha plane */
1955
1850
  | 'I422AP10'
1956
- /** Planar YUV 4:4:4| 10-bit */
1957
1851
  | 'I444P10'
1958
- /** Planar YUV 4:4:4| 10-bit| with alpha plane */
1959
1852
  | 'I444AP10'
1960
- /** Planar YUV 4:2:0| 12-bit */
1961
1853
  | 'I420P12'
1962
- /** Planar YUV 4:2:2| 12-bit */
1963
1854
  | 'I422P12'
1964
- /** Planar YUV 4:4:4| 12-bit */
1965
1855
  | 'I444P12'
1966
- /** Semi-planar YUV 4:2:0| 12bpp (Y plane + interleaved UV) */
1967
1856
  | 'NV12'
1968
- /** Semi-planar YUV 4:2:0| 12bpp (Y plane + interleaved VU) - per W3C WebCodecs spec */
1969
1857
  | 'NV21'
1970
- /** RGBA 32bpp */
1971
1858
  | 'RGBA'
1972
- /** RGBX 32bpp (alpha ignored) */
1973
1859
  | 'RGBX'
1974
- /** BGRA 32bpp */
1975
1860
  | 'BGRA'
1976
- /** BGRX 32bpp (alpha ignored) */
1977
1861
  | 'BGRX'
1978
1862
 
1979
1863
  /** Video transfer characteristics (W3C WebCodecs spec) */
1980
- export type VideoTransferCharacteristics = /** BT.709 transfer */
1981
- | 'bt709'
1982
- /** SMPTE 170M transfer */
1983
- | 'smpte170m'
1984
- /** IEC 61966-2-1 (sRGB) - technical name */
1985
- | 'iec61966-2-1'
1986
- /** sRGB transfer (alias for iec61966-2-1) */
1987
- | 'srgb'
1988
- /** Linear transfer */
1989
- | 'linear'
1990
- /** Perceptual Quantizer (HDR) */
1991
- | 'pq'
1992
- /** Hybrid Log-Gamma (HDR) */
1993
- | 'hlg'
1864
+ export type VideoTransferCharacteristics = 'bt709' | 'smpte170m' | 'iec61966-2-1' | 'srgb' | 'linear' | 'pq' | 'hlg'
1994
1865
 
1995
1866
  /** Audio track configuration for WebM muxer */
1996
1867
  export interface WebMAudioTrackConfig {
package/index.js CHANGED
@@ -1,9 +1,8 @@
1
- // prettier-ignore
2
1
  /* eslint-disable */
3
2
  // @ts-nocheck
4
3
  /* auto-generated by NAPI-RS */
5
4
 
6
- const { readFileSync } = require('node:fs')
5
+ const { readFileSync } = require('fs')
7
6
  let nativeBinding = null
8
7
  const loadErrors = []
9
8
 
@@ -33,7 +32,7 @@ const isMuslFromFilesystem = () => {
33
32
 
34
33
  const isMuslFromReport = () => {
35
34
  let report = null
36
- if (typeof process.report?.getReport === 'function') {
35
+ if (process.report && typeof process.report.getReport === 'function') {
37
36
  process.report.excludeNetwork = true
38
37
  report = process.report.getReport()
39
38
  }
@@ -78,12 +77,12 @@ function requireNative() {
78
77
  const binding = require('@napi-rs/webcodecs-android-arm64')
79
78
  const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm64/package.json').version
80
79
  if (
81
- bindingPackageVersion !== '1.3.1' &&
80
+ bindingPackageVersion !== '1.4.1' &&
82
81
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
83
82
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
84
83
  ) {
85
84
  throw new Error(
86
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
85
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
87
86
  )
88
87
  }
89
88
  return binding
@@ -100,12 +99,12 @@ function requireNative() {
100
99
  const binding = require('@napi-rs/webcodecs-android-arm-eabi')
101
100
  const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm-eabi/package.json').version
102
101
  if (
103
- bindingPackageVersion !== '1.3.1' &&
102
+ bindingPackageVersion !== '1.4.1' &&
104
103
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
105
104
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
106
105
  ) {
107
106
  throw new Error(
108
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
107
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
109
108
  )
110
109
  }
111
110
  return binding
@@ -118,8 +117,8 @@ function requireNative() {
118
117
  } else if (process.platform === 'win32') {
119
118
  if (process.arch === 'x64') {
120
119
  if (
121
- process.config?.variables?.shlib_suffix === 'dll.a' ||
122
- process.config?.variables?.node_target_type === 'shared_library'
120
+ (process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') ||
121
+ (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')
123
122
  ) {
124
123
  try {
125
124
  return require('./webcodecs.win32-x64-gnu.node')
@@ -130,12 +129,12 @@ function requireNative() {
130
129
  const binding = require('@napi-rs/webcodecs-win32-x64-gnu')
131
130
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-gnu/package.json').version
132
131
  if (
133
- bindingPackageVersion !== '1.3.1' &&
132
+ bindingPackageVersion !== '1.4.1' &&
134
133
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
135
134
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
136
135
  ) {
137
136
  throw new Error(
138
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
137
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
139
138
  )
140
139
  }
141
140
  return binding
@@ -152,12 +151,12 @@ function requireNative() {
152
151
  const binding = require('@napi-rs/webcodecs-win32-x64-msvc')
153
152
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-msvc/package.json').version
154
153
  if (
155
- bindingPackageVersion !== '1.3.1' &&
154
+ bindingPackageVersion !== '1.4.1' &&
156
155
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
157
156
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
158
157
  ) {
159
158
  throw new Error(
160
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
159
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
161
160
  )
162
161
  }
163
162
  return binding
@@ -175,12 +174,12 @@ function requireNative() {
175
174
  const binding = require('@napi-rs/webcodecs-win32-ia32-msvc')
176
175
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-ia32-msvc/package.json').version
177
176
  if (
178
- bindingPackageVersion !== '1.3.1' &&
177
+ bindingPackageVersion !== '1.4.1' &&
179
178
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
180
179
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
181
180
  ) {
182
181
  throw new Error(
183
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
182
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
184
183
  )
185
184
  }
186
185
  return binding
@@ -197,12 +196,12 @@ function requireNative() {
197
196
  const binding = require('@napi-rs/webcodecs-win32-arm64-msvc')
198
197
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-arm64-msvc/package.json').version
199
198
  if (
200
- bindingPackageVersion !== '1.3.1' &&
199
+ bindingPackageVersion !== '1.4.1' &&
201
200
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
202
201
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
203
202
  ) {
204
203
  throw new Error(
205
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
204
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
206
205
  )
207
206
  }
208
207
  return binding
@@ -222,12 +221,12 @@ function requireNative() {
222
221
  const binding = require('@napi-rs/webcodecs-darwin-universal')
223
222
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-universal/package.json').version
224
223
  if (
225
- bindingPackageVersion !== '1.3.1' &&
224
+ bindingPackageVersion !== '1.4.1' &&
226
225
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
227
226
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
228
227
  ) {
229
228
  throw new Error(
230
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
229
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
231
230
  )
232
231
  }
233
232
  return binding
@@ -244,12 +243,12 @@ function requireNative() {
244
243
  const binding = require('@napi-rs/webcodecs-darwin-x64')
245
244
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-x64/package.json').version
246
245
  if (
247
- bindingPackageVersion !== '1.3.1' &&
246
+ bindingPackageVersion !== '1.4.1' &&
248
247
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
249
248
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
250
249
  ) {
251
250
  throw new Error(
252
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
251
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
253
252
  )
254
253
  }
255
254
  return binding
@@ -266,12 +265,12 @@ function requireNative() {
266
265
  const binding = require('@napi-rs/webcodecs-darwin-arm64')
267
266
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-arm64/package.json').version
268
267
  if (
269
- bindingPackageVersion !== '1.3.1' &&
268
+ bindingPackageVersion !== '1.4.1' &&
270
269
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
271
270
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
272
271
  ) {
273
272
  throw new Error(
274
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
273
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
275
274
  )
276
275
  }
277
276
  return binding
@@ -292,12 +291,12 @@ function requireNative() {
292
291
  const binding = require('@napi-rs/webcodecs-freebsd-x64')
293
292
  const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-x64/package.json').version
294
293
  if (
295
- bindingPackageVersion !== '1.3.1' &&
294
+ bindingPackageVersion !== '1.4.1' &&
296
295
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
297
296
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
298
297
  ) {
299
298
  throw new Error(
300
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
299
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
301
300
  )
302
301
  }
303
302
  return binding
@@ -314,12 +313,12 @@ function requireNative() {
314
313
  const binding = require('@napi-rs/webcodecs-freebsd-arm64')
315
314
  const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-arm64/package.json').version
316
315
  if (
317
- bindingPackageVersion !== '1.3.1' &&
316
+ bindingPackageVersion !== '1.4.1' &&
318
317
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
319
318
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
320
319
  ) {
321
320
  throw new Error(
322
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
321
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
323
322
  )
324
323
  }
325
324
  return binding
@@ -341,12 +340,12 @@ function requireNative() {
341
340
  const binding = require('@napi-rs/webcodecs-linux-x64-musl')
342
341
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-musl/package.json').version
343
342
  if (
344
- bindingPackageVersion !== '1.3.1' &&
343
+ bindingPackageVersion !== '1.4.1' &&
345
344
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
346
345
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
347
346
  ) {
348
347
  throw new Error(
349
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
348
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
350
349
  )
351
350
  }
352
351
  return binding
@@ -363,12 +362,12 @@ function requireNative() {
363
362
  const binding = require('@napi-rs/webcodecs-linux-x64-gnu')
364
363
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-gnu/package.json').version
365
364
  if (
366
- bindingPackageVersion !== '1.3.1' &&
365
+ bindingPackageVersion !== '1.4.1' &&
367
366
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
368
367
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
369
368
  ) {
370
369
  throw new Error(
371
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
370
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
372
371
  )
373
372
  }
374
373
  return binding
@@ -387,12 +386,12 @@ function requireNative() {
387
386
  const binding = require('@napi-rs/webcodecs-linux-arm64-musl')
388
387
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-musl/package.json').version
389
388
  if (
390
- bindingPackageVersion !== '1.3.1' &&
389
+ bindingPackageVersion !== '1.4.1' &&
391
390
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
392
391
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
393
392
  ) {
394
393
  throw new Error(
395
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
394
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
396
395
  )
397
396
  }
398
397
  return binding
@@ -409,12 +408,12 @@ function requireNative() {
409
408
  const binding = require('@napi-rs/webcodecs-linux-arm64-gnu')
410
409
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-gnu/package.json').version
411
410
  if (
412
- bindingPackageVersion !== '1.3.1' &&
411
+ bindingPackageVersion !== '1.4.1' &&
413
412
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
414
413
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
415
414
  ) {
416
415
  throw new Error(
417
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
416
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
418
417
  )
419
418
  }
420
419
  return binding
@@ -433,12 +432,12 @@ function requireNative() {
433
432
  const binding = require('@napi-rs/webcodecs-linux-arm-musleabihf')
434
433
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-musleabihf/package.json').version
435
434
  if (
436
- bindingPackageVersion !== '1.3.1' &&
435
+ bindingPackageVersion !== '1.4.1' &&
437
436
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
438
437
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
439
438
  ) {
440
439
  throw new Error(
441
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
440
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
442
441
  )
443
442
  }
444
443
  return binding
@@ -455,12 +454,12 @@ function requireNative() {
455
454
  const binding = require('@napi-rs/webcodecs-linux-arm-gnueabihf')
456
455
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-gnueabihf/package.json').version
457
456
  if (
458
- bindingPackageVersion !== '1.3.1' &&
457
+ bindingPackageVersion !== '1.4.1' &&
459
458
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
460
459
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
461
460
  ) {
462
461
  throw new Error(
463
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
462
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
464
463
  )
465
464
  }
466
465
  return binding
@@ -479,12 +478,12 @@ function requireNative() {
479
478
  const binding = require('@napi-rs/webcodecs-linux-loong64-musl')
480
479
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-musl/package.json').version
481
480
  if (
482
- bindingPackageVersion !== '1.3.1' &&
481
+ bindingPackageVersion !== '1.4.1' &&
483
482
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
484
483
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
485
484
  ) {
486
485
  throw new Error(
487
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
486
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
488
487
  )
489
488
  }
490
489
  return binding
@@ -501,12 +500,12 @@ function requireNative() {
501
500
  const binding = require('@napi-rs/webcodecs-linux-loong64-gnu')
502
501
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-gnu/package.json').version
503
502
  if (
504
- bindingPackageVersion !== '1.3.1' &&
503
+ bindingPackageVersion !== '1.4.1' &&
505
504
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
506
505
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
507
506
  ) {
508
507
  throw new Error(
509
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
508
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
510
509
  )
511
510
  }
512
511
  return binding
@@ -525,12 +524,12 @@ function requireNative() {
525
524
  const binding = require('@napi-rs/webcodecs-linux-riscv64-musl')
526
525
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-musl/package.json').version
527
526
  if (
528
- bindingPackageVersion !== '1.3.1' &&
527
+ bindingPackageVersion !== '1.4.1' &&
529
528
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
530
529
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
531
530
  ) {
532
531
  throw new Error(
533
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
532
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
534
533
  )
535
534
  }
536
535
  return binding
@@ -547,12 +546,12 @@ function requireNative() {
547
546
  const binding = require('@napi-rs/webcodecs-linux-riscv64-gnu')
548
547
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-gnu/package.json').version
549
548
  if (
550
- bindingPackageVersion !== '1.3.1' &&
549
+ bindingPackageVersion !== '1.4.1' &&
551
550
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
552
551
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
553
552
  ) {
554
553
  throw new Error(
555
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
554
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
556
555
  )
557
556
  }
558
557
  return binding
@@ -570,12 +569,12 @@ function requireNative() {
570
569
  const binding = require('@napi-rs/webcodecs-linux-ppc64-gnu')
571
570
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-ppc64-gnu/package.json').version
572
571
  if (
573
- bindingPackageVersion !== '1.3.1' &&
572
+ bindingPackageVersion !== '1.4.1' &&
574
573
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
575
574
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
576
575
  ) {
577
576
  throw new Error(
578
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
577
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
579
578
  )
580
579
  }
581
580
  return binding
@@ -592,12 +591,12 @@ function requireNative() {
592
591
  const binding = require('@napi-rs/webcodecs-linux-s390x-gnu')
593
592
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-s390x-gnu/package.json').version
594
593
  if (
595
- bindingPackageVersion !== '1.3.1' &&
594
+ bindingPackageVersion !== '1.4.1' &&
596
595
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
597
596
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
598
597
  ) {
599
598
  throw new Error(
600
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
599
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
601
600
  )
602
601
  }
603
602
  return binding
@@ -618,12 +617,12 @@ function requireNative() {
618
617
  const binding = require('@napi-rs/webcodecs-openharmony-arm64')
619
618
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm64/package.json').version
620
619
  if (
621
- bindingPackageVersion !== '1.3.1' &&
620
+ bindingPackageVersion !== '1.4.1' &&
622
621
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
623
622
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
624
623
  ) {
625
624
  throw new Error(
626
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
625
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
627
626
  )
628
627
  }
629
628
  return binding
@@ -640,12 +639,12 @@ function requireNative() {
640
639
  const binding = require('@napi-rs/webcodecs-openharmony-x64')
641
640
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-x64/package.json').version
642
641
  if (
643
- bindingPackageVersion !== '1.3.1' &&
642
+ bindingPackageVersion !== '1.4.1' &&
644
643
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
645
644
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
646
645
  ) {
647
646
  throw new Error(
648
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
647
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
649
648
  )
650
649
  }
651
650
  return binding
@@ -662,12 +661,12 @@ function requireNative() {
662
661
  const binding = require('@napi-rs/webcodecs-openharmony-arm')
663
662
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm/package.json').version
664
663
  if (
665
- bindingPackageVersion !== '1.3.1' &&
664
+ bindingPackageVersion !== '1.4.1' &&
666
665
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
667
666
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
668
667
  ) {
669
668
  throw new Error(
670
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
669
+ `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
671
670
  )
672
671
  }
673
672
  return binding
@@ -682,54 +681,165 @@ function requireNative() {
682
681
  }
683
682
  }
684
683
 
685
- nativeBinding = requireNative()
684
+ function createLoadErrorChain(errors) {
685
+ return errors.reduce((previous, current) => {
686
+ let message
687
+ try {
688
+ message = current && typeof current.message === 'string' ? current.message : String(current)
689
+ } catch {
690
+ message = 'Unknown error'
691
+ }
692
+ const error = new Error(message)
693
+ error.cause = previous
694
+ return error
695
+ }, null)
696
+ }
697
+
698
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
699
+ // unset / any other value → native binding preferred, WASI is only a fallback
700
+ // 'true' → prefer WASI, but retain native as a lazy fallback
701
+ // 'error' → require WASI without initializing a native fallback
702
+ // Treating any non-empty string as truthy (the historical behavior) meant
703
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
704
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
705
+ //
706
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
707
+ // WASI loading. It never crosses into another flavor or falls back to native.
708
+ const __napiWasiFlavors = ['wasm32-wasi']
709
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
710
+ const __napiWasiFlavorRequested = typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
711
+ if (__napiWasiFlavorRequested && __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1) {
712
+ throw new Error(
713
+ 'Unsupported WASI flavor "' + __napiWasiFlavor + '". Available flavors: ' + __napiWasiFlavors.join(', '),
714
+ )
715
+ }
716
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
717
+ const forceWasi = process.env.NAPI_RS_FORCE_WASI === 'true' || forceWasiError || __napiWasiFlavorRequested
686
718
 
687
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
719
+ if (!forceWasi) {
720
+ nativeBinding = requireNative()
721
+ }
722
+
723
+ if (!nativeBinding || forceWasi) {
688
724
  let wasiBinding = null
689
- let wasiBindingError = null
690
- try {
691
- wasiBinding = require('./webcodecs.wasi.cjs')
692
- nativeBinding = wasiBinding
693
- } catch (err) {
694
- if (process.env.NAPI_RS_FORCE_WASI) {
695
- wasiBindingError = err
725
+ let wasiBindingLoaded = false
726
+ const wasiBindingErrors = []
727
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
728
+ try {
729
+ require.resolve(specifier)
730
+ } catch (resolveError) {
731
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
732
+ throw resolveError
733
+ }
734
+ if (isPackage) {
735
+ try {
736
+ require.resolve(specifier + '/package.json')
737
+ } catch (packageError) {
738
+ if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
739
+ return resolveError
740
+ }
741
+ // An exports restriction proves the package exists even when its
742
+ // package.json is not public. Preserve the root resolution failure.
743
+ throw resolveError
744
+ }
745
+ // The package exists but its main/export target is broken.
746
+ throw resolveError
747
+ }
748
+ return resolveError
696
749
  }
750
+ if (localArtifacts) {
751
+ let artifactError = null
752
+ for (let i = 0; i < localArtifacts.length; i++) {
753
+ try {
754
+ require.resolve(localArtifacts[i])
755
+ return null
756
+ } catch (resolveError) {
757
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
758
+ throw resolveError
759
+ }
760
+ artifactError = resolveError
761
+ }
762
+ }
763
+ return artifactError
764
+ }
765
+ return null
697
766
  }
698
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
767
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
768
+ let candidateError = null
769
+ let candidateFailed = false
699
770
  try {
700
- wasiBinding = require('@napi-rs/webcodecs-wasm32-wasi')
701
- nativeBinding = wasiBinding
771
+ candidateError = __napiWasiResolveCandidate('./webcodecs.wasi.cjs', false, [
772
+ './webcodecs.wasm32-wasi.debug.wasm',
773
+ './webcodecs.wasm32-wasi.wasm',
774
+ ])
775
+ candidateFailed = candidateError !== null
776
+ if (!candidateFailed) {
777
+ wasiBinding = require('./webcodecs.wasi.cjs')
778
+ nativeBinding = wasiBinding
779
+ wasiBindingLoaded = true
780
+ }
702
781
  } catch (err) {
703
- if (process.env.NAPI_RS_FORCE_WASI) {
704
- if (!wasiBindingError) {
705
- wasiBindingError = err
706
- } else {
707
- wasiBindingError.cause = err
782
+ candidateError = err
783
+ candidateFailed = true
784
+ }
785
+ if (candidateFailed) {
786
+ wasiBindingErrors.push(candidateError)
787
+ loadErrors.push(candidateError)
788
+ }
789
+ }
790
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
791
+ let candidateError = null
792
+ let candidateFailed = false
793
+ try {
794
+ candidateError = __napiWasiResolveCandidate('@napi-rs/webcodecs-wasm32-wasi', true, undefined)
795
+ candidateFailed = candidateError !== null
796
+ if (!candidateFailed) {
797
+ if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
798
+ const bindingPackageVersion = require('@napi-rs/webcodecs-wasm32-wasi/package.json').version
799
+ if (bindingPackageVersion !== '1.4.1') {
800
+ throw new Error(
801
+ `WASI binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
802
+ )
803
+ }
708
804
  }
709
- loadErrors.push(err)
805
+ wasiBinding = require('@napi-rs/webcodecs-wasm32-wasi')
806
+ nativeBinding = wasiBinding
807
+ wasiBindingLoaded = true
710
808
  }
809
+ } catch (err) {
810
+ candidateError = err
811
+ candidateFailed = true
711
812
  }
813
+ if (candidateFailed) {
814
+ wasiBindingErrors.push(candidateError)
815
+ loadErrors.push(candidateError)
816
+ }
817
+ }
818
+ if (!wasiBindingLoaded && forceWasi && !forceWasiError && !__napiWasiFlavorRequested) {
819
+ nativeBinding = requireNative()
712
820
  }
713
- if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
714
- const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
715
- error.cause = wasiBindingError
821
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
822
+ const error = new Error(
823
+ __napiWasiFlavorRequested
824
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
825
+ : 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
826
+ )
827
+ error.cause = createLoadErrorChain(wasiBindingErrors)
716
828
  throw error
717
829
  }
718
830
  }
719
831
 
720
832
  if (!nativeBinding) {
721
833
  if (loadErrors.length > 0) {
722
- throw new Error(
834
+ const error = new Error(
723
835
  `Cannot find native binding. ` +
724
836
  `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
725
837
  'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
726
- {
727
- cause: loadErrors.reduce((err, cur) => {
728
- cur.cause = err
729
- return cur
730
- }),
731
- },
732
838
  )
839
+ // assign instead of the `new Error(message, { cause })` options form,
840
+ // which Node < 16.9 silently ignores
841
+ error.cause = createLoadErrorChain(loadErrors)
842
+ throw error
733
843
  }
734
844
  throw new Error(`Failed to load native binding`)
735
845
  }
@@ -769,6 +879,7 @@ module.exports.getHardwareAccelerators = nativeBinding.getHardwareAccelerators
769
879
  module.exports.getPreferredHardwareAccelerator = nativeBinding.getPreferredHardwareAccelerator
770
880
  module.exports.HardwareAcceleration = nativeBinding.HardwareAcceleration
771
881
  module.exports.HevcBitstreamFormat = nativeBinding.HevcBitstreamFormat
882
+ module.exports.HevcSampleEntryJs = nativeBinding.HevcSampleEntryJs
772
883
  module.exports.isHardwareAcceleratorAvailable = nativeBinding.isHardwareAcceleratorAvailable
773
884
  module.exports.LatencyMode = nativeBinding.LatencyMode
774
885
  module.exports.OpusApplication = nativeBinding.OpusApplication
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/webcodecs",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "description": "WebCodecs API implementation for Node.js using FFmpeg",
5
5
  "keywords": [
6
6
  "N-API",
@@ -32,7 +32,6 @@
32
32
  "require": "./polyfill.js"
33
33
  }
34
34
  },
35
- "browser": "browser.js",
36
35
  "types": "index.d.ts",
37
36
  "files": [
38
37
  "index.d.ts",
@@ -53,7 +52,7 @@
53
52
  "prepublishOnly": "napi prepublish -t npm",
54
53
  "test": "ava",
55
54
  "demo": "cd example && vite",
56
- "typecheck": "tsc -b tsconfig.json && tsc ./index.d.ts",
55
+ "typecheck": "tsc -b tsconfig.json && tsc --ignoreConfig ./index.d.ts",
57
56
  "preversion": "oxnode ./build.ts --platform && git add .",
58
57
  "version": "napi version"
59
58
  },
@@ -63,31 +62,31 @@
63
62
  ]
64
63
  },
65
64
  "devDependencies": {
66
- "@emnapi/core": "^1.8.1",
67
- "@emnapi/runtime": "^1.8.1",
68
- "@napi-rs/canvas": "^0.1.88",
69
- "@napi-rs/cli": "^3.5.1",
70
- "@napi-rs/wasm-runtime": "^1.1.1",
71
- "@oxc-node/cli": "^0.0.35",
72
- "@oxc-node/core": "^0.0.35",
65
+ "@emnapi/core": "^2.0.0-alpha.5",
66
+ "@emnapi/runtime": "^2.0.0-alpha.5",
67
+ "@napi-rs/canvas": "^1.0.9",
68
+ "@napi-rs/cli": "^3.9.1",
69
+ "@napi-rs/wasm-runtime": "^1.2.4",
70
+ "@oxc-node/cli": "^0.1.2",
71
+ "@oxc-node/core": "^0.1.2",
73
72
  "@taplo/cli": "^0.7.0",
74
- "@tybys/wasm-util": "^0.10.1",
75
- "@types/node": "^25.0.10",
76
- "ava": "^6.4.1",
77
- "chalk": "^5.6.2",
78
- "emnapi": "^1.8.1",
73
+ "@tybys/wasm-util": "^0.10.4",
74
+ "@types/node": "^26.5.1",
75
+ "ava": "^8.0.1",
76
+ "chalk": "^6.0.0",
77
+ "emnapi": "^2.0.0-alpha.5",
79
78
  "husky": "^9.1.7",
80
- "lint-staged": "^16.2.7",
81
- "mediabunny": "1.30.1",
82
- "npm-run-all2": "^8.0.4",
83
- "oxfmt": "^0.26.0",
84
- "oxlint": "^1.41.0",
85
- "oxlint-tsgolint": "^0.11.1",
86
- "prettier": "^3.8.1",
87
- "tinybench": "^6.0.0",
88
- "typescript": "^5.9.3",
79
+ "lint-staged": "^17.5.1",
80
+ "mediabunny": "1.56.2",
81
+ "npm-run-all2": "^9.0.3",
82
+ "oxfmt": "^0.68.0",
83
+ "oxlint": "^1.83.0",
84
+ "oxlint-tsgolint": "^7.0.2001",
85
+ "prettier": "^3.9.6",
86
+ "tinybench": "^6.2.0",
87
+ "typescript": "^7.0.2",
89
88
  "webcodecs-polyfill": "^1.0.1",
90
- "vite-plugin-mkcert": "^1.17.9"
89
+ "vite-plugin-mkcert": "^2.1.0"
91
90
  },
92
91
  "peerDependencies": {
93
92
  "@napi-rs/canvas": ">=0.1.0"
@@ -113,14 +112,14 @@
113
112
  "armv7-unknown-linux-gnueabihf"
114
113
  ]
115
114
  },
116
- "packageManager": "pnpm@10.28.1",
115
+ "packageManager": "pnpm@12.4.1",
117
116
  "ava": {
118
117
  "environmentVariables": {
119
118
  "TS_NODE_PROJECT": "./tsconfig.json"
120
119
  },
121
- "extensions": {
122
- "ts": "module"
123
- },
120
+ "extensions": [
121
+ "ts"
122
+ ],
124
123
  "files": [
125
124
  "__test__/**/*.spec.ts"
126
125
  ],
@@ -132,34 +131,21 @@
132
131
  "workerThreads": false
133
132
  },
134
133
  "engines": {
135
- "node": ">= 10"
134
+ "node": "^22.20 || ^24.12 || >=25"
136
135
  },
137
136
  "publishConfig": {
138
137
  "access": "public",
139
138
  "registry": "https://registry.npmjs.org/"
140
139
  },
141
- "pnpm": {
142
- "onlyBuiltDependencies": [
143
- "node-av",
144
- "@seydx/node-av-darwin-arm64",
145
- "@seydx/node-av-darwin-x64",
146
- "@seydx/node-av-linux-arm64",
147
- "@seydx/node-av-linux-x64",
148
- "@seydx/node-av-win32-arm64-mingw",
149
- "@seydx/node-av-win32-arm64-msvc",
150
- "@seydx/node-av-win32-x64-mingw",
151
- "@seydx/node-av-win32-x64-msvc"
152
- ]
153
- },
154
140
  "optionalDependencies": {
155
- "@napi-rs/webcodecs-darwin-x64": "1.3.1",
156
- "@napi-rs/webcodecs-darwin-arm64": "1.3.1",
157
- "@napi-rs/webcodecs-linux-x64-gnu": "1.3.1",
158
- "@napi-rs/webcodecs-linux-x64-musl": "1.3.1",
159
- "@napi-rs/webcodecs-win32-x64-msvc": "1.3.1",
160
- "@napi-rs/webcodecs-linux-arm64-gnu": "1.3.1",
161
- "@napi-rs/webcodecs-linux-arm64-musl": "1.3.1",
162
- "@napi-rs/webcodecs-win32-arm64-msvc": "1.3.1",
163
- "@napi-rs/webcodecs-linux-arm-gnueabihf": "1.3.1"
141
+ "@napi-rs/webcodecs-darwin-x64": "1.4.1",
142
+ "@napi-rs/webcodecs-darwin-arm64": "1.4.1",
143
+ "@napi-rs/webcodecs-linux-x64-gnu": "1.4.1",
144
+ "@napi-rs/webcodecs-linux-x64-musl": "1.4.1",
145
+ "@napi-rs/webcodecs-win32-x64-msvc": "1.4.1",
146
+ "@napi-rs/webcodecs-linux-arm64-gnu": "1.4.1",
147
+ "@napi-rs/webcodecs-linux-arm64-musl": "1.4.1",
148
+ "@napi-rs/webcodecs-win32-arm64-msvc": "1.4.1",
149
+ "@napi-rs/webcodecs-linux-arm-gnueabihf": "1.4.1"
164
150
  }
165
- }
151
+ }