I have a MediaStreamTrack that's streaming a video from the user's camera onto a <video>
tag in Google Meets.
Running as a chrome extension, I'd like to replace it with a track that's just a static image.
I've tried to change the enabled
flag as specified in other questions ( which turns it black instead of freezing the image ), calling stop() which kills it, or using ImageCapture.TakePhoto(...) to generate an image, put it in a canvas, and capture the canvas source - this failed because the canvas stream didn't match the original one, resulting in a black image. I tried to override other properties using Object.defineProperty()
to replace the track with another after calling removeTrack()
, didnt work either.
Question:
How would you go about "freezing" mediaStreamTrack so it contains, gets sent and recorded as just a static image?
(editor's note:
This part is from a comment on a (now deleted) Answer. It clarifies the Askers expected results)
Can you show me an example of how you'd get the source for the canvas from that (webcam) video before changing the stream for the output video into that canvas stream?
Here's the code that I used:
var vid = getVideoElementFromPage();
var Stream = vid.captureStream();
var Track = Stream.getVideoTracks()[0];
var URLIdea = undefined;
new ImageCapture(Track).takePhoto().then((imCpt) => {
URLIdea = URL.createObjectURL(imCpt);
// Here, I've tried setting this URL to a canvas, capturing stream and changing the track,
// or changing the video src to the URL directly.
// in both cases - black screen
});