@stream-io/video-filters-web 0.1.2 → 0.1.3
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 +7 -0
- package/dist/index.cjs.js +12 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +12 -5
- package/dist/index.es.js.map +1 -1
- package/dist/src/createRenderer.d.ts +1 -1
- package/dist/src/tflite.d.ts +0 -1
- package/package.json +3 -3
- package/src/createRenderer.ts +8 -3
- package/src/webgl2/webgl2Pipeline.ts +1 -0
package/dist/index.es.js
CHANGED
|
@@ -673,6 +673,8 @@ function buildWebGL2Pipeline(videoSource, backgroundImage, blurLevel, background
|
|
|
673
673
|
const gl = canvas.getContext('webgl2');
|
|
674
674
|
if (!gl)
|
|
675
675
|
throw new Error('WebGL2 is not supported');
|
|
676
|
+
if (gl.isContextLost())
|
|
677
|
+
throw new Error('WebGL2 context was lost');
|
|
676
678
|
const { width: frameWidth, height: frameHeight } = videoSource;
|
|
677
679
|
const { width: segmentationWidth, height: segmentationHeight } = segmentationConfig;
|
|
678
680
|
const vertexShaderSource = glsl `#version 300 es
|
|
@@ -775,16 +777,21 @@ const getSegmentationParams = (level) => {
|
|
|
775
777
|
return { width: 160, height: 96 };
|
|
776
778
|
};
|
|
777
779
|
|
|
778
|
-
function createRenderer(tflite, videoSource, targetCanvas, options) {
|
|
780
|
+
function createRenderer(tflite, videoSource, targetCanvas, options, onError) {
|
|
779
781
|
const { backgroundFilter, backgroundImage, backgroundBlurLevel, segmentationLevel = SegmentationLevel.HIGH, fps = 30, } = options;
|
|
780
782
|
if (backgroundFilter === 'image' && !backgroundImage) {
|
|
781
783
|
throw new Error(`backgroundImage element is required when backgroundFilter is image`);
|
|
782
784
|
}
|
|
783
785
|
const pipeline = buildWebGL2Pipeline(videoSource, backgroundImage, backgroundBlurLevel, backgroundFilter, targetCanvas, tflite, getSegmentationParams(segmentationLevel));
|
|
784
786
|
const id = setInterval(() => {
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
787
|
+
try {
|
|
788
|
+
pipeline.render();
|
|
789
|
+
if (backgroundFilter === 'image') {
|
|
790
|
+
pipeline.updatePostProcessingConfig();
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
catch (error) {
|
|
794
|
+
onError?.(error);
|
|
788
795
|
}
|
|
789
796
|
}, 1000 / (fps <= 0 ? 30 : fps));
|
|
790
797
|
return {
|
|
@@ -1529,7 +1536,7 @@ const createTFLiteSIMDModule = (__Module) => {
|
|
|
1529
1536
|
return __Module.ready;
|
|
1530
1537
|
};
|
|
1531
1538
|
|
|
1532
|
-
const version = "0.1.
|
|
1539
|
+
const version = "0.1.3" ;
|
|
1533
1540
|
const packageName = "@stream-io/video-filters-web" ;
|
|
1534
1541
|
|
|
1535
1542
|
// @ts-expect-error - module is not declared
|