@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
|
@@ -29,7 +29,7 @@ export declare abstract class BaseVideoProcessor {
|
|
|
29
29
|
protected constructor(track: MediaStreamVideoTrack, hooks?: VideoTrackProcessorHooks);
|
|
30
30
|
start(): Promise<MediaStreamTrack>;
|
|
31
31
|
stop(): void;
|
|
32
|
-
|
|
32
|
+
protected updateStats(delay: number): void;
|
|
33
33
|
protected abstract initialize(): Promise<void>;
|
|
34
34
|
protected abstract transform(frame: VideoFrame): Promise<VideoFrame>;
|
|
35
35
|
protected onFlush(): void;
|
|
@@ -14,7 +14,6 @@ export declare class VirtualBackground extends BaseVideoProcessor {
|
|
|
14
14
|
private latestCategoryMask;
|
|
15
15
|
private latestConfidenceMask;
|
|
16
16
|
private lastFrameTime;
|
|
17
|
-
private count;
|
|
18
17
|
constructor(track: MediaStreamVideoTrack, options?: BackgroundOptions, hooks?: VideoTrackProcessorHooks);
|
|
19
18
|
protected initialize(): Promise<void>;
|
|
20
19
|
private initializeSegmenter;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface VideoTrackProcessorHooks {
|
|
|
39
39
|
onError?: (error: unknown) => void;
|
|
40
40
|
onStats?: (stats: PerformanceStats) => void;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Maps blur level to blur strength values.
|
|
44
|
+
*/
|
|
45
|
+
export declare const BACKGROUND_BLUR_MAP: Record<'low' | 'medium' | 'high', number>;
|
package/package.json
CHANGED
|
@@ -64,11 +64,8 @@ export abstract class BaseVideoProcessor {
|
|
|
64
64
|
this.canvas.height = frame.displayHeight;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const start = performance.now();
|
|
68
67
|
const processed = await this.transform(frame);
|
|
69
|
-
const delay = performance.now() - start;
|
|
70
68
|
|
|
71
|
-
this.updateStats(delay);
|
|
72
69
|
controller.enqueue(processed);
|
|
73
70
|
} catch (e) {
|
|
74
71
|
this.hooks.onError?.(e);
|
|
@@ -98,7 +95,7 @@ export abstract class BaseVideoProcessor {
|
|
|
98
95
|
this.onStop();
|
|
99
96
|
}
|
|
100
97
|
|
|
101
|
-
|
|
98
|
+
protected updateStats(delay: number): void {
|
|
102
99
|
this.frames++;
|
|
103
100
|
this.delayTotal += delay;
|
|
104
101
|
|
package/src/VirtualBackground.ts
CHANGED
|
@@ -24,7 +24,6 @@ export class VirtualBackground extends BaseVideoProcessor {
|
|
|
24
24
|
private latestCategoryMask: WebGLTexture | undefined = undefined;
|
|
25
25
|
private latestConfidenceMask: WebGLTexture | undefined = undefined;
|
|
26
26
|
private lastFrameTime = -1;
|
|
27
|
-
private count = 0;
|
|
28
27
|
|
|
29
28
|
constructor(
|
|
30
29
|
track: MediaStreamVideoTrack,
|
|
@@ -71,10 +70,12 @@ export class VirtualBackground extends BaseVideoProcessor {
|
|
|
71
70
|
|
|
72
71
|
protected async transform(frame: VideoFrame): Promise<VideoFrame> {
|
|
73
72
|
const currentTime = frame.timestamp;
|
|
74
|
-
const hasNewFrame = currentTime
|
|
73
|
+
const hasNewFrame = currentTime - this.lastFrameTime > 1_000;
|
|
75
74
|
this.lastFrameTime = currentTime;
|
|
76
75
|
|
|
77
76
|
if (hasNewFrame && this.isSegmenterReady && this.segmenter) {
|
|
77
|
+
const start = performance.now();
|
|
78
|
+
|
|
78
79
|
await this.runSegmentation(frame);
|
|
79
80
|
|
|
80
81
|
this.webGlRenderer.render(
|
|
@@ -83,6 +84,8 @@ export class VirtualBackground extends BaseVideoProcessor {
|
|
|
83
84
|
this.latestCategoryMask,
|
|
84
85
|
this.latestConfidenceMask,
|
|
85
86
|
);
|
|
87
|
+
|
|
88
|
+
this.updateStats(performance.now() - start);
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
return new VideoFrame(this.canvas, { timestamp: frame.timestamp });
|
|
@@ -125,20 +128,15 @@ export class VirtualBackground extends BaseVideoProcessor {
|
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
const blurLevel = this.options.backgroundBlurLevel;
|
|
131
|
+
const strength =
|
|
132
|
+
typeof blurLevel === 'string'
|
|
133
|
+
? BACKGROUND_BLUR_MAP[blurLevel]
|
|
134
|
+
: Math.round(blurLevel ?? 5);
|
|
128
135
|
|
|
129
|
-
if (typeof blurLevel === 'string') {
|
|
130
|
-
return {
|
|
131
|
-
...BACKGROUND_BLUR_MAP[blurLevel],
|
|
132
|
-
backgroundSource: undefined,
|
|
133
|
-
isSelfieMode,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const numeric = blurLevel ?? 5;
|
|
138
136
|
return {
|
|
139
137
|
backgroundSource: undefined,
|
|
140
|
-
bgBlur: Math.min(
|
|
141
|
-
bgBlurRadius: Math.min(
|
|
138
|
+
bgBlur: Math.min(strength * 1.5, 20),
|
|
139
|
+
bgBlurRadius: Math.min(strength, 10),
|
|
142
140
|
isSelfieMode,
|
|
143
141
|
};
|
|
144
142
|
}
|
package/src/types.ts
CHANGED
|
@@ -43,20 +43,11 @@ export interface VideoTrackProcessorHooks {
|
|
|
43
43
|
onStats?: (stats: PerformanceStats) => void;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
> = {
|
|
50
|
-
low:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
medium: {
|
|
55
|
-
bgBlur: 15,
|
|
56
|
-
bgBlurRadius: 4,
|
|
57
|
-
},
|
|
58
|
-
high: {
|
|
59
|
-
bgBlur: 30,
|
|
60
|
-
bgBlurRadius: 5,
|
|
61
|
-
},
|
|
46
|
+
/**
|
|
47
|
+
* Maps blur level to blur strength values.
|
|
48
|
+
*/
|
|
49
|
+
export const BACKGROUND_BLUR_MAP: Record<'low' | 'medium' | 'high', number> = {
|
|
50
|
+
low: 3,
|
|
51
|
+
medium: 5,
|
|
52
|
+
high: 7,
|
|
62
53
|
};
|