@stream-io/video-filters-web 0.7.1 → 0.7.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/CHANGELOG.md +6 -0
- package/dist/index.cjs.js +15 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +15 -28
- package/dist/index.es.js.map +1 -1
- package/dist/src/BaseVideoProcessor.d.ts +1 -1
- package/dist/src/VirtualBackground.d.ts +0 -1
- package/dist/src/types.d.ts +4 -4
- package/package.json +1 -1
- package/src/BaseVideoProcessor.ts +1 -4
- package/src/VirtualBackground.ts +11 -13
- package/src/types.ts +7 -16
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.7.
|
|
1562
|
+
const version = "0.7.2";
|
|
1563
1563
|
const packageName = "@stream-io/video-filters-web";
|
|
1564
1564
|
|
|
1565
1565
|
// @ts-expect-error - module is not declared
|
|
@@ -1600,19 +1600,13 @@ const loadMediaPipe = async (options = {}) => {
|
|
|
1600
1600
|
return model;
|
|
1601
1601
|
};
|
|
1602
1602
|
|
|
1603
|
+
/**
|
|
1604
|
+
* Maps blur level to blur strength values.
|
|
1605
|
+
*/
|
|
1603
1606
|
const BACKGROUND_BLUR_MAP = {
|
|
1604
|
-
low:
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
},
|
|
1608
|
-
medium: {
|
|
1609
|
-
bgBlur: 15,
|
|
1610
|
-
bgBlurRadius: 4,
|
|
1611
|
-
},
|
|
1612
|
-
high: {
|
|
1613
|
-
bgBlur: 30,
|
|
1614
|
-
bgBlurRadius: 5,
|
|
1615
|
-
},
|
|
1607
|
+
low: 3,
|
|
1608
|
+
medium: 5,
|
|
1609
|
+
high: 7,
|
|
1616
1610
|
};
|
|
1617
1611
|
|
|
1618
1612
|
class WebGLRenderer {
|
|
@@ -2498,10 +2492,7 @@ class BaseVideoProcessor {
|
|
|
2498
2492
|
this.canvas.width = frame.displayWidth;
|
|
2499
2493
|
this.canvas.height = frame.displayHeight;
|
|
2500
2494
|
}
|
|
2501
|
-
const start = performance.now();
|
|
2502
2495
|
const processed = await this.transform(frame);
|
|
2503
|
-
const delay = performance.now() - start;
|
|
2504
|
-
this.updateStats(delay);
|
|
2505
2496
|
controller.enqueue(processed);
|
|
2506
2497
|
}
|
|
2507
2498
|
catch (e) {
|
|
@@ -2567,7 +2558,6 @@ class VirtualBackground extends BaseVideoProcessor {
|
|
|
2567
2558
|
this.latestCategoryMask = undefined;
|
|
2568
2559
|
this.latestConfidenceMask = undefined;
|
|
2569
2560
|
this.lastFrameTime = -1;
|
|
2570
|
-
this.count = 0;
|
|
2571
2561
|
}
|
|
2572
2562
|
async initialize() {
|
|
2573
2563
|
this.webGlRenderer = new WebGLRenderer(this.canvas);
|
|
@@ -2597,11 +2587,13 @@ class VirtualBackground extends BaseVideoProcessor {
|
|
|
2597
2587
|
}
|
|
2598
2588
|
async transform(frame) {
|
|
2599
2589
|
const currentTime = frame.timestamp;
|
|
2600
|
-
const hasNewFrame = currentTime
|
|
2590
|
+
const hasNewFrame = currentTime - this.lastFrameTime > 1000;
|
|
2601
2591
|
this.lastFrameTime = currentTime;
|
|
2602
2592
|
if (hasNewFrame && this.isSegmenterReady && this.segmenter) {
|
|
2593
|
+
const start = performance.now();
|
|
2603
2594
|
await this.runSegmentation(frame);
|
|
2604
2595
|
this.webGlRenderer.render(frame, this.opts, this.latestCategoryMask, this.latestConfidenceMask);
|
|
2596
|
+
this.updateStats(performance.now() - start);
|
|
2605
2597
|
}
|
|
2606
2598
|
return new VideoFrame(this.canvas, { timestamp: frame.timestamp });
|
|
2607
2599
|
}
|
|
@@ -2641,18 +2633,13 @@ class VirtualBackground extends BaseVideoProcessor {
|
|
|
2641
2633
|
};
|
|
2642
2634
|
}
|
|
2643
2635
|
const blurLevel = this.options.backgroundBlurLevel;
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
backgroundSource: undefined,
|
|
2648
|
-
isSelfieMode,
|
|
2649
|
-
};
|
|
2650
|
-
}
|
|
2651
|
-
const numeric = blurLevel ?? 5;
|
|
2636
|
+
const strength = typeof blurLevel === 'string'
|
|
2637
|
+
? BACKGROUND_BLUR_MAP[blurLevel]
|
|
2638
|
+
: Math.round(blurLevel ?? 5);
|
|
2652
2639
|
return {
|
|
2653
2640
|
backgroundSource: undefined,
|
|
2654
|
-
bgBlur: Math.min(
|
|
2655
|
-
bgBlurRadius: Math.min(
|
|
2641
|
+
bgBlur: Math.min(strength * 1.5, 20),
|
|
2642
|
+
bgBlurRadius: Math.min(strength, 10),
|
|
2656
2643
|
isSelfieMode,
|
|
2657
2644
|
};
|
|
2658
2645
|
}
|