MultiStreamsMixer | Mix Multiple Cameras &
Screens into Single Stream

HOME © Muaz Khan . @WebRTCWeb . Github . Latest issues . What's New?

Pass multiple streams (e.g. screen+camera or multiple-cameras) and get single stream.

Requires THIS CHROME EXTENSION and following Chrome flag:
chrome://flags/#enable-experimental-web-platform-features

How to use MultiStreamsMixer?

// https://cdn.webrtc-experiment.com/MultiStreamsMixer.js
screenStream.fullcanvas = true;
screenStream.width = screen.width; // or 3840
screenStream.height = screen.height; // or 2160 

cameraStream.width = parseInt((20 / 100) * screenStream.width);
cameraStream.height = parseInt((20 / 100) * screenStream.height);
cameraStream.top = screenStream.height - cameraStream.height;
cameraStream.left = screenStream.width - cameraStream.width;

var mixer = new MultiStreamsMixer([screenStream, cameraStream]);

mixer.mixedStream.getTracks().forEach(function(track) {
    rtcPeerConnection.addTrack(track, mixer.mixedStream)
});

mixer.setOptions({
    frameInterval: 1
});

mixer.startDrawingFrames();

btnStopStreams.onclick = function() {
    mixer.releaseStreams();
};

btnAppendNewStreams.onclick = function() {
    mixer.appendStreams([anotherStream]);
};

btnStopScreenSharing.onclick = function() {
    // replace all old streams with this one
    // it will replace only video tracks
    mixer.replaceStreams([cameraStreamOnly]);
};

Issues

Latest Updates