I'm trying to create a Sprite using PixiJS v4 (or v5?) but feeding a texture from a Webcam (a MediaStream) into it. It doesn't seem to be possible.
An old 2017 thread has a link to an example that should work. Unfortunately 1) this example doesn't work anymore, likely because of HTML change since then and 2) even if it worked, the solution also seems pretty convoluted (copying frame by frame?) so I'd like to avoid something like that if possible.
On my case, I've tried creating a <Video> element and setting a source from that...
const stream; // This is a MediaStream that comes from navigator.mediaDevices.getUserMedia()
const video = document.createElement("video");
video.autoplay = true;
video.srcObject = stream;
document.documentElement.appendChild(video);
This works well, since we can set the srcObject (not the src) of a <Video> to a stream and it works magically.
But the problem arises when I try adding that to Pixi. I can do this:
const texture = Texture.fromVideo(video, SCALE_MODES.LINEAR, true, false);
const sprite = new Sprite(texture);
Which is, I pass the <Video> instance (since I don't have a url) to the texture. But it doesn't work; Pixi itself is kinda silent, but them I get an initial Chrome render error:
[.WebGL-0000017A07139680]GL ERROR :GL_INVALID_OPERATION : glGenerateMipmap: Can not generate mips
And additional errors on every frame:
[.WebGL-0000017A07139680]RENDER WARNING: texture bound to texture unit 8 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering.
Despite what the error says, I don't think it has anything to do with the bounds of the texture. Even if I grab a 256x256 texture from the camera, it stops working.
For comparison, if I just set the <Video> src to a normal file...
const video = document.createElement("video");
video.src = "myvideo.mp4";
document.documentElement.appendChild(video);
...then the above code works fine and I'm able to create a Texture from a <Video> tag.
I've tried a different approach, creating a video URL out of a media stream (which, technically, should work):
const stream; // This is a MediaStream that comes from navigator.mediaDevices.getUserMedia()
const videoURL = URL.createObjectURL(stream);
const texture = Texture.fromVideo(videoURL, SCALE_MODES.LINEAR, true, false);
const sprite = new Sprite(texture);
this.addChild(sprite);
But I get a nasty error on the "URL.createObjectURL" line:
Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
So, anyway.
Does anyone know of a way to create a texture from a webcam input in PixiJS?