@catlabtech/webcvt-transcode 0.2.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 +70 -0
- package/dist/index.cjs +1578 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +172 -0
- package/dist/index.d.ts +172 -0
- package/dist/index.js +1554 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @catlabtech/webcvt-transcode
|
|
2
|
+
|
|
3
|
+
WebCodecs-first **audio** transcode backend for [webcvt](https://github.com/Junhui20/webcvt). Performs real cross-format audio conversion by chaining `demux → decode → encode → mux` over the container packages and the browser's WebCodecs codecs — no ffmpeg.wasm, no `SharedArrayBuffer`, no cross-origin isolation.
|
|
4
|
+
|
|
5
|
+
This is the "hardware path": WebCodecs runs in any secure context (HTTPS) and uses the platform's codecs. When a codec pair is unsupported at runtime (e.g. Safari < 26 has no `AudioEncoder`/`AudioDecoder`), `canHandle` returns `false` and routing falls through to the ffmpeg-wasm backend automatically.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @catlabtech/webcvt-transcode
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Nothing registers on import — register explicitly (keeps the backend tree-shakeable):
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { convert } from '@catlabtech/webcvt-core';
|
|
19
|
+
import { registerTranscodeBackend } from '@catlabtech/webcvt-transcode';
|
|
20
|
+
|
|
21
|
+
registerTranscodeBackend(); // into core's defaultRegistry
|
|
22
|
+
|
|
23
|
+
const wav = await convert(mp3File, { format: 'wav' });
|
|
24
|
+
const opus = await convert(flacFile, { format: 'ogg', quality: 0.8 });
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Register into a custom registry and unregister by name:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { BackendRegistry } from '@catlabtech/webcvt-core';
|
|
31
|
+
const registry = new BackendRegistry();
|
|
32
|
+
registerTranscodeBackend(registry);
|
|
33
|
+
registry.unregister('webcodecs-transcode');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## v1 audio matrix
|
|
37
|
+
|
|
38
|
+
**Inputs (decodable):** wav (PCM), mp3, aac (ADTS), flac, opus-in-ogg.
|
|
39
|
+
**Outputs:** wav, opus-in-ogg, opus-in-webm, aac (ADTS), flac.
|
|
40
|
+
|
|
41
|
+
| To → | Path |
|
|
42
|
+
|---|---|
|
|
43
|
+
| **wav** | decode → interleave int16 PCM → `serializeWav` (no encoder needed) |
|
|
44
|
+
| **ogg / opus** | Opus encode → `serializeOgg` (OpusHead identification packet) |
|
|
45
|
+
| **webm** | Opus encode → `serializeWebm` (OpusHead as `CodecPrivate`, cluster-split for int16 deltas) |
|
|
46
|
+
| **aac** | encoder-native ADTS (`aac: { format: 'adts' }`) → concatenate frames |
|
|
47
|
+
| **flac** | FLAC encode (Chromium; probe-gated) → `description ++ frames` |
|
|
48
|
+
|
|
49
|
+
Off-matrix by design → routed to ffmpeg-wasm: `→ mp3` (no WebCodecs MP3 encoder), `→ ogg(vorbis)` (no Vorbis encoder), `→ mp4/m4a` (no from-scratch mp4 muxer yet), and all video.
|
|
50
|
+
|
|
51
|
+
## `canHandle` — two-stage, cached
|
|
52
|
+
|
|
53
|
+
1. **Static matrix gate** — O(1) reject for any off-matrix pair, with no probing.
|
|
54
|
+
2. **Concrete codec probe** — `AudioDecoder.isConfigSupported` for the input codec **and** `AudioEncoder.isConfigSupported` for the output codec. Only both-supported → `true`. A missing WebCodecs global is treated as `false` (never throws).
|
|
55
|
+
3. **Per-session cache** — probe results are memoised, so repeated registry lookups don't re-probe.
|
|
56
|
+
|
|
57
|
+
## Options
|
|
58
|
+
|
|
59
|
+
- `quality` (0–1, default 0.7) → bitrate ladder. Opus/AAC stereo land on **128 kbps at q0.7**; ends at 64→256 kbps (Opus) / 96→256 kbps (AAC). Mono ≈ 0.6×.
|
|
60
|
+
- `codec` — accepted; the audio targets here have a fixed codec per container.
|
|
61
|
+
- `signal` — abort via `AbortSignal`; in-flight codecs are `close()`-d.
|
|
62
|
+
- `onProgress` — four weighted phases: `demux` (0–10%), `decode` (10–45%), `encode` (45–90%), `mux` (90–100%), then `done` at 100%.
|
|
63
|
+
|
|
64
|
+
## Limits
|
|
65
|
+
|
|
66
|
+
Buffer-all (every serializer takes a complete in-memory model): input is capped at **256 MiB**. mp4/m4a/webm/mkv audio-track inputs and video transcoding are handled by later stages.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|