@stream-io/video-filters-web 0.7.0 → 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/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.0";
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
@@ -1591,7 +1591,7 @@ const fetchModel = async (modelFilePath) => {
1591
1591
  let lastModelFilePath = '';
1592
1592
  let modelFileCache;
1593
1593
  const loadMediaPipe = async (options = {}) => {
1594
- const { basePath = `https://unpkg.com/${packageName}@${version}/mediapipe`, modelPath = `${basePath}/models/selfie_segmenter.tflite`, } = options;
1594
+ const { basePath = `https://unpkg.com/${packageName}@${version}/mediapipe`, modelPath = `${basePath}/models/selfie_segmenter_landscape.tflite`, } = options;
1595
1595
  const model = modelPath === lastModelFilePath && modelFileCache
1596
1596
  ? modelFileCache
1597
1597
  : await fetch(modelPath).then((r) => r.arrayBuffer());
@@ -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
- bgBlur: 5,
1606
- bgBlurRadius: 3,
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);
@@ -2578,7 +2568,8 @@ class VirtualBackground extends BaseVideoProcessor {
2578
2568
  this.opts = await this.initializeSegmenterOptions();
2579
2569
  const basePath = this.options.basePath ||
2580
2570
  `https://unpkg.com/${packageName}@${version}/mediapipe`;
2581
- const model = this.options.modelPath || `${basePath}/models/selfie_segmenter.tflite`;
2571
+ const model = this.options.modelPath ||
2572
+ `${basePath}/models/selfie_segmenter_landscape.tflite`;
2582
2573
  const fileset = await FilesetResolver.forVisionTasks(`${basePath}/wasm`);
2583
2574
  this.segmenter = await ImageSegmenter.createFromOptions(fileset, {
2584
2575
  baseOptions: { modelAssetPath: model, delegate: 'GPU' },
@@ -2596,11 +2587,13 @@ class VirtualBackground extends BaseVideoProcessor {
2596
2587
  }
2597
2588
  async transform(frame) {
2598
2589
  const currentTime = frame.timestamp;
2599
- const hasNewFrame = currentTime !== this.lastFrameTime;
2590
+ const hasNewFrame = currentTime - this.lastFrameTime > 1000;
2600
2591
  this.lastFrameTime = currentTime;
2601
2592
  if (hasNewFrame && this.isSegmenterReady && this.segmenter) {
2593
+ const start = performance.now();
2602
2594
  await this.runSegmentation(frame);
2603
2595
  this.webGlRenderer.render(frame, this.opts, this.latestCategoryMask, this.latestConfidenceMask);
2596
+ this.updateStats(performance.now() - start);
2604
2597
  }
2605
2598
  return new VideoFrame(this.canvas, { timestamp: frame.timestamp });
2606
2599
  }
@@ -2640,18 +2633,13 @@ class VirtualBackground extends BaseVideoProcessor {
2640
2633
  };
2641
2634
  }
2642
2635
  const blurLevel = this.options.backgroundBlurLevel;
2643
- if (typeof blurLevel === 'string') {
2644
- return {
2645
- ...BACKGROUND_BLUR_MAP[blurLevel],
2646
- backgroundSource: undefined,
2647
- isSelfieMode,
2648
- };
2649
- }
2650
- const numeric = blurLevel ?? 5;
2636
+ const strength = typeof blurLevel === 'string'
2637
+ ? BACKGROUND_BLUR_MAP[blurLevel]
2638
+ : Math.round(blurLevel ?? 5);
2651
2639
  return {
2652
2640
  backgroundSource: undefined,
2653
- bgBlur: Math.min(numeric * 3, 30),
2654
- bgBlurRadius: Math.min(numeric, 10),
2641
+ bgBlur: Math.min(strength * 1.5, 20),
2642
+ bgBlurRadius: Math.min(strength, 10),
2655
2643
  isSelfieMode,
2656
2644
  };
2657
2645
  }