@napi-rs/webcodecs 1.2.1 โ 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -5
- package/index.d.ts +255 -212
- package/index.js +82 -237
- package/package.json +42 -33
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
|
|
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.
|
|
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
|