@mediaway/container 0.1.0 → 0.1.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 (2) hide show
  1. package/README.md +85 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # @mediaway/container
2
+
3
+ Sans-IO **fragmented MP4 (fMP4) mux and demux** over Mediaway's C ABI. The
4
+ muxer/demuxer never touch files or sockets — you push packets in and poll
5
+ bytes out, and own every byte of I/O.
6
+
7
+ Backed by the `iso-bmff` core crate (sans-io, unit-tested) and the native
8
+ `mediaway_ffi.dll` (shipped by `@mediaway/ffi`).
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @mediaway/container
14
+ ```
15
+
16
+ Windows x64 (native DLL). The `@mediaway/ffi` dependency is installed
17
+ automatically.
18
+
19
+ ## Mux example
20
+
21
+ ```ts
22
+ import { Muxer, Demuxer, type VideoTrackInfo, type AudioTrackInfo, type Packet } from "@mediaway/container";
23
+
24
+ const muxer = new Muxer();
25
+
26
+ const videoTrack: VideoTrackInfo = {
27
+ codec: "h264",
28
+ width: 640,
29
+ height: 480,
30
+ pixelFormat: "nv12",
31
+ timeBase: { num: 1, den: 30 },
32
+ };
33
+ const audioTrack: AudioTrackInfo = {
34
+ codec: "aac",
35
+ sampleRate: 48_000,
36
+ channels: 2,
37
+ timeBase: { num: 1, den: 48_000 },
38
+ };
39
+
40
+ const v = muxer.addVideoTrack(videoTrack);
41
+ const a = muxer.addAudioTrack(audioTrack);
42
+ const chunks: Buffer[] = [muxer.begin()]; // init segment (ftyp + moov)
43
+
44
+ for (let i = 0; i < 90; i++) {
45
+ muxer.push({
46
+ trackIndex: v,
47
+ data: fakeH264Packet(i), // your encoded bytes
48
+ pts: i, // ticks of the track timeBase
49
+ duration: 1,
50
+ key: i % 30 === 0,
51
+ } satisfies Packet);
52
+ }
53
+ muxer.flush(); // finalize the last fragment
54
+ chunks.push(muxer.pollBytes()); // drain everything queued
55
+ muxer.close();
56
+ // chunks -> concatenate and write to a file / stream
57
+ ```
58
+
59
+ ## Demux example
60
+
61
+ ```ts
62
+ const demuxer = new Demuxer();
63
+ demuxer.pushBytes(buffer); // feed chunks as they arrive
64
+ const streams = demuxer.streams(); // TrackInfo[] once moov parsed
65
+ for (;;) {
66
+ const packet = demuxer.pollPacket(); // Packet | null
67
+ if (!packet) break;
68
+ // packet.trackIndex, packet.data, packet.pts, packet.duration, packet.key
69
+ }
70
+ demuxer.close();
71
+ ```
72
+
73
+ ## API
74
+
75
+ | Class | Methods | Notes |
76
+ | --- | --- | --- |
77
+ | `Muxer` | `addVideoTrack`, `addAudioTrack`, `begin`, `push`, `flush`, `pollBytes`, `close` | sans-io: never blocks, never touches I/O |
78
+ | `Demuxer` | `pushBytes`, `streams`, `pollPacket`, `close` | streaming — feed repeatedly |
79
+
80
+ Errors surface as `MediawayError` (with an ABI-level code).
81
+
82
+ ## License
83
+
84
+ MIT OR Apache-2.0. Part of the [Mediaway](https://github.com/nyxways/mediaway)
85
+ project — pre-1.0, APIs may change.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mediaway/container",
3
- "version": "0.1.0",
4
- "description": "Mediaway fMP4 mux/demux over the C ABI (mediaway-ffi)",
3
+ "version": "0.1.1",
4
+ "description": "Sans-IO fragmented MP4 (fMP4) mux and demux for Node.js — push packets in, poll bytes out",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",