longpipe 0.0.13 โ†’ 0.0.15

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 CHANGED
@@ -1,281 +1,78 @@
1
1
  # Longpipe ๐Ÿ‰
2
2
 
3
- Fast, high quality virtual effects in the browser
3
+ Fast, high-quality video effects in the browser โ€” virtual backgrounds, face touch-up, auto-reframe, and mic noise removal in one open-source SDK.
4
4
 
5
+ <img width="960" height="540" alt="video-effects-sdk" src="https://github.com/user-attachments/assets/5dbe1ccb-09dd-4f22-b4be-e3122767dbcc" />
5
6
 
6
- <img width="640" height="360" alt="0087" src="https://github.com/user-attachments/assets/525f983c-6b3d-43ff-aedf-b1203e2955c1" />
7
-
8
-
9
-
10
- Try the live demo: [longpipe.dev/demo](https://longpipe.dev/demo)
7
+ **Try the live demo โ†’ [longpipe.dev/demo](https://longpipe.dev/demo)**
11
8
 
12
9
  > **Warning** โ€” This project is very new and still under active development. Expect API changes between versions and bugs.
13
10
 
14
- ## Features
15
-
16
- - **Support across browsers:** Works on every browser, simplifying dozens of browser inconsistencies in one simple API.
17
- - **Performance:** Longpipe was built from the ground up to work as well on 10-year-old netbooks as it does on the latest MacBook Pro.
18
- - **Adaptivity:** Longpipe has several model variants (xl to xs), auto-selecting to provide the best quality while maintaining 30 fps.
19
- - Built by the founder of [Vectorly](https://www.crunchbase.com/organization/vectorly), a commercial effects SDK acquired in 2021. A ground-up redesign for the WebGPU era, with years of production lessons baked in.
20
-
21
- ## Install
11
+ ## Quick start
22
12
 
23
13
  ```
24
14
  npm install longpipe
25
15
  ```
26
16
 
27
- ## Quick start
28
-
29
17
  ```ts
30
18
  import { EffectsPipeline } from 'longpipe'
31
19
 
32
- const inputStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true })
20
+ const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true })
33
21
 
34
- const pipeline = new EffectsPipeline(inputStream, {
35
- background: 'blur',
36
- audio: 'denoise'
22
+ const pipeline = new EffectsPipeline(stream, {
23
+ background: 'blur', // or an image, video, or solid color
24
+ touchup: true, // skin smoothing
25
+ reframe: true, // auto-frame the subject
26
+ audio: 'denoise', // mic noise removal
37
27
  })
38
28
 
39
29
  videoEl.srcObject = pipeline.stream // available immediately
40
30
  await pipeline.ready // optional โ€” resolves once the effect is live
41
31
  ```
42
32
 
43
- `pipeline.stream` is wired synchronously and emits the unprocessed input until the model is ready (~1โ€“3s on cold start, depending on hardware), so the consumer sees live video the whole time.
44
-
45
-
46
- ## Performance
47
-
48
- Longpipe uses custom-trained models built with an EfficientNet-Lite encoder and a U-Net style decoder, broken into five performance presets (`xs` through `xl`) that vary in encoder size, decoder width, and input resolution. Across all variants Longpipe has much higher segmentation accuracy than alternative open-source models like MediaPipe and BodyPix, while also delivering much better real-world performance โ€” the model runs as pure WebGPU/WebGL shaders in a zero-copy, fully-GPU pipeline.
49
-
50
- ### Quality
51
- Using average alpha pixel error on the P3M-10K valdation dataset (499 landscape images), all variants of Longpipe surpassed mediapipe in both MAE and IoU.
33
+ `pipeline.stream` is wired synchronously and emits the unprocessed input until the model is ready (~1โ€“3 s on cold start), so users see live video the whole time. Model weights stream from `cdn.longpipe.dev` by default โ€” no extra setup, and [self-hostable](https://longpipe.dev/docs/self-hosting).
52
34
 
53
- <img width="640" alt="lp-quality" src="https://github.com/user-attachments/assets/c7044937-95af-496f-893a-a05a50d7c914" />
35
+ ## Why Longpipe
54
36
 
55
- ### Speed
56
- With the pure GPU zero copy pipeline, Longpipe achieves better real world performance than mediapipe using much larger models.
37
+ - **One model, many effects.** Backgrounds, touch-up, and auto-reframe all run off a single shared encoder pass โ€” enabling another effect doesn't cost another inference. Audio denoise runs in a parallel `AudioWorklet`, off the GPU entirely. ([Architecture](https://longpipe.dev/docs/architecture))
38
+ - **More accurate *and* faster than the open-source alternatives.** Custom-trained models running as pure WebGPU/WebGL shaders in a zero-copy, fully-GPU pipeline โ€” no general-purpose runtime, no CPUโ†”GPU round trips.
39
+ - **Works everywhere.** Chromium, Firefox, and Safari (desktop + iOS). WebGPU when available, WebGL2 fallback, per-browser frame transport handled internally.
40
+ - **Adapts to the device.** Five model presets (`xs`โ€“`xl`); autotune benchmarks the actual device at init and an adaptive controller swaps presets at runtime to hold 30 fps โ€” on 10-year-old netbooks and the latest MacBook Pro alike.
41
+ - **Production pedigree.** Built by the founder of [Vectorly](https://www.crunchbase.com/organization/vectorly), a commercial effects SDK acquired in 2021 โ€” a ground-up redesign for the WebGPU era.
57
42
 
58
- <img width="640" alt="lp-speed" src="https://github.com/user-attachments/assets/ce658b8d-dc62-4d6b-90f8-cd62dfef2a59" />
43
+ ### Best models on the web
59
44
 
45
+ Longpipe's hydranet architecture, custom model-specific shaders, zero-memory-copy pipeline, developer friendly interface and 100% MIT open source license mean that ๐Ÿฒ Longpipe pareto dominates on performance, model quality and ease of use.
60
46
 
47
+ <img width="958" height="652" alt="lp-performance" src="https://github.com/user-attachments/assets/792b9f63-e8fd-4d30-aa90-9c92b6a0430c" />
61
48
 
62
49
 
50
+ ## Documentation
63
51
 
64
- ## Backgrounds
52
+ Full docs live at **[longpipe.dev/docs](https://longpipe.dev/docs)**:
65
53
 
66
- The `background` option takes a wide set of inputs and normalizes them internally:
67
-
68
- ```ts
69
- new EffectsPipeline(stream, { background: 'none' }) // passthrough
70
- new EffectsPipeline(stream, { background: 'blur' }) // default sigma
71
- new EffectsPipeline(stream, { background: { blur: { sigma: 12 } } })
72
-
73
- // images: URL, <img>, ImageBitmap, or { image: ... }
74
- new EffectsPipeline(stream, { background: 'https://example.com/bg.jpg' })
75
- new EffectsPipeline(stream, { background: imgElement })
76
- new EffectsPipeline(stream, { background: imageBitmap })
77
-
78
- // video: URL, Blob, or <video> โ€” looped, muted, decoded on the main thread
79
- new EffectsPipeline(stream, { background: { video: 'https://example.com/bg.mp4' } })
80
-
81
- // solid color โ€” hex string or [r, g, b] floats in [0, 1]
82
- new EffectsPipeline(stream, { background: { color: '#00b050' } }) // greenscreen
83
- new EffectsPipeline(stream, { background: { color: [0, 0.7, 0.3] } })
84
- ```
85
-
86
- Swap at runtime:
87
-
88
- ```ts
89
- await pipeline.setBackground({ blur: { sigma: 20 } })
90
- await pipeline.setBackground('https://example.com/other-bg.jpg')
91
- ```
92
-
93
- ## Performance presets
94
-
95
- ```ts
96
- new EffectsPipeline(stream, { preset: 'auto' }) // benchmarks at init (default)
97
- new EffectsPipeline(stream, { preset: 'fast' }) // small model
98
- new EffectsPipeline(stream, { preset: 'balanced' }) // medium model
99
- new EffectsPipeline(stream, { preset: 'quality' }) // xl model
100
- ```
101
-
102
- `'auto'` runs a microbenchmark at init and picks the largest preset that fits the per-frame budget on the current device, **topping out at `large`** โ€” `xl` is the explicit opt-in flagship (`'quality'` or a manual config). While `'auto'` is in effect an adaptive controller polls FPS / model time and swaps preset up or down as conditions change. Explicit preset choices (`'fast'`, `'balanced'`, `'quality'`, or a manual config) are always respected and never auto-overridden.
103
-
104
- You can also pass a manual config:
105
-
106
- ```ts
107
- new EffectsPipeline(stream, {
108
- preset: { model: 'large', dtype: 'f32', resolution: { w: 640, h: 400 }, skipFrames: 0 },
109
- })
110
- ```
111
-
112
- ## Audio denoise
113
-
114
- Real-time speech denoising runs as a **separate AudioWorklet pipeline** on the audio render thread โ€” independent of the video/GPU pipeline, in parallel. Pass `audio: 'denoise'` and the input stream's mic is cleaned in place; `pipeline.stream` carries the denoised audio track.
115
-
116
- ```ts
117
- const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true })
118
- new EffectsPipeline(stream, { audio: 'denoise' }) // auto-picks a model for the device
119
- ```
120
-
121
- Three models back three tiers. `auto` (the default) runs a tiny **weight-free probe** at init โ€” it times the real network on this device *without* downloading the multi-MB weights โ€” and picks the best fit:
122
-
123
- | `model` | tier | what it is |
124
- |-----------|------|------------|
125
- | `dfn` | high | DeepFilterNet3, full f32 โ€” best quality |
126
- | `dfnint8` | mid | DeepFilterNet3 with int8 GRUs โ€” smaller download, faster on weak hardware |
127
- | `rnnoise` | low | classic RNNoise โ€” tiny, and the fallback where wasm SIMD is unavailable |
128
-
129
- ```ts
130
- // force a specific model or tier instead of probing
131
- new EffectsPipeline(stream, { audio: { denoise: { model: 'dfn' } } })
132
-
133
- interface DenoiseOptions {
134
- model?: 'auto' | 'high' | 'mid' | 'low' | 'rnnoise' | 'dfn' | 'dfnint8' // default 'auto'
135
- postFilterBeta?: number // DFN post-filter, suppresses residual noise (default 0.03)
136
- gruLeak?: number // DFN recurrent-drift bound (default 0.995)
137
- enabled?: boolean // start denoising vs. passthrough (default true)
138
- }
139
- ```
140
-
141
- Toggle, reconfigure, and inspect at runtime:
142
-
143
- ```ts
144
- pipeline.setDenoise(false) // passthrough (cheap to re-enable)
145
- pipeline.setDenoise({ postFilterBeta: 0.05 }) // tweak DFN params live
146
- pipeline.getAudioStats() // { model, p50Ms, p95Ms, latencyMs, sampleRate, active }
147
- ```
148
-
149
- The denoiser handles sample-rate conversion internally (it runs at 48 kHz and resamples when the device can't). `pipeline.ready` resolves on the video first frame and does **not** wait on audio โ€” denoising joins asynchronously, with the mic passing through until it's live.
150
-
151
- ## Other options
152
-
153
- ```ts
154
- new EffectsPipeline(stream, {
155
- background: 'blur',
156
- preset: 'auto',
157
- adaptive: true, // default; only applies when preset is 'auto'
158
- audio: 'denoise', // 'passthrough' | 'drop' | 'denoise' | { denoise: {...} }
159
- outputResolution: { w: 1280, h: 720 }, // default: matches the input video track
160
- weightsBaseUrl: 'https://your-cdn/longpipe/', // default: cdn.longpipe.dev
161
- enabled: true, // false = pass input through unchanged
162
- onReady: () => console.log('live'),
163
- onError: (err) => console.error(err),
164
- })
165
- ```
166
-
167
- Toggle the effect on/off without tearing anything down (cheap to re-enable):
168
-
169
- ```ts
170
- pipeline.setEnabled(false)
171
- ```
172
-
173
- Tear it all down:
174
-
175
- ```ts
176
- pipeline.destroy()
177
- ```
178
-
179
- ## Self-hosting weights
180
-
181
- By default Longpipe fetches model weights from `https://cdn.longpipe.dev/models/v/0.0.5/`. You can browse the available files, sizes, and SHA-256 hashes at [cdn.longpipe.dev/models/v/0.0.5/index.html](https://cdn.longpipe.dev/models/v/0.0.5/index.html) (machine-readable list at [manifest.json](https://cdn.longpipe.dev/models/v/0.0.5/manifest.json)).
182
-
183
- To serve them yourself, mirror the files under any base URL with the same `model_${name}.bin` naming convention and pass it via `weightsBaseUrl`:
184
-
185
- ```ts
186
- new EffectsPipeline(stream, {
187
- weightsBaseUrl: 'https://your-cdn.example.com/longpipe-weights/',
188
- })
189
- ```
190
-
191
- ## Browser support
192
-
193
- Works on Chromium (Chrome, Edge), Firefox, and Safari (desktop and iOS). WebGPU is used when available; WebGL2 is the fallback. Longpipe picks the optimal video frame transport for each browser internally โ€” `MediaStreamTrackProcessor`, `transferControlToOffscreen` + `captureStream`, or an `ImageBitmap` shuttle as universal fallback โ€” all invisible to the caller.
194
-
195
-
196
-
197
- ## Face touch-up
198
-
199
- UV-space skin smoothing (the "beautify" filter). It runs **in parallel with any background effect** โ€” both features share one encoder pass per frame, and the retouched frame feeds the background compositor.
200
-
201
- ```ts
202
- new EffectsPipeline(stream, {
203
- background: 'blur',
204
- touchup: { strength: 0.6 }, // presence enables it
205
- })
206
-
207
- await pipeline.setTouchup({ strength: 0.8, style: 'bilateral' }) // live update
208
- await pipeline.setTouchup(null) // disable
209
- ```
210
-
211
- ```ts
212
- interface TouchupOptions {
213
- strength?: number // 0..1 โ€” blend of smoothed skin over original (default 0.6)
214
- amount?: number // smoothing radius (default 8)
215
- detail?: number // high-frequency (pore texture) keep โ€” freq-sep only (default 0.35)
216
- style?: 'freq-sep' | 'bilateral' // default 'freq-sep'
217
- }
218
- ```
219
-
220
- How it works: a 5-point face-keypoint head rides the matting encoder (no second encoder pass); its heatmaps are decoded on the GPU into a face box; a 478-point landmark model runs on the face crop; the face is unwrapped into a pose-independent UV atlas, smoothed there, and composited back through a per-region weight mask. Eyes, brows, and lips are protected and stay pixel-exact; `'freq-sep'` smooths while keeping pore-level texture, `'bilateral'` is a stronger edge-preserving filter. The whole chain is GPU-resident โ€” no per-frame readback.
221
-
222
- On first enable the landmark weights (`model_landmark_mesh.bin`, ~2.6 MB) and two small static assets are fetched from `weightsBaseUrl`, then cached; parameter updates are instant. With no face in frame the effect passes through cleanly.
223
-
224
- Current limitation: single face โ€” with multiple people in frame, detection can jump between faces. Multi-face support is on the roadmap.
225
-
226
- ## How it works
227
-
228
- Two layers:
229
-
230
- - **Model** (`src/model/`) โ€” a shared EfficientNet-Lite encoder (lite0; lite3 on the `xl` tier) feeding multiple heads: a U-Net matting decoder (sharpened at higher resolution by a lightweight U-Net *wrapper*), a 5-point face-keypoint head (drives touch-up, and auto-reframe later), and a small optical-flow head that provides temporal stability โ€” the renderer warps the previous outputs along the predicted flow and blends them through a flow-gated stabilizer, so the matte is steady without any recurrent state in the network. A separate 478-point landmark model runs on the detected face crop. Written as TypeScript op classes โ€” each layer is a class; weights load as binary tensors at init; the backend (WebGPU or WebGL2) is injected at construction. BatchNorm is fused into conv weights at export โ€” there is no BN op at inference.
231
- - **Pipeline** (`src/pipeline/`) โ€” capability detection, per-browser frame transport selection, worker spawn, audio passthrough, autotune, and the adaptive controller. Designed to absorb the browser/codec/canvas plumbing complexity so consumers don't have to.
232
-
233
- Five trained presets cover the hardware range. "Resolution" is the model's working (canvas) resolution; the encoder runs at a lower internal resolution and the U-Net wrapper refines back up to this.
234
-
235
- | Preset | Resolution | Encoder | Decoder | Skip frames |
236
- |--------|------------|--------------|----------|-------------|
237
- | xl | 1280ร—768 | full (lite3) | 2ร— ch | 0 |
238
- | large | 640ร—400 | full (lite0) | standard | 0 |
239
- | medium | 512ร—320 | full (lite0) | standard | 1 |
240
- | small | 384ร—224 | small | standard | 1 |
241
- | xs | 384ร—240 | small | standard | 2 |
242
-
243
- `Skip frames` is how many input frames the model sits out between runs โ€” the compositor still renders every frame using the most recent alpha matte. Autotune picks one of these at init based on a microbenchmark of the actual network on the actual device.
244
-
245
- ## Development
246
-
247
- Training scripts, fixture generation, and the weight export pipeline are not yet documented here โ€” coming soon.
54
+ - [Getting started](https://longpipe.dev/docs/getting-started)
55
+ - [API reference](https://longpipe.dev/docs/api) โ€” all `EffectsPipeline` options and methods
56
+ - [Architecture](https://longpipe.dev/docs/architecture) โ€” the hydranet: one encoder, many heads
57
+ - [Backgrounds](https://longpipe.dev/docs/backgrounds) ยท [Touch-up](https://longpipe.dev/docs/touchup) ยท [Auto-reframe](https://longpipe.dev/docs/reframe) ยท [Audio denoise](https://longpipe.dev/docs/audio)
58
+ - [Presets & autotune](https://longpipe.dev/docs/presets)
59
+ - [Model layer](https://longpipe.dev/docs/model-layer) โ€” drive the model directly, without the pipeline
60
+ - [Self-hosting weights](https://longpipe.dev/docs/self-hosting)
248
61
 
62
+ Machine-readable for LLMs and agents: [`llms.txt`](https://longpipe.dev/llms.txt) ยท [`llms-full.txt`](https://longpipe.dev/llms-full.txt)
249
63
 
250
64
  ## Roadmap
251
65
 
252
66
  - [x] Background segmentation / virtual backgrounds
253
67
  - [x] Background noise removal (audio, separate pipeline)
254
68
  - [x] Face landmarks + touch-up
255
- - [ ] Multi-face support
256
- - [ ] Auto-reframe
69
+ - [x] Multi-face support
70
+ - [x] Auto-reframe
257
71
  - [ ] AR effects
258
72
  - [ ] Lighting correction
259
73
 
260
-
261
74
  ## License
262
75
 
263
- SDK source code is MIT-licensed โ€” see [LICENSE](LICENSE).
264
-
265
- The pre-trained model weights distributed via `cdn.longpipe.dev` (and any mirrored copies) are also MIT-licensed โ€” see [WEIGHTS_LICENSE](WEIGHTS_LICENSE). You're free to self-host them inside other open-source or commercial projects under MIT-compatible terms.
266
-
267
- ### Training data and pretrained weights
268
-
269
- Longpipe's pre-trained weights are released under MIT (see [WEIGHTS_LICENSE](WEIGHTS_LICENSE)). They were trained on:
270
-
271
- - [P3M-10k](https://github.com/JizhiziLi/P3M) โ€” MIT
272
- - [AISegment Matting Human Datasets](https://www.kaggle.com/datasets/laurentmih/aisegmentcom-matting-human-datasets) โ€” MIT ([upstream license](https://github.com/aisegmentcn/matting_human_datasets/blob/master/LICENSE))
273
- - [COCO](https://cocodataset.org) CC BY 4.0
274
- - [OpenImages](https://storage.googleapis.com/openimages/web/index.html) CC by 4.0
275
- - Synthetic images generated with [Z-Image](https://github.com/Tongyi-MAI/Z-Image) (text-to-image) โ€” Apache 2.0
276
- - A custom dataset of short webcam videos collected via [Prolific](https://www.prolific.com/), from participants who gave explicit, informed consent for their footage to be used to train an open-source virtual-background model. Faces are blurred before training; the raw videos are stored privately (EU), never distributed, and deleted after the training window.
277
- - Pseudo-labels generated by [BiRefNet](https://github.com/ZhengPeng7/BiRefNet) (MIT), used as a teacher model
278
-
279
- The encoder is initialized from a pre-trained [EfficientNet-Lite](https://github.com/RangiLyu/EfficientNet-Lite) backbone โ€” Apache 2.0.
76
+ SDK source code **and** pre-trained model weights are MIT-licensed โ€” see [LICENSE](LICENSE) and [WEIGHTS_LICENSE](WEIGHTS_LICENSE). You're free to self-host the weights inside other open-source or commercial projects under MIT-compatible terms.
280
77
 
281
- As is standard for trained models, the released weights are not a redistribution of any training image or video โ€” they are published under MIT.
78
+ The weights were trained on permissively-licensed public datasets (P3M-10k, AISegment, COCO, OpenImages), Z-Image synthetics, and a custom webcam dataset collected with participants' explicit, informed consent. The full dataset list and provenance details: [longpipe.dev/docs/licensing](https://longpipe.dev/docs/licensing).