mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 05:49:22 +00:00
Improve script
This commit is contained in:
parent
cc3bdd1b0a
commit
7df6e5b3bf
@ -924,19 +924,18 @@ class CallWindow extends CustomEvents {
|
|||||||
if(!this.isOpen)
|
if(!this.isOpen)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
// If streaming video stream, allow to blur background
|
||||||
if(includeVideo)
|
if(includeVideo)
|
||||||
{
|
{
|
||||||
// Create capture
|
// Create capture
|
||||||
const videoTarget = document.createElement("video");
|
const videoTarget = document.createElement("video");
|
||||||
|
videoTarget.muted = true;
|
||||||
videoTarget.srcObject = stream;
|
videoTarget.srcObject = stream;
|
||||||
videoTarget.play()
|
videoTarget.play()
|
||||||
|
|
||||||
|
|
||||||
const canvasTarget = document.createElement("canvas");
|
const canvasTarget = document.createElement("canvas");
|
||||||
const canvas = canvasTarget.getContext("2d");
|
const canvas = canvasTarget.getContext("2d");
|
||||||
|
|
||||||
document.body.appendChild(videoTarget) // TODO : remove
|
|
||||||
document.body.appendChild(canvasTarget) // TODO : remove
|
|
||||||
bodyPix.load({
|
bodyPix.load({
|
||||||
multiplier: 0.75,
|
multiplier: 0.75,
|
||||||
stride: 32,
|
stride: 32,
|
||||||
@ -945,28 +944,29 @@ document.body.appendChild(canvasTarget) // TODO : remove
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//await new Promise((res) => setTimeout(() => res(), 3000));
|
// Wait for video to be ready
|
||||||
|
|
||||||
await new Promise((res, rej) => videoTarget.addEventListener("loadeddata", e => res(), {once: true}));
|
await new Promise((res, rej) => videoTarget.addEventListener("loadeddata", e => res(), {once: true}));
|
||||||
alert("do it");
|
|
||||||
videoTarget.width = this.mainStream.getVideoTracks()[0].getSettings().width
|
const videoTrack = this.mainStream.getVideoTracks()[0];
|
||||||
videoTarget.height = this.mainStream.getVideoTracks()[0].getSettings().height
|
|
||||||
|
// Fix size
|
||||||
|
videoTarget.width = videoTrack.getSettings().width
|
||||||
|
videoTarget.height = videoTrack.getSettings().height
|
||||||
canvasTarget.width = videoTarget.width;
|
canvasTarget.width = videoTarget.width;
|
||||||
canvasTarget.height = videoTarget.height;
|
canvasTarget.height = videoTarget.height;
|
||||||
|
|
||||||
while(true) // TODO : Find something better
|
while(videoTrack.readyState == "live")
|
||||||
{
|
{
|
||||||
const segmentation = await net.segmentPerson(videoTarget);
|
const segmentation = await net.segmentPerson(videoTarget);
|
||||||
|
|
||||||
const backgroundBlurAmount = 6;
|
const backgroundBlurAmount = 6;
|
||||||
const edgeBlurAmount = 2;
|
const edgeBlurAmount = 2;
|
||||||
const flipHorizontal = true;
|
const flipHorizontal = true;
|
||||||
console.info(
|
|
||||||
canvasTarget, videoTarget, segmentation, backgroundBlurAmount,
|
|
||||||
edgeBlurAmount, flipHorizontal);
|
|
||||||
bodyPix.drawBokehEffect(
|
bodyPix.drawBokehEffect(
|
||||||
canvasTarget, videoTarget, segmentation, backgroundBlurAmount,
|
canvasTarget, videoTarget, segmentation, backgroundBlurAmount,
|
||||||
edgeBlurAmount, flipHorizontal);
|
edgeBlurAmount, flipHorizontal);
|
||||||
|
console.log("track update");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user