@napi-rs/webcodecs 1.2.1 โ†’ 1.3.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 +60 -5
  2. package/index.d.ts +93 -0
  3. package/index.js +58 -54
  4. package/package.json +47 -46
package/README.md CHANGED
@@ -7,8 +7,8 @@ WebCodecs API implementation for Node.js using FFmpeg, built with [NAPI-RS](http
7
7
  ## Features
8
8
 
9
9
  - **W3C WebCodecs API compliant** - Full implementation of the WebCodecs specification with native `DOMException` errors
10
- - **Video encoding/decoding** - H.264, H.265, VP8, VP9 (with Alpha), AV1
11
- - **Encoding Alpha channel** - VP9 encoding/decoding with Alpha support(See [canvas-to-video.js](example/canvas-to-video.js) example and [video.html](example/video.html))
10
+ - **Video encoding/decoding** - H.264, H.265 (with Alpha), VP8, VP9 (with Alpha), AV1
11
+ - **Encoding Alpha channel** - VP9 and HEVC alpha encoding/decoding with transparency support (See [canvas-to-video.js](example/canvas-to-video.js) example and [video.html](example/video.html))
12
12
  - **Audio encoding/decoding** - AAC, Opus, MP3, FLAC, Vorbis, PCM variants
13
13
  - **Container muxing/demuxing** - MP4, WebM, MKV containers with seeking support
14
14
  - **Image decoding** - JPEG, PNG, WebP, GIF, BMP, AVIF, JPEG XL
@@ -343,12 +343,18 @@ frame.close()
343
343
  | Codec | Codec String | Encoding | Encoding Alpha | Decoding | Decoding Alpha |
344
344
  | ----- | ----------------------- | -------- | -------------- | -------- | -------------- |
345
345
  | H.264 | `avc1.*` | โœ… | ๐Ÿ™…๐Ÿปโ€โ™€๏ธ | โœ… | ๐Ÿ™…๐Ÿปโ€โ™€๏ธ |
346
- | H.265 | `hev1.*`, `hvc1.*` | โœ… | โ“ | โœ… | โ“ |
346
+ | H.265 | `hev1.*`, `hvc1.*` | โœ… | โœ…ยน | โœ… | โœ… |
347
347
  | VP8 | `vp8` | โœ… | ๐Ÿ™…๐Ÿปโ€โ™€๏ธ | โœ… | ๐Ÿ™…๐Ÿปโ€โ™€๏ธ |
348
348
  | VP9 | `vp09.*`, `vp9` | โœ… | โœ… | โœ… | โœ… |
349
349
  | AV1 | `av01.*`, `av01`, `av1` | โœ… | ๐Ÿ™…๐Ÿปโ€โ™€๏ธ | โœ… | ๐Ÿ™…๐Ÿปโ€โ™€๏ธ |
350
350
 
351
- **Note:** Short form codec strings (`vp9`, `av01`, `av1`) are accepted for compatibility with browser implementations. VP9 encoding and decoding now supports Alpha channel (transparency).
351
+ **Note:** Short form codec strings (`vp9`, `av01`, `av1`) are accepted for compatibility with browser implementations.
352
+
353
+ ยน **HEVC Alpha Encoding Limitations:**
354
+
355
+ - Requires software encoder (libx265) - set `hardwareAcceleration: 'prefer-software'`
356
+ - Hardware encoders (VideoToolbox, NVENC, VAAPI, QSV) do not support alpha
357
+ - Only YUVA420P (8-bit) and YUVA420P10 (10-bit Main 10 profile) pixel formats supported
352
358
 
353
359
  **Legend:**
354
360
 
@@ -448,14 +454,63 @@ encoder.configure({
448
454
  hardwareAcceleration: 'prefer-hardware', // 'no-preference' | 'prefer-hardware' | 'prefer-software'
449
455
  // Latency mode affects encoder tuning
450
456
  latencyMode: 'realtime', // 'quality' | 'realtime'
457
+ // Alpha channel preservation (VP9 and HEVC only)
458
+ alpha: 'discard', // 'keep' | 'discard' (default: 'discard')
451
459
  })
452
460
  ```
453
461
 
454
462
  - `latencyMode: 'realtime'` - Enables low-latency encoder options (smaller GOP, no B-frames, fast presets)
455
463
  - `latencyMode: 'quality'` - Enables quality-focused options (larger GOP, B-frames, lookahead)
464
+ - `alpha: 'keep'` - Preserves alpha channel (VP9 and HEVC only). For HEVC, requires `hardwareAcceleration: 'prefer-software'`
456
465
 
457
466
  The encoder automatically applies optimal settings for each hardware encoder based on the latency mode.
458
467
 
468
+ ### Alpha Channel Encoding
469
+
470
+ Encode video with transparency using VP9 or HEVC:
471
+
472
+ ```typescript
473
+ import { VideoEncoder, VideoFrame } from '@napi-rs/webcodecs'
474
+
475
+ const encoder = new VideoEncoder({
476
+ output: (chunk, metadata) => {
477
+ console.log(`Alpha chunk: ${chunk.byteLength} bytes`)
478
+ },
479
+ error: (e) => console.error(e),
480
+ })
481
+
482
+ // VP9 alpha - works with hardware or software
483
+ encoder.configure({
484
+ codec: 'vp09.00.10.08',
485
+ width: 1920,
486
+ height: 1080,
487
+ alpha: 'keep',
488
+ })
489
+
490
+ // HEVC alpha - requires software encoder
491
+ encoder.configure({
492
+ codec: 'hev1.1.6.L93.B0',
493
+ width: 1920,
494
+ height: 1080,
495
+ alpha: 'keep',
496
+ hardwareAcceleration: 'prefer-software', // Required for HEVC alpha
497
+ })
498
+
499
+ // Create frame with alpha channel (I420A format)
500
+ const width = 1920
501
+ const height = 1080
502
+ const frameData = new Uint8Array(width * height * 1.5 + width * height) // Y + U + V + A
503
+ const frame = new VideoFrame(frameData, {
504
+ format: 'I420A',
505
+ codedWidth: width,
506
+ codedHeight: height,
507
+ timestamp: 0,
508
+ })
509
+
510
+ encoder.encode(frame)
511
+ frame.close()
512
+ ```
513
+
459
514
  ## Limitations
460
515
 
461
516
  ### Scalable Video Coding (SVC)
@@ -650,4 +705,4 @@ cargo clippy
650
705
 
651
706
  ## License
652
707
 
653
- MIT
708
+ MIT
package/index.d.ts CHANGED
@@ -137,6 +137,60 @@ export interface MkvMuxerInit {
137
137
  streaming?: { bufferCapacity?: number }
138
138
  }
139
139
 
140
+ // ============================================================================
141
+ // Async Iterator Types
142
+ // ============================================================================
143
+
144
+ /**
145
+ * Chunk yielded by demuxer async iterator.
146
+ *
147
+ * Contains either a video or audio chunk. Use the `chunkType` property
148
+ * to determine which type of chunk is present.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * for await (const chunk of demuxer) {
153
+ * if (chunk.chunkType === 'video') {
154
+ * videoDecoder.decode(chunk.videoChunk!)
155
+ * } else {
156
+ * audioDecoder.decode(chunk.audioChunk!)
157
+ * }
158
+ * }
159
+ * ```
160
+ */
161
+ export interface DemuxerChunk {
162
+ /** Type of chunk: 'video' or 'audio' */
163
+ chunkType: 'video' | 'audio'
164
+ /** Video chunk (present when chunkType is 'video') */
165
+ videoChunk?: EncodedVideoChunk
166
+ /** Audio chunk (present when chunkType is 'audio') */
167
+ audioChunk?: EncodedAudioChunk
168
+ }
169
+
170
+ /**
171
+ * Adds async iterator support to Mp4Demuxer.
172
+ * Declaration merging allows using `for await...of` with the demuxer.
173
+ */
174
+ export interface Mp4Demuxer {
175
+ [Symbol.asyncIterator](): AsyncGenerator<DemuxerChunk, void, void>
176
+ }
177
+
178
+ /**
179
+ * Adds async iterator support to WebMDemuxer.
180
+ * Declaration merging allows using `for await...of` with the demuxer.
181
+ */
182
+ export interface WebMDemuxer {
183
+ [Symbol.asyncIterator](): AsyncGenerator<DemuxerChunk, void, void>
184
+ }
185
+
186
+ /**
187
+ * Adds async iterator support to MkvDemuxer.
188
+ * Declaration merging allows using `for await...of` with the demuxer.
189
+ */
190
+ export interface MkvDemuxer {
191
+ [Symbol.asyncIterator](): AsyncGenerator<DemuxerChunk, void, void>
192
+ }
193
+
140
194
  export type TypedArray =
141
195
  | Int8Array
142
196
  | Uint8Array
@@ -561,6 +615,11 @@ export declare class ImageTrackList {
561
615
  * MKV Demuxer for reading encoded video and audio from Matroska container
562
616
  *
563
617
  * MKV supports almost any video and audio codec.
618
+ *
619
+ * This type implements JavaScript's async iterable protocol.
620
+ * It can be used with `for await...of` loops.
621
+ *
622
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
564
623
  */
565
624
  export declare class MkvDemuxer {
566
625
  constructor(init: MkvDemuxerInit)
@@ -579,6 +638,8 @@ export declare class MkvDemuxer {
579
638
  selectVideoTrack(trackIndex: number): void
580
639
  selectAudioTrack(trackIndex: number): void
581
640
  demux(count?: number | undefined | null): void
641
+ /** Demux packets asynchronously (awaitable version of demux) */
642
+ demuxAsync(count?: number | undefined | null): Promise<void>
582
643
  seek(timestampUs: number): void
583
644
  close(): void
584
645
  get state(): string
@@ -673,6 +734,11 @@ export declare class MkvMuxer {
673
734
  *
674
735
  * demuxer.close();
675
736
  * ```
737
+ *
738
+ * This type implements JavaScript's async iterable protocol.
739
+ * It can be used with `for await...of` loops.
740
+ *
741
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
676
742
  */
677
743
  export declare class Mp4Demuxer {
678
744
  /** Create a new MP4 demuxer */
@@ -705,6 +771,20 @@ export declare class Mp4Demuxer {
705
771
  * Otherwise, reads all packets until end of stream.
706
772
  */
707
773
  demux(count?: number | undefined | null): void
774
+ /**
775
+ * Demux packets asynchronously (awaitable version of demux)
776
+ *
777
+ * If count is specified, reads up to that many packets.
778
+ * Otherwise, reads all packets until end of stream.
779
+ * Returns a Promise that resolves when demuxing is complete.
780
+ *
781
+ * This method is useful when you want to wait for demuxing to finish
782
+ * before proceeding with other operations.
783
+ *
784
+ * Note: For streaming use cases, prefer the async iterator pattern:
785
+ * `for await (const chunk of demuxer) { ... }`
786
+ */
787
+ demuxAsync(count?: number | undefined | null): Promise<void>
708
788
  /** Seek to a timestamp in microseconds */
709
789
  seek(timestampUs: number): void
710
790
  /** Close the demuxer and release resources */
@@ -1100,6 +1180,11 @@ export declare class VideoFrame {
1100
1180
  * WebM Demuxer for reading encoded video and audio from WebM container
1101
1181
  *
1102
1182
  * WebM typically contains VP8, VP9, or AV1 video with Opus or Vorbis audio.
1183
+ *
1184
+ * This type implements JavaScript's async iterable protocol.
1185
+ * It can be used with `for await...of` loops.
1186
+ *
1187
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
1103
1188
  */
1104
1189
  export declare class WebMDemuxer {
1105
1190
  constructor(init: WebMDemuxerInit)
@@ -1118,6 +1203,8 @@ export declare class WebMDemuxer {
1118
1203
  selectVideoTrack(trackIndex: number): void
1119
1204
  selectAudioTrack(trackIndex: number): void
1120
1205
  demux(count?: number | undefined | null): void
1206
+ /** Demux packets asynchronously (awaitable version of demux) */
1207
+ demuxAsync(count?: number | undefined | null): Promise<void>
1121
1208
  seek(timestampUs: number): void
1122
1209
  close(): void
1123
1210
  get state(): string
@@ -1537,6 +1624,8 @@ export interface MkvVideoTrackConfig {
1537
1624
  width: number
1538
1625
  /** Video height in pixels */
1539
1626
  height: number
1627
+ /** Frame rate (frames per second) */
1628
+ framerate?: number
1540
1629
  /** Codec-specific description data */
1541
1630
  description?: Uint8Array
1542
1631
  }
@@ -1577,6 +1666,8 @@ export interface Mp4VideoTrackConfig {
1577
1666
  width: number
1578
1667
  /** Video height in pixels */
1579
1668
  height: number
1669
+ /** Frame rate (frames per second) */
1670
+ framerate?: number
1580
1671
  /** Codec-specific description data (avcC/hvcC/av1C from encoder metadata) */
1581
1672
  description?: Uint8Array
1582
1673
  }
@@ -1929,6 +2020,8 @@ export interface WebMVideoTrackConfig {
1929
2020
  width: number
1930
2021
  /** Video height in pixels */
1931
2022
  height: number
2023
+ /** Frame rate (frames per second) */
2024
+ framerate?: number
1932
2025
  /** Codec-specific description data */
1933
2026
  description?: Uint8Array
1934
2027
  /** Whether the video has alpha channel (VP9 alpha support) */
package/index.js CHANGED
@@ -78,12 +78,12 @@ function requireNative() {
78
78
  const binding = require('@napi-rs/webcodecs-android-arm64')
79
79
  const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm64/package.json').version
80
80
  if (
81
- bindingPackageVersion !== '1.2.1' &&
81
+ bindingPackageVersion !== '1.3.1' &&
82
82
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
83
83
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
84
84
  ) {
85
85
  throw new Error(
86
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
86
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
87
87
  )
88
88
  }
89
89
  return binding
@@ -100,12 +100,12 @@ function requireNative() {
100
100
  const binding = require('@napi-rs/webcodecs-android-arm-eabi')
101
101
  const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm-eabi/package.json').version
102
102
  if (
103
- bindingPackageVersion !== '1.2.1' &&
103
+ bindingPackageVersion !== '1.3.1' &&
104
104
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
105
105
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
106
106
  ) {
107
107
  throw new Error(
108
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
108
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
109
109
  )
110
110
  }
111
111
  return binding
@@ -130,12 +130,12 @@ function requireNative() {
130
130
  const binding = require('@napi-rs/webcodecs-win32-x64-gnu')
131
131
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-gnu/package.json').version
132
132
  if (
133
- bindingPackageVersion !== '1.2.1' &&
133
+ bindingPackageVersion !== '1.3.1' &&
134
134
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
135
135
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
136
136
  ) {
137
137
  throw new Error(
138
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
138
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
139
139
  )
140
140
  }
141
141
  return binding
@@ -152,12 +152,12 @@ function requireNative() {
152
152
  const binding = require('@napi-rs/webcodecs-win32-x64-msvc')
153
153
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-msvc/package.json').version
154
154
  if (
155
- bindingPackageVersion !== '1.2.1' &&
155
+ bindingPackageVersion !== '1.3.1' &&
156
156
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
157
157
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
158
158
  ) {
159
159
  throw new Error(
160
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
160
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
161
161
  )
162
162
  }
163
163
  return binding
@@ -175,12 +175,12 @@ function requireNative() {
175
175
  const binding = require('@napi-rs/webcodecs-win32-ia32-msvc')
176
176
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-ia32-msvc/package.json').version
177
177
  if (
178
- bindingPackageVersion !== '1.2.1' &&
178
+ bindingPackageVersion !== '1.3.1' &&
179
179
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
180
180
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
181
181
  ) {
182
182
  throw new Error(
183
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
183
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
184
184
  )
185
185
  }
186
186
  return binding
@@ -197,12 +197,12 @@ function requireNative() {
197
197
  const binding = require('@napi-rs/webcodecs-win32-arm64-msvc')
198
198
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-arm64-msvc/package.json').version
199
199
  if (
200
- bindingPackageVersion !== '1.2.1' &&
200
+ bindingPackageVersion !== '1.3.1' &&
201
201
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
202
202
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
203
203
  ) {
204
204
  throw new Error(
205
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
205
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
206
206
  )
207
207
  }
208
208
  return binding
@@ -222,12 +222,12 @@ function requireNative() {
222
222
  const binding = require('@napi-rs/webcodecs-darwin-universal')
223
223
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-universal/package.json').version
224
224
  if (
225
- bindingPackageVersion !== '1.2.1' &&
225
+ bindingPackageVersion !== '1.3.1' &&
226
226
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
227
227
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
228
228
  ) {
229
229
  throw new Error(
230
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
230
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
231
231
  )
232
232
  }
233
233
  return binding
@@ -244,12 +244,12 @@ function requireNative() {
244
244
  const binding = require('@napi-rs/webcodecs-darwin-x64')
245
245
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-x64/package.json').version
246
246
  if (
247
- bindingPackageVersion !== '1.2.1' &&
247
+ bindingPackageVersion !== '1.3.1' &&
248
248
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
249
249
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
250
250
  ) {
251
251
  throw new Error(
252
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
252
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
253
253
  )
254
254
  }
255
255
  return binding
@@ -266,12 +266,12 @@ function requireNative() {
266
266
  const binding = require('@napi-rs/webcodecs-darwin-arm64')
267
267
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-arm64/package.json').version
268
268
  if (
269
- bindingPackageVersion !== '1.2.1' &&
269
+ bindingPackageVersion !== '1.3.1' &&
270
270
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
271
271
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
272
272
  ) {
273
273
  throw new Error(
274
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
274
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
275
275
  )
276
276
  }
277
277
  return binding
@@ -292,12 +292,12 @@ function requireNative() {
292
292
  const binding = require('@napi-rs/webcodecs-freebsd-x64')
293
293
  const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-x64/package.json').version
294
294
  if (
295
- bindingPackageVersion !== '1.2.1' &&
295
+ bindingPackageVersion !== '1.3.1' &&
296
296
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
297
297
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
298
298
  ) {
299
299
  throw new Error(
300
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
300
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
301
301
  )
302
302
  }
303
303
  return binding
@@ -314,12 +314,12 @@ function requireNative() {
314
314
  const binding = require('@napi-rs/webcodecs-freebsd-arm64')
315
315
  const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-arm64/package.json').version
316
316
  if (
317
- bindingPackageVersion !== '1.2.1' &&
317
+ bindingPackageVersion !== '1.3.1' &&
318
318
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
319
319
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
320
320
  ) {
321
321
  throw new Error(
322
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
322
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
323
323
  )
324
324
  }
325
325
  return binding
@@ -341,12 +341,12 @@ function requireNative() {
341
341
  const binding = require('@napi-rs/webcodecs-linux-x64-musl')
342
342
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-musl/package.json').version
343
343
  if (
344
- bindingPackageVersion !== '1.2.1' &&
344
+ bindingPackageVersion !== '1.3.1' &&
345
345
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
346
346
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
347
347
  ) {
348
348
  throw new Error(
349
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
349
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
350
350
  )
351
351
  }
352
352
  return binding
@@ -363,12 +363,12 @@ function requireNative() {
363
363
  const binding = require('@napi-rs/webcodecs-linux-x64-gnu')
364
364
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-gnu/package.json').version
365
365
  if (
366
- bindingPackageVersion !== '1.2.1' &&
366
+ bindingPackageVersion !== '1.3.1' &&
367
367
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
368
368
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
369
369
  ) {
370
370
  throw new Error(
371
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
371
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
372
372
  )
373
373
  }
374
374
  return binding
@@ -387,12 +387,12 @@ function requireNative() {
387
387
  const binding = require('@napi-rs/webcodecs-linux-arm64-musl')
388
388
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-musl/package.json').version
389
389
  if (
390
- bindingPackageVersion !== '1.2.1' &&
390
+ bindingPackageVersion !== '1.3.1' &&
391
391
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
392
392
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
393
393
  ) {
394
394
  throw new Error(
395
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
395
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
396
396
  )
397
397
  }
398
398
  return binding
@@ -409,12 +409,12 @@ function requireNative() {
409
409
  const binding = require('@napi-rs/webcodecs-linux-arm64-gnu')
410
410
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-gnu/package.json').version
411
411
  if (
412
- bindingPackageVersion !== '1.2.1' &&
412
+ bindingPackageVersion !== '1.3.1' &&
413
413
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
414
414
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
415
415
  ) {
416
416
  throw new Error(
417
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
417
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
418
418
  )
419
419
  }
420
420
  return binding
@@ -433,12 +433,12 @@ function requireNative() {
433
433
  const binding = require('@napi-rs/webcodecs-linux-arm-musleabihf')
434
434
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-musleabihf/package.json').version
435
435
  if (
436
- bindingPackageVersion !== '1.2.1' &&
436
+ bindingPackageVersion !== '1.3.1' &&
437
437
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
438
438
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
439
439
  ) {
440
440
  throw new Error(
441
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
441
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
442
442
  )
443
443
  }
444
444
  return binding
@@ -455,12 +455,12 @@ function requireNative() {
455
455
  const binding = require('@napi-rs/webcodecs-linux-arm-gnueabihf')
456
456
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-gnueabihf/package.json').version
457
457
  if (
458
- bindingPackageVersion !== '1.2.1' &&
458
+ bindingPackageVersion !== '1.3.1' &&
459
459
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
460
460
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
461
461
  ) {
462
462
  throw new Error(
463
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
463
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
464
464
  )
465
465
  }
466
466
  return binding
@@ -479,12 +479,12 @@ function requireNative() {
479
479
  const binding = require('@napi-rs/webcodecs-linux-loong64-musl')
480
480
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-musl/package.json').version
481
481
  if (
482
- bindingPackageVersion !== '1.2.1' &&
482
+ bindingPackageVersion !== '1.3.1' &&
483
483
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
484
484
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
485
485
  ) {
486
486
  throw new Error(
487
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
487
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
488
488
  )
489
489
  }
490
490
  return binding
@@ -501,12 +501,12 @@ function requireNative() {
501
501
  const binding = require('@napi-rs/webcodecs-linux-loong64-gnu')
502
502
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-gnu/package.json').version
503
503
  if (
504
- bindingPackageVersion !== '1.2.1' &&
504
+ bindingPackageVersion !== '1.3.1' &&
505
505
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
506
506
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
507
507
  ) {
508
508
  throw new Error(
509
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
509
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
510
510
  )
511
511
  }
512
512
  return binding
@@ -525,12 +525,12 @@ function requireNative() {
525
525
  const binding = require('@napi-rs/webcodecs-linux-riscv64-musl')
526
526
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-musl/package.json').version
527
527
  if (
528
- bindingPackageVersion !== '1.2.1' &&
528
+ bindingPackageVersion !== '1.3.1' &&
529
529
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
530
530
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
531
531
  ) {
532
532
  throw new Error(
533
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
533
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
534
534
  )
535
535
  }
536
536
  return binding
@@ -547,12 +547,12 @@ function requireNative() {
547
547
  const binding = require('@napi-rs/webcodecs-linux-riscv64-gnu')
548
548
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-gnu/package.json').version
549
549
  if (
550
- bindingPackageVersion !== '1.2.1' &&
550
+ bindingPackageVersion !== '1.3.1' &&
551
551
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
552
552
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
553
553
  ) {
554
554
  throw new Error(
555
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
555
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
556
556
  )
557
557
  }
558
558
  return binding
@@ -570,12 +570,12 @@ function requireNative() {
570
570
  const binding = require('@napi-rs/webcodecs-linux-ppc64-gnu')
571
571
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-ppc64-gnu/package.json').version
572
572
  if (
573
- bindingPackageVersion !== '1.2.1' &&
573
+ bindingPackageVersion !== '1.3.1' &&
574
574
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
575
575
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
576
576
  ) {
577
577
  throw new Error(
578
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
578
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
579
579
  )
580
580
  }
581
581
  return binding
@@ -592,12 +592,12 @@ function requireNative() {
592
592
  const binding = require('@napi-rs/webcodecs-linux-s390x-gnu')
593
593
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-s390x-gnu/package.json').version
594
594
  if (
595
- bindingPackageVersion !== '1.2.1' &&
595
+ bindingPackageVersion !== '1.3.1' &&
596
596
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
597
597
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
598
598
  ) {
599
599
  throw new Error(
600
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
600
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
601
601
  )
602
602
  }
603
603
  return binding
@@ -618,12 +618,12 @@ function requireNative() {
618
618
  const binding = require('@napi-rs/webcodecs-openharmony-arm64')
619
619
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm64/package.json').version
620
620
  if (
621
- bindingPackageVersion !== '1.2.1' &&
621
+ bindingPackageVersion !== '1.3.1' &&
622
622
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
623
623
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
624
624
  ) {
625
625
  throw new Error(
626
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
626
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
627
627
  )
628
628
  }
629
629
  return binding
@@ -640,12 +640,12 @@ function requireNative() {
640
640
  const binding = require('@napi-rs/webcodecs-openharmony-x64')
641
641
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-x64/package.json').version
642
642
  if (
643
- bindingPackageVersion !== '1.2.1' &&
643
+ bindingPackageVersion !== '1.3.1' &&
644
644
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
645
645
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
646
646
  ) {
647
647
  throw new Error(
648
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
648
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
649
649
  )
650
650
  }
651
651
  return binding
@@ -662,12 +662,12 @@ function requireNative() {
662
662
  const binding = require('@napi-rs/webcodecs-openharmony-arm')
663
663
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm/package.json').version
664
664
  if (
665
- bindingPackageVersion !== '1.2.1' &&
665
+ bindingPackageVersion !== '1.3.1' &&
666
666
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
667
667
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
668
668
  ) {
669
669
  throw new Error(
670
- `Native binding package version mismatch, expected 1.2.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
670
+ `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
671
671
  )
672
672
  }
673
673
  return binding
@@ -695,13 +695,17 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
695
695
  wasiBindingError = err
696
696
  }
697
697
  }
698
- if (!nativeBinding) {
698
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
699
699
  try {
700
700
  wasiBinding = require('@napi-rs/webcodecs-wasm32-wasi')
701
701
  nativeBinding = wasiBinding
702
702
  } catch (err) {
703
703
  if (process.env.NAPI_RS_FORCE_WASI) {
704
- wasiBindingError.cause = err
704
+ if (!wasiBindingError) {
705
+ wasiBindingError = err
706
+ } else {
707
+ wasiBindingError.cause = err
708
+ }
705
709
  loadErrors.push(err)
706
710
  }
707
711
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/webcodecs",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "WebCodecs API implementation for Node.js using FFmpeg",
5
5
  "keywords": [
6
6
  "N-API",
@@ -43,56 +43,51 @@
43
43
  ],
44
44
  "scripts": {
45
45
  "artifacts": "napi artifacts",
46
- "bench": "node --import @oxc-node/core/register benchmark/bench.ts",
47
- "build": "napi build --platform --release",
48
- "build:debug": "napi build --platform",
49
- "format": "run-p format:rs format:toml format:oxfmt format:prettier",
50
- "format:prettier": "prettier . \"!**/*.{js,jsx,ts,tsx}\" -w",
46
+ "bench": "node --import @oxc-node/core/register benchmark/compare.ts",
47
+ "build": "oxnode ./build.ts --platform --release",
48
+ "build:debug": "oxnode ./build.ts --platform",
49
+ "format": "run-p format:rs format:oxfmt",
51
50
  "format:oxfmt": "oxfmt",
52
- "format:toml": "taplo format",
53
51
  "format:rs": "cargo fmt",
54
52
  "lint": "oxlint --type-aware",
55
53
  "prepublishOnly": "napi prepublish -t npm",
56
54
  "test": "ava",
55
+ "demo": "cd example && vite",
57
56
  "typecheck": "tsc -b tsconfig.json && tsc ./index.d.ts",
58
- "preversion": "napi build --platform && git add .",
57
+ "preversion": "oxnode ./build.ts --platform && git add .",
59
58
  "version": "napi version"
60
59
  },
61
60
  "lint-staged": {
62
61
  "*.@(js|ts|tsx)": [
63
- "oxlint --fix",
64
- "oxfmt"
65
- ],
66
- "*.@(yml|yaml|md|json)": [
67
- "prettier --write"
68
- ],
69
- "*.toml": [
70
- "taplo format"
62
+ "oxlint --fix"
71
63
  ]
72
64
  },
73
65
  "devDependencies": {
74
- "@emnapi/core": "^1.7.1",
75
- "@emnapi/runtime": "^1.7.1",
76
- "@napi-rs/canvas": "^0.1.86",
77
- "@napi-rs/cli": "^3.5.0",
78
- "@napi-rs/wasm-runtime": "^1.1.0",
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",
79
72
  "@oxc-node/core": "^0.0.35",
80
73
  "@taplo/cli": "^0.7.0",
81
74
  "@tybys/wasm-util": "^0.10.1",
82
- "@types/node": "^25.0.2",
75
+ "@types/node": "^25.0.10",
83
76
  "ava": "^6.4.1",
84
77
  "chalk": "^5.6.2",
85
- "emnapi": "^1.7.1",
78
+ "emnapi": "^1.8.1",
86
79
  "husky": "^9.1.7",
87
80
  "lint-staged": "^16.2.7",
88
- "mediabunny": "1.26.0",
81
+ "mediabunny": "1.30.1",
89
82
  "npm-run-all2": "^8.0.4",
90
- "oxfmt": "^0.18.0",
91
- "oxlint": "^1.33.0",
92
- "oxlint-tsgolint": "^0.9.1",
93
- "prettier": "^3.7.4",
83
+ "oxfmt": "^0.26.0",
84
+ "oxlint": "^1.41.0",
85
+ "oxlint-tsgolint": "^0.11.1",
86
+ "prettier": "^3.8.1",
94
87
  "tinybench": "^6.0.0",
95
- "typescript": "^5.9.3"
88
+ "typescript": "^5.9.3",
89
+ "webcodecs-polyfill": "^1.0.1",
90
+ "vite-plugin-mkcert": "^1.17.9"
96
91
  },
97
92
  "peerDependencies": {
98
93
  "@napi-rs/canvas": ">=0.1.0"
@@ -118,14 +113,7 @@
118
113
  "armv7-unknown-linux-gnueabihf"
119
114
  ]
120
115
  },
121
- "packageManager": "pnpm@10.26.0",
122
- "prettier": {
123
- "arrowParens": "always",
124
- "printWidth": 120,
125
- "semi": false,
126
- "singleQuote": true,
127
- "trailingComma": "all"
128
- },
116
+ "packageManager": "pnpm@10.28.1",
129
117
  "ava": {
130
118
  "environmentVariables": {
131
119
  "TS_NODE_PROJECT": "./tsconfig.json"
@@ -150,15 +138,28 @@
150
138
  "access": "public",
151
139
  "registry": "https://registry.npmjs.org/"
152
140
  },
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
+ },
153
154
  "optionalDependencies": {
154
- "@napi-rs/webcodecs-darwin-x64": "1.2.1",
155
- "@napi-rs/webcodecs-darwin-arm64": "1.2.1",
156
- "@napi-rs/webcodecs-linux-x64-gnu": "1.2.1",
157
- "@napi-rs/webcodecs-linux-x64-musl": "1.2.1",
158
- "@napi-rs/webcodecs-win32-x64-msvc": "1.2.1",
159
- "@napi-rs/webcodecs-linux-arm64-gnu": "1.2.1",
160
- "@napi-rs/webcodecs-linux-arm64-musl": "1.2.1",
161
- "@napi-rs/webcodecs-win32-arm64-msvc": "1.2.1",
162
- "@napi-rs/webcodecs-linux-arm-gnueabihf": "1.2.1"
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"
163
164
  }
164
165
  }