Skip to content

Instantly share code, notes, and snippets.

@MagnusThor
Last active May 26, 2021 19:09
Show Gist options
  • Save MagnusThor/715496c2a1c8baf9aaab5a871f5d2a30 to your computer and use it in GitHub Desktop.
Save MagnusThor/715496c2a1c8baf9aaab5a871f5d2a30 to your computer and use it in GitHub Desktop.
Snapshot , dump of virtual-bg example broski dosiki, kushki khleb
import { GreenScreenStream, GreenScreenMethod } from "../../src/GreenScreenStream";
document.addEventListener("DOMContentLoaded", () => {
const bgfile = location.hash.length > 0 ? location.hash.replace("#", "") : "beach.jpg"
navigator.getUserMedia({ video: { width: 640, height: 360 }, audio: false }, (ms: MediaStream) => {
let instance = GreenScreenStream.getInstance(true, `../assets/${bgfile}`, undefined, 640, 360);
instance.onReady = () => {
const fps = 60;
instance.initialize().then(result => {
instance.start(GreenScreenMethod.VirtualBackground);
const ms = instance.captureStream(fps); // capture result as a MediaSteam and attacj to video element
document.querySelector("video").srcObject = ms;
}).catch(err => {
console.log(err);
});
}
instance.addVideoTrack(ms.getVideoTracks()[0]);
window["_instance"] = instance; // expose for debuging purposes
}, (e) => console.error(e));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment