@stream-io/video-filters-web 0.7.2 → 0.7.4
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 +12 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +12 -8
- package/dist/index.es.js.map +1 -1
- package/dist/src/WebGLRenderer.d.ts +5 -0
- package/dist/src/types.d.ts +31 -0
- package/package.json +2 -2
- package/src/VirtualBackground.ts +10 -3
- package/src/WebGLRenderer.ts +17 -3
- package/src/types.ts +34 -0
|
@@ -75,6 +75,11 @@ export declare class WebGLRenderer {
|
|
|
75
75
|
bgBlur: number;
|
|
76
76
|
bgBlurRadius: number;
|
|
77
77
|
isSelfieMode: boolean;
|
|
78
|
+
segmentationOptions?: {
|
|
79
|
+
smoothingFactor?: number;
|
|
80
|
+
smoothstepMin?: number;
|
|
81
|
+
smoothstepMax?: number;
|
|
82
|
+
};
|
|
78
83
|
}, categoryTexture?: WebGLTexture, confidenceTexture?: WebGLTexture): void;
|
|
79
84
|
close(): void;
|
|
80
85
|
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -7,11 +7,41 @@ export type BackgroundSource = {
|
|
|
7
7
|
};
|
|
8
8
|
export type BackgroundFilter = 'blur' | 'image';
|
|
9
9
|
export type BackgroundBlurLevel = 'low' | 'medium' | 'high' | number;
|
|
10
|
+
/**
|
|
11
|
+
* Options for controlling the segmentation mask smoothing.
|
|
12
|
+
* These values are passed to the WebGL shader that blends
|
|
13
|
+
* consecutive segmentation masks over time.
|
|
14
|
+
*/
|
|
15
|
+
export interface SegmentationOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Controls how fast the mask adapts to new segmentation results.
|
|
18
|
+
* Higher values make the mask react faster but may cause flickering.
|
|
19
|
+
* Lower values produce smoother transitions but increase latency.
|
|
20
|
+
* Value should be between 0 and 1.
|
|
21
|
+
* @default 0.8
|
|
22
|
+
*/
|
|
23
|
+
smoothingFactor?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Lower edge of the smoothstep function applied to the confidence mask.
|
|
26
|
+
* Confidence values below this are mapped to 0 (background).
|
|
27
|
+
* Value should be between 0 and 1, and less than smoothstepMax.
|
|
28
|
+
* @default 0.6
|
|
29
|
+
*/
|
|
30
|
+
smoothstepMin?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Upper edge of the smoothstep function applied to the confidence mask.
|
|
33
|
+
* Confidence values above this are mapped to 1 (foreground).
|
|
34
|
+
* Value should be between 0 and 1, and greater than smoothstepMin.
|
|
35
|
+
* @default 0.9
|
|
36
|
+
*/
|
|
37
|
+
smoothstepMax?: number;
|
|
38
|
+
}
|
|
10
39
|
export interface SegmenterOptions {
|
|
11
40
|
backgroundSource?: BackgroundSource | null;
|
|
12
41
|
bgBlur: number;
|
|
13
42
|
bgBlurRadius: number;
|
|
14
43
|
isSelfieMode: boolean;
|
|
44
|
+
segmentationOptions?: SegmentationOptions;
|
|
15
45
|
}
|
|
16
46
|
/**
|
|
17
47
|
* Static configuration for the processor, defining which background
|
|
@@ -23,6 +53,7 @@ export interface BackgroundOptions {
|
|
|
23
53
|
backgroundFilter?: BackgroundFilter;
|
|
24
54
|
backgroundBlurLevel?: BackgroundBlurLevel;
|
|
25
55
|
backgroundImage?: string | undefined;
|
|
56
|
+
segmentationOptions?: SegmentationOptions;
|
|
26
57
|
}
|
|
27
58
|
/**
|
|
28
59
|
* Performance statistics for video processing.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/video-filters-web",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"main": "./dist/index.cjs.js",
|
|
5
5
|
"module": "./dist/index.es.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"CHANGELOG.md"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mediapipe/tasks-vision": "^0.10.
|
|
31
|
+
"@mediapipe/tasks-vision": "^0.10.34",
|
|
32
32
|
"@stream-io/worker-timer": "^1.2.5",
|
|
33
33
|
"wasm-feature-detect": "^1.8.0"
|
|
34
34
|
},
|
package/src/VirtualBackground.ts
CHANGED
|
@@ -63,8 +63,9 @@ export class VirtualBackground extends BaseVideoProcessor {
|
|
|
63
63
|
|
|
64
64
|
this.isSegmenterReady = true;
|
|
65
65
|
} catch (error) {
|
|
66
|
-
console.error('[virtual-background] Segmenter init failed:', error);
|
|
67
66
|
this.isSegmenterReady = false;
|
|
67
|
+
this.hooks.onError?.(error);
|
|
68
|
+
throw error;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
@@ -124,6 +125,7 @@ export class VirtualBackground extends BaseVideoProcessor {
|
|
|
124
125
|
bgBlur: 0,
|
|
125
126
|
bgBlurRadius: 0,
|
|
126
127
|
isSelfieMode,
|
|
128
|
+
segmentationOptions: this.options.segmentationOptions,
|
|
127
129
|
};
|
|
128
130
|
}
|
|
129
131
|
|
|
@@ -138,13 +140,18 @@ export class VirtualBackground extends BaseVideoProcessor {
|
|
|
138
140
|
bgBlur: Math.min(strength * 1.5, 20),
|
|
139
141
|
bgBlurRadius: Math.min(strength, 10),
|
|
140
142
|
isSelfieMode,
|
|
143
|
+
segmentationOptions: this.options.segmentationOptions,
|
|
141
144
|
};
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
private async loadBackground(url?: string) {
|
|
145
148
|
if (!url) return null;
|
|
146
|
-
const result = await fetch(url);
|
|
147
|
-
if (!result.ok)
|
|
149
|
+
const result = await fetch(url, { signal: this.abortController.signal });
|
|
150
|
+
if (!result.ok) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`[virtual-background] Failed to load background image: ${result.status} ${result.statusText}`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
148
155
|
|
|
149
156
|
return {
|
|
150
157
|
type: 'image',
|
package/src/WebGLRenderer.ts
CHANGED
|
@@ -754,6 +754,11 @@ export class WebGLRenderer {
|
|
|
754
754
|
bgBlur: number;
|
|
755
755
|
bgBlurRadius: number;
|
|
756
756
|
isSelfieMode: boolean;
|
|
757
|
+
segmentationOptions?: {
|
|
758
|
+
smoothingFactor?: number;
|
|
759
|
+
smoothstepMin?: number;
|
|
760
|
+
smoothstepMax?: number;
|
|
761
|
+
};
|
|
757
762
|
},
|
|
758
763
|
categoryTexture?: WebGLTexture,
|
|
759
764
|
confidenceTexture?: WebGLTexture,
|
|
@@ -864,9 +869,18 @@ export class WebGLRenderer {
|
|
|
864
869
|
gl.bindTexture(gl.TEXTURE_2D, prevStateTexture);
|
|
865
870
|
gl.uniform1i(stateUpdateLocations.prevStateTexture, 2);
|
|
866
871
|
|
|
867
|
-
gl.uniform1f(
|
|
868
|
-
|
|
869
|
-
|
|
872
|
+
gl.uniform1f(
|
|
873
|
+
stateUpdateLocations.smoothingFactor,
|
|
874
|
+
options.segmentationOptions?.smoothingFactor ?? 0.8,
|
|
875
|
+
);
|
|
876
|
+
gl.uniform1f(
|
|
877
|
+
stateUpdateLocations.smoothstepMin,
|
|
878
|
+
options.segmentationOptions?.smoothstepMin ?? 0.6,
|
|
879
|
+
);
|
|
880
|
+
gl.uniform1f(
|
|
881
|
+
stateUpdateLocations.smoothstepMax,
|
|
882
|
+
options.segmentationOptions?.smoothstepMax ?? 0.9,
|
|
883
|
+
);
|
|
870
884
|
|
|
871
885
|
gl.uniform1i(
|
|
872
886
|
stateUpdateLocations.selfieModel,
|
package/src/types.ts
CHANGED
|
@@ -8,11 +8,44 @@ export type BackgroundSource = {
|
|
|
8
8
|
export type BackgroundFilter = 'blur' | 'image';
|
|
9
9
|
export type BackgroundBlurLevel = 'low' | 'medium' | 'high' | number;
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Options for controlling the segmentation mask smoothing.
|
|
13
|
+
* These values are passed to the WebGL shader that blends
|
|
14
|
+
* consecutive segmentation masks over time.
|
|
15
|
+
*/
|
|
16
|
+
export interface SegmentationOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Controls how fast the mask adapts to new segmentation results.
|
|
19
|
+
* Higher values make the mask react faster but may cause flickering.
|
|
20
|
+
* Lower values produce smoother transitions but increase latency.
|
|
21
|
+
* Value should be between 0 and 1.
|
|
22
|
+
* @default 0.8
|
|
23
|
+
*/
|
|
24
|
+
smoothingFactor?: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Lower edge of the smoothstep function applied to the confidence mask.
|
|
28
|
+
* Confidence values below this are mapped to 0 (background).
|
|
29
|
+
* Value should be between 0 and 1, and less than smoothstepMax.
|
|
30
|
+
* @default 0.6
|
|
31
|
+
*/
|
|
32
|
+
smoothstepMin?: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Upper edge of the smoothstep function applied to the confidence mask.
|
|
36
|
+
* Confidence values above this are mapped to 1 (foreground).
|
|
37
|
+
* Value should be between 0 and 1, and greater than smoothstepMin.
|
|
38
|
+
* @default 0.9
|
|
39
|
+
*/
|
|
40
|
+
smoothstepMax?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
11
43
|
export interface SegmenterOptions {
|
|
12
44
|
backgroundSource?: BackgroundSource | null;
|
|
13
45
|
bgBlur: number;
|
|
14
46
|
bgBlurRadius: number;
|
|
15
47
|
isSelfieMode: boolean;
|
|
48
|
+
segmentationOptions?: SegmentationOptions;
|
|
16
49
|
}
|
|
17
50
|
/**
|
|
18
51
|
* Static configuration for the processor, defining which background
|
|
@@ -24,6 +57,7 @@ export interface BackgroundOptions {
|
|
|
24
57
|
backgroundFilter?: BackgroundFilter;
|
|
25
58
|
backgroundBlurLevel?: BackgroundBlurLevel;
|
|
26
59
|
backgroundImage?: string | undefined;
|
|
60
|
+
segmentationOptions?: SegmentationOptions;
|
|
27
61
|
}
|
|
28
62
|
|
|
29
63
|
/**
|