@stream-io/video-filters-web 0.7.4 → 0.8.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/CHANGELOG.md +12 -0
- package/dist/index.cjs.js +73 -27
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +73 -27
- package/dist/index.es.js.map +1 -1
- package/package.json +10 -8
package/dist/index.es.js
CHANGED
|
@@ -1559,7 +1559,7 @@ const createTFLiteSIMDModule = (__Module) => {
|
|
|
1559
1559
|
return __Module.ready;
|
|
1560
1560
|
};
|
|
1561
1561
|
|
|
1562
|
-
const version = "0.
|
|
1562
|
+
const version = "0.8.0";
|
|
1563
1563
|
const packageName = "@stream-io/video-filters-web";
|
|
1564
1564
|
|
|
1565
1565
|
// @ts-expect-error - module is not declared
|
|
@@ -1610,11 +1610,33 @@ const BACKGROUND_BLUR_MAP = {
|
|
|
1610
1610
|
};
|
|
1611
1611
|
|
|
1612
1612
|
class WebGLRenderer {
|
|
1613
|
+
canvas;
|
|
1614
|
+
gl;
|
|
1615
|
+
stateUpdateProgram;
|
|
1616
|
+
maskRefineProgram;
|
|
1617
|
+
blurProgram;
|
|
1618
|
+
blendProgram;
|
|
1619
|
+
stateUpdateLocations;
|
|
1620
|
+
maskRefineLocations;
|
|
1621
|
+
blurLocations;
|
|
1622
|
+
blendLocations;
|
|
1623
|
+
positionBuffer;
|
|
1624
|
+
texCoordBuffer;
|
|
1625
|
+
storedStateTextures;
|
|
1626
|
+
fbo;
|
|
1627
|
+
refineFbo;
|
|
1628
|
+
refinedMaskTexture;
|
|
1629
|
+
frameTexture;
|
|
1630
|
+
blurTexture1;
|
|
1631
|
+
blurTexture2;
|
|
1632
|
+
blurFbo1;
|
|
1633
|
+
blurFbo2;
|
|
1634
|
+
running = false;
|
|
1635
|
+
static DEFAULT_BG_COLOR = [33, 150, 243, 255];
|
|
1636
|
+
currentStateIndex = 0;
|
|
1637
|
+
backgroundRenderInfo = null;
|
|
1638
|
+
activeBackgroundSourceIdentifier = null;
|
|
1613
1639
|
constructor(canvas) {
|
|
1614
|
-
this.running = false;
|
|
1615
|
-
this.currentStateIndex = 0;
|
|
1616
|
-
this.backgroundRenderInfo = null;
|
|
1617
|
-
this.activeBackgroundSourceIdentifier = null;
|
|
1618
1640
|
this.canvas = canvas;
|
|
1619
1641
|
const gl = this.canvas.getContext('webgl2', {
|
|
1620
1642
|
alpha: false,
|
|
@@ -2307,7 +2329,6 @@ class WebGLRenderer {
|
|
|
2307
2329
|
this.activeBackgroundSourceIdentifier = null;
|
|
2308
2330
|
}
|
|
2309
2331
|
}
|
|
2310
|
-
WebGLRenderer.DEFAULT_BG_COLOR = [33, 150, 243, 255];
|
|
2311
2332
|
|
|
2312
2333
|
/**
|
|
2313
2334
|
* Fallback video processor for browsers that do not support MediaStreamTrackGenerator.
|
|
@@ -2373,13 +2394,10 @@ const TrackGenerator = typeof MediaStreamTrackGenerator !== 'undefined'
|
|
|
2373
2394
|
* into the canvas and update the underlying track automatically.
|
|
2374
2395
|
*/
|
|
2375
2396
|
class FallbackProcessor {
|
|
2397
|
+
readable;
|
|
2398
|
+
workerTimer;
|
|
2399
|
+
video;
|
|
2376
2400
|
constructor({ track }) {
|
|
2377
|
-
this.close = () => {
|
|
2378
|
-
this.video.pause();
|
|
2379
|
-
this.video.srcObject = null;
|
|
2380
|
-
this.video.src = '';
|
|
2381
|
-
this.workerTimer.destroy();
|
|
2382
|
-
};
|
|
2383
2401
|
if (!track)
|
|
2384
2402
|
throw new Error('MediaStreamTrack is required');
|
|
2385
2403
|
if (track.kind !== 'video') {
|
|
@@ -2442,6 +2460,12 @@ class FallbackProcessor {
|
|
|
2442
2460
|
},
|
|
2443
2461
|
});
|
|
2444
2462
|
}
|
|
2463
|
+
close = () => {
|
|
2464
|
+
this.video.pause();
|
|
2465
|
+
this.video.srcObject = null;
|
|
2466
|
+
this.video.src = '';
|
|
2467
|
+
this.workerTimer.destroy();
|
|
2468
|
+
};
|
|
2445
2469
|
}
|
|
2446
2470
|
const TrackProcessor = typeof MediaStreamTrackProcessor !== 'undefined'
|
|
2447
2471
|
? MediaStreamTrackProcessor
|
|
@@ -2460,15 +2484,20 @@ const TrackProcessor = typeof MediaStreamTrackProcessor !== 'undefined'
|
|
|
2460
2484
|
* `MediaStreamTrack` ready to use.
|
|
2461
2485
|
*/
|
|
2462
2486
|
class BaseVideoProcessor {
|
|
2487
|
+
track;
|
|
2488
|
+
processor;
|
|
2489
|
+
generator;
|
|
2490
|
+
hooks;
|
|
2491
|
+
abortController = new AbortController();
|
|
2492
|
+
canvas;
|
|
2493
|
+
frames = 0;
|
|
2494
|
+
delayTotal = 0;
|
|
2495
|
+
lastStatsTime = 0;
|
|
2463
2496
|
/**
|
|
2464
2497
|
* Constructs a new instance.
|
|
2465
2498
|
*/
|
|
2466
2499
|
constructor(track, hooks = {}) {
|
|
2467
2500
|
this.track = track;
|
|
2468
|
-
this.abortController = new AbortController();
|
|
2469
|
-
this.frames = 0;
|
|
2470
|
-
this.delayTotal = 0;
|
|
2471
|
-
this.lastStatsTime = 0;
|
|
2472
2501
|
this.processor = new TrackProcessor({ track });
|
|
2473
2502
|
this.generator = new TrackGenerator({
|
|
2474
2503
|
kind: 'video',
|
|
@@ -2550,14 +2579,17 @@ class BaseVideoProcessor {
|
|
|
2550
2579
|
* on a new MediaStreamVideoTrack for downstream consumption.
|
|
2551
2580
|
*/
|
|
2552
2581
|
class VirtualBackground extends BaseVideoProcessor {
|
|
2582
|
+
options;
|
|
2583
|
+
segmenter = null;
|
|
2584
|
+
isSegmenterReady = false;
|
|
2585
|
+
webGlRenderer;
|
|
2586
|
+
opts;
|
|
2587
|
+
latestCategoryMask = undefined;
|
|
2588
|
+
latestConfidenceMask = undefined;
|
|
2589
|
+
lastFrameTime = -1;
|
|
2553
2590
|
constructor(track, options = {}, hooks = {}) {
|
|
2554
2591
|
super(track, hooks);
|
|
2555
2592
|
this.options = options;
|
|
2556
|
-
this.segmenter = null;
|
|
2557
|
-
this.isSegmenterReady = false;
|
|
2558
|
-
this.latestCategoryMask = undefined;
|
|
2559
|
-
this.latestConfidenceMask = undefined;
|
|
2560
|
-
this.lastFrameTime = -1;
|
|
2561
2593
|
}
|
|
2562
2594
|
async initialize() {
|
|
2563
2595
|
this.webGlRenderer = new WebGLRenderer(this.canvas);
|
|
@@ -2588,7 +2620,7 @@ class VirtualBackground extends BaseVideoProcessor {
|
|
|
2588
2620
|
}
|
|
2589
2621
|
async transform(frame) {
|
|
2590
2622
|
const currentTime = frame.timestamp;
|
|
2591
|
-
const hasNewFrame = currentTime - this.lastFrameTime >
|
|
2623
|
+
const hasNewFrame = currentTime - this.lastFrameTime > 1_000;
|
|
2592
2624
|
this.lastFrameTime = currentTime;
|
|
2593
2625
|
if (hasNewFrame && this.isSegmenterReady && this.segmenter) {
|
|
2594
2626
|
const start = performance.now();
|
|
@@ -2683,12 +2715,24 @@ class VirtualBackground extends BaseVideoProcessor {
|
|
|
2683
2715
|
* and upscaling back to full resolution for output.
|
|
2684
2716
|
*/
|
|
2685
2717
|
class FullScreenBlurRenderer {
|
|
2718
|
+
canvas;
|
|
2719
|
+
gl;
|
|
2720
|
+
blurProgramHandle;
|
|
2721
|
+
blurLocations;
|
|
2722
|
+
passthroughProgramHandle;
|
|
2723
|
+
passthroughLocations;
|
|
2724
|
+
positionBuffer;
|
|
2725
|
+
texCoordBuffer;
|
|
2726
|
+
pingTexture;
|
|
2727
|
+
pongTexture;
|
|
2728
|
+
pingFbo;
|
|
2729
|
+
pongFbo;
|
|
2730
|
+
inputTexture = null;
|
|
2731
|
+
isRunning = false;
|
|
2732
|
+
targetWidth = 0;
|
|
2733
|
+
targetHeight = 0;
|
|
2734
|
+
weightCache = new Map();
|
|
2686
2735
|
constructor(canvas) {
|
|
2687
|
-
this.inputTexture = null;
|
|
2688
|
-
this.isRunning = false;
|
|
2689
|
-
this.targetWidth = 0;
|
|
2690
|
-
this.targetHeight = 0;
|
|
2691
|
-
this.weightCache = new Map();
|
|
2692
2736
|
this.canvas = canvas;
|
|
2693
2737
|
const gl = canvas.getContext('webgl2', {
|
|
2694
2738
|
alpha: false,
|
|
@@ -2946,6 +2990,8 @@ class FullScreenBlurRenderer {
|
|
|
2946
2990
|
* by the base processor.
|
|
2947
2991
|
*/
|
|
2948
2992
|
class FullScreenBlur extends BaseVideoProcessor {
|
|
2993
|
+
blurRenderer;
|
|
2994
|
+
blurRadius;
|
|
2949
2995
|
/**
|
|
2950
2996
|
* Creates a new full-screen blur processor for the given video track.
|
|
2951
2997
|
*
|