@mediaway/encoder 0.1.0 → 0.1.2
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 +67 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @mediaway/encoder
|
|
2
|
+
|
|
3
|
+
Automatic hardware video encoding to **fragmented MP4** over Mediaway's C ABI.
|
|
4
|
+
`openAutoEncoder()` picks a working backend for your machine (NVENC, Vulkan
|
|
5
|
+
Video, or QuickSync on Windows), wires it to the fMP4 muxer, and returns a
|
|
6
|
+
session you push frames into.
|
|
7
|
+
|
|
8
|
+
Windows is the verified platform. Software fallbacks and other platforms are
|
|
9
|
+
explicit follow-up work — see the [Mediaway roadmap](https://github.com/nyxways/mediaway).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @mediaway/encoder
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { openAutoEncoder, AutoVideoEncodeConfig, EncoderUnavailableError, type VideoFrame } from "@mediaway/encoder";
|
|
21
|
+
import type { Rational } from "@mediaway/container";
|
|
22
|
+
|
|
23
|
+
const TIME_BASE: Rational = { num: 1, den: 30 };
|
|
24
|
+
|
|
25
|
+
const config = AutoVideoEncodeConfig.defaults("h264", 640, 480, TIME_BASE);
|
|
26
|
+
config.bitrateBps = 1_500_000; // override the backend default
|
|
27
|
+
|
|
28
|
+
let session;
|
|
29
|
+
try {
|
|
30
|
+
session = await openAutoEncoder(config);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err instanceof EncoderUnavailableError) {
|
|
33
|
+
console.log("no hardware encoder available on this machine");
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const greyFrame = Buffer.alloc(640 * 480 * 1.5); // NV12 (or i420/bgra8/rgba8)
|
|
40
|
+
for (let i = 0; i < 90; i++) {
|
|
41
|
+
greyFrame.fill(i % 255);
|
|
42
|
+
await session.writeFrame({
|
|
43
|
+
data: greyFrame, // safe to reuse: the wrapper copies per writeFrame call
|
|
44
|
+
width: 640,
|
|
45
|
+
height: 480,
|
|
46
|
+
pixelFormat: "nv12",
|
|
47
|
+
pts: i, // ticks of the config timeBase
|
|
48
|
+
} satisfies VideoFrame);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const mp4 = await session.finish(); // terminal: complete fMP4 bytes
|
|
52
|
+
// -> write `mp4` to a file / stream
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
| Member | Notes |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `AutoVideoEncodeConfig.defaults(codec, width, height, timeBase)` | sensible defaults for the resolution; `codec` is `"h264" \| "hevc" \| "av1" \| "vp9"` |
|
|
60
|
+
| `openAutoEncoder(config)` | resolves a hardware backend or throws `EncoderUnavailableError` |
|
|
61
|
+
| `EncodeSession.writeFrame(frame)` | async; the frame is copied — reuse the buffer |
|
|
62
|
+
| `EncodeSession.finish()` | terminal; returns the complete fMP4 `Buffer` |
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT OR Apache-2.0. Part of the [Mediaway](https://github.com/nyxways/mediaway)
|
|
67
|
+
project — pre-1.0, APIs may change.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mediaway/encoder",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Automatic hardware video encoding to fragmented MP4 for Node.js (NVENC / Vulkan Video / QuickSync)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|