Jump to content

Use pixi js to merge two camera streams on the canvas and extract the media stream.


Azir
 Share

Recommended Posts

I want to use pixi js to help me synthesize the webcam stream

I successfully merg two video stream into one canvas

But I cannot get mediastream using canvas.captureStream()

look this image

picture.thumb.png.78627f4e7d32b32f5f903405f5d0ad01.png

sample code

const canvas = document.getElementById('mycanvas')

const app = new PIXI.Application({
  view: canvas,
});

canvas.width = 1920;
canvas.height = 1080;

var texture = null;

var captureMixerStream = () => {

  // canvas mixer stream
  let mediaStream3 = canvas.captureStream();
  video2.srcObject = mediaStream3;
  video2.onloadedmetadata = () => {
    video2.play();
    // error broken screen
  };

}

var initvideo2 = () => {
  // mediaStream from getusermedia webcam stream
  video2.srcObject = mediastream;
  video2.onloadedmetadata = () => {
    video2.play();
  };
  video2.oncanplay = function () {
    let sprite = new PIXI.Sprite(texture);
    sprite.position.set(640, 360);
    sprite.width = 640;
    sprite.height = 360;
    app.stage.addChild(sprite)
    captureMixerStream();
  }
}

var initvideo1 = () => {
  // mediaStream from getusermedia webcam stream
  video1.srcObject = mediastream;
  video1.onloadedmetadata = () => {
    video1.play();
  };
  video1.oncanplay = function () {
    texture = PIXI.Texture.from(video1);
    let sprite = new PIXI.Sprite(texture);
    sprite.position.set(0, 0);
    sprite.width = 1920;
    sprite.height = 1080;
    app.stage.addChild(sprite);
    initvideo2();
  }
}

initvideo1();

 

 

Edited by Azir
Pixi.js
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...