Giter Club home page Giter Club logo

video-stream-merger's Introduction

video-stream-merger

JavaScript Style Guide

Merges the video of multiple MediaStreams. Also merges the audio via the WebAudio API.

  • Send multiple videos over a single WebRTC MediaConnection.
  • Hotswap streams without worrying about renegotation or delays.
  • Crop, scale, and rotate live video.
  • Add creative effects through the canvas API.

Demo

P2P Demo

Existing Files Demo

install

npm install video-stream-merger

or

<script src="dist/video-stream-merger.js"></script>

usage

Let's first get two media streams. One from the webcam, and another a screen capture.

const getusermedia = require('getusermedia')
const screenRecord = require('screen-record')

getusermedia({video: true, audio:true}, (err, webcamStream) => {
  screenRecord(window, (err, sourceId, constraints) => {
    getusermedia(constraints, (err, screenStream) => {
      // We now have 2 streams: webcamStream, screenStream
    })
  })
})

We want to overlay the webcam stream in the corner of the screen stream.

var VideoStreamMerger = require('video-stream-merger')

var merger = new VideoStreamMerger()

// Add the screen capture. Position it to fill the whole stream (the default)
merger.addStream(screenStream, {
  x: 0, // position of the topleft corner
  y: 0,
  width: merger.width,
  height: merger.height,
  mute: true // we don't want sound from the screen (if there is any)
})

// Add the webcam stream. Position it on the bottom left and resize it to 100x100.
merger.addStream(webcamStream, {
  x: 0,
  y: merger.height - 100,
  width: 100,
  height: 100,
  mute: false
})

// Start the merging. Calling this makes the result available to us
merger.start()

// We now have a merged MediaStream!
merger.result

API

merger = new VideoStreamMerger([opts])

Create a new video merger.

Optional opts defaults to the below:

{
  width: 400,   // Width of the output video
  height: 300,  // Height of the output video
  fps: 25,       // Video capture frames per second
  clearRect: true, // Clear the canvas every frame
  audioContext: null, // Supply an external AudioContext (for audio effects)
}

merger.addStream(mediaStream|id, [opts])

Add a MediaStream to be merged. Use an id string if you only want to provide an effect.

The order that streams are added matters. Streams placed earlier will be behind later streams (use the index option to change this behaviour.)

Optional opts defaults to the below:

{
  x: 0, // position of the top-left corner
  y: 0,
  width: <width of output>,     // size to draw the stream
  height: <height of output>,
  index: 0, // Layer on which to draw the stream (0 is bottom, 1 is above that, and so on)
  mute: false,  // if true, any audio tracks will not be merged
  draw: null,    // A custom drawing function (see below)
  audioEffect: null // A custom WebAudio effect (see below)
}

merger.removeStream(mediaStream|id)

Remove a MediaStream from the merging. You may also use the ID of the stream.

If you have added the same MediaStream multiple times, all instances will be removed.

merger.addMediaElement(id, mediaElement, opts)

A convenience function to merge a HTML5 MediaElement instead of a MediaStream.

id is a string used to remove or update the index of the stream later.

mediaElement is a playing HTML5 Audio or Video element.

opts are identical to the opts for addStream.

Streams from MediaElements can be removed via merger.removeStream(id).

merger.updateIndex(mediaStream|id, newIndex)

Update the z-index (draw order) of an already added stream or data object. Identical to the index option.

If you have added the same MediaStream multiple times, all instances will be updated.

merger.setOutputSize(width, height)

Change the size of the canvas and the output video track.

Automatically updates merger.width and merger.height.

merger.start()

Start the merging and create merger.result.

You can call this any time, but you only need to call it once.

You will still be able to add/remove streams and the result stream will automatically update.

merger.result

The resulting merged MediaStream. Only available after calling merger.start()

Never has more than one Audio and one Video track.

merger.destroy()

Clean up everything and destroy the result stream.

merger.getAudioContext()

Get the WebAudio AudioContext being used by the merger.

merger.getAudioDestination()

Get the MediaStreamDestination node that is used by the merger.

Hot-Swapping Streams (P2P Streaming)

This library makes it easy to change streams in a WebRTC connection without needing to renegotiate.

The result MediaStream will appear to be constant and stable, no matter what streams you add/remove!

P2P Streaming Demo

getusermedia({video: true, audio:true}, (err, webcamStream) => {
  const merger = new VideoStreamMerger()
  merger.start()
  players[0].srcObject = merger.result
  players[0].play()
  
  const peer1 = new SimplePeer({initiator: true, stream:merger.result})
  const peer2 = new SimplePeer()

  peer1.on('signal', (data) => {
    peer2.signal(data)
  })
  peer2.on('signal', (data) => {
    peer1.signal(data)
  })

  peer2.on('stream', (stream) => {
    players[1].srcObject = stream
  })
  
  const clones = []
  
  shareWebCamStream.addEventListener('click', () => {
      clones.push(webcamStream.clone())
      merger.addStream(clones[clones.length-1])
  })
  removeWebCamStream.addEventListener('click', () => {
      merger.removeStream(clones.pop())
  })
})

Custom Draw Function

If sizing and positioning aren't enough, you can directly draw the video frames by passing a function to the draw option.

merger.addStream(mediaStream, {
  draw: (ctx, frame, done) => {
    // You can do whatever you want with this canvas context
    ctx.drawImage(frame, 0, 0, merger.width, merger.height)
    done()
  })
})

See the bottom example of the Live Demo to see this in action.

Custom WebAudio Effects

You can also take direct control over how audio streams are merged, and apply effects.

merger.addStream(mediaStream, {
  audioEffect: (sourceNode, destinationNode) => {
    // sourceNode is the input streams audio (microphone, etc)
    // destinationNode is the output streams audio
    
    sourceNode.connect(destinationNode) // The default effect, simply merges audio
  })
})

Both the draw and audioEffect options can be used without any MediaStream at all. Just pass a string instead.

Sponsors

Support this project by becoming a sponsor. Your logo will appear here with a link to your website. [Become a sponsor]

video-stream-merger's People

Contributors

changeweb avatar hthetiot avatar jorisgu avatar luanraithz avatar nadavami avatar paul-em avatar rationalcoding avatar t-mullen avatar timebutt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

video-stream-merger's Issues

black video in chrome v67

Hi,
It was working fine while using chrome v66, After updating chrome v67 then it is showing black video.
I have checked this issue in Ubutu 14.04 LTS (64 bit) and windows 10 (64 bit).
image

Empty video in Firefox

The merged recorded video works well in Chrome but empty recorded video in Firefox. If I use just non-merged video, the recorded video displayed. Helps?

                       recordedBlobs = [];
			
			var merger = new VideoStreamMerger()

			// Add the screen capture. Position it to fill the whole stream (the default)
			merger.addStream(peerStream, {
			  x: 0, // position of the topleft corner
			  y: 0,
			  width: merger.width,
			  height: merger.height,
			  mute: false, // we don't want sound from the screen (if there is any)
			  index: 0
			})

			// Add the webcam stream. Position it on the bottom left and resize it to 100x100.
			merger.addStream(lclStream, {
			  x: merger.width - 100,
			  y: 0,
			  width: 100,
			  height: 100,
			  mute: false,
			  index: null
			})

			// Start the merging. Calling this makes the result available to us
			merger.start()
			combinedStream = merger.result;
			  var options = {mimeType: 'video/webm;codecs=vp9'};
			  if (!MediaRecorder.isTypeSupported(options.mimeType)) {
				console.log(options.mimeType + ' is not Supported');
				options = {mimeType: 'video/webm;codecs=vp8'};
				if (!MediaRecorder.isTypeSupported(options.mimeType)) {
				  console.log(options.mimeType + ' is not Supported');
				  options = {mimeType: 'video/webm'};
				  if (!MediaRecorder.isTypeSupported(options.mimeType)) {
					console.log(options.mimeType + ' is not Supported');
					options = {mimeType: ''};
				  }
				}
			  }
			  try {
				mediaRecorder = new MediaRecorder(combinedStream, options);
				theRecorder = mediaRecorder;
			  } catch (e) {
				console.error('Exception while creating MediaRecorder: ' + e);
				console.log('Exception while creating MediaRecorder: '
				  + e + '. mimeType: ' + options.mimeType);
				return;
			  }
			  console.log('Created MediaRecorder', mediaRecorder, 'with options', options);
			  recordButton.innerHTML = '<i class="fa fa-square round"></i><div style="display:none">Stop Recording</div>';
			  mediaRecorder.onstop = handleStop;
			  mediaRecorder.ondataavailable = handleDataAvailable;
			  mediaRecorder.start(10); // collect 10ms of data
			  console.log('MediaRecorder started', mediaRecorder);

Allow any data in "addStream"

It would be useful to pass any object instead of a MediaStream and use the draw option to render it to canvas. This might be images, graphs, anything.

From #5

Audio handle question

Hi @rationalcoding,

awesome work with video-stream-merger, but i have one question.

I merged some stream (video & audio) with your video-stream-merger, making one unique stream to send by webrtc, but i need to mute and unmute selective of that source stream. I see your code and make a new function for that:

VideoStreamMerger.prototype.muteStream = function (mediaStream, estado) {
var self = this

if (typeof mediaStream === 'string') {
mediaStream = {
id: mediaStream
}
}

for (var i = 0; i < self._streams.length; i++) {
if (mediaStream.id === self._streams[i].id) {
if (self._streams[i].audioOutput) {
self._streams[i].audioOutput.gain.value = estado ? 0 : 1;
}

  break;
}

}
}

If "estado" is true, set gain.value to 0, otherwise 1. Is this function the correct path?, because i still hear the audio in the other peer. If this function is not correct, how can i handle de audio for the source streams, once has been merged?

Regards

Stream Stops if you focus out of the tab

Scenario:

Peer1 - Combines and Share Streams
Peer2 - Received Stream
Peer1 - Looses focus on tab, by navigating to another tab or opening another program
Peer2 - Received Stream stops
Peer1 - Focuses to chrome tab that did the sharing
Peer2 - Resumes receiving the stream

Issue: Normally, this doesn't happen with WebRtc and Streams, is the issue that the merger is stopped? Is there some way we can continue making the merger work while in the background?

Video currentTime not working

Hi Thomas,

The ability to manipulate html5 video property for currentTime when media is played with the merger

1# The time increments despite video looped.
2# I am unable to set the currentTime of the video.

I would need to be able to manipulate the currentTime of the media that is played with the merger such as getting the correct currentTime and setting to specific time of the video

removeStream() and addStream() throw error since version 3.3.2

Thank you for the 3.3.2 update. I wanted to try it out but since the update i get the following error when calling removeStream() and addStream():

client.js?06a0:77 Error: "i" is read-only
    at _readOnlyError (video-stream-merger.js?a366:formatted:56)

My assumption is that it might have something to do with the variable decelerations you changed from var to let in the for-loops.

Audio sometimes delayed behind video

This intermittently happens if you add a stream too soon after creating a VideoStreamMerger object.

This is due to a bug (?) in Chrome that causes the audio context to buffer slightly before playback.

A workaround is to wait ~6 seconds (this is always more than enough time) before adding streams.

var merger = new VideoStreamMerger()

setTimeout(function () {
  merger.addStream(stream)
  merger.start()
}, 6000)

Notice how WBS has a slight wait time.

Capture from Merger canvas appears blank when using getDisplayMedia

Hi,

First off, thanks for the package!

I'm encountering a somewhat odd bug. I'm using video-stream-merger to let my customers narrate over top of a screen share. I was having problems where the audio and video would get out of sync, but this fixed it ๐Ÿ˜ƒ

However, I am encountering an odd potential bug. If you use getDisplayMedia and the user selects a non-frontmost Chrome tab, the output from video-stream-merger appears to be a black square (even though the MediaStream itself has data).

It doesn't look like an issue with the captureStream because I can use a custom draw() function to draw a red circle (or anything) and that sticks around.

Here's a jsfiddle with a minimal reproduction of the bug.

I have been trying everything here (order of creating the merger etc. etc) with no luck. Any help at this point is much appreciated! Hopefully this is a case of me doing something silly. Happy to work on a patch/fix too if anyone can point me in the right direction.

Cheers,

Nik

How to get a desktop stream?

Moved from email:

I came across your video stream merger project on GitHub while doing research for one of my classes. I am trying to use your code to merge a webcam stream and a desktop screen stream in order to make a single WebRTC connection. I see that in your read me it says this is possible. Can you help point me in the right direction to get this working? I appreciate any help or advice that you are willing to offer. Thank you.

Use the video stream merger in node.js

Hi,
This is not really an issue. I just didn't know how to contact you.
First thank you for your hard work on the video stream merger.
I am using the video stream merger to merge multiple recorded videos with different sizes and positions to a single video. Unfortunately, I get performance issues on older devices and ios devices, so I decided to merge the videos in a firebase function (node.js). I have the URLs and coordinates of the recorded videos. Is it possible to create a merged video in node.js? I am struggling to create a Media Stream. Is this possible?
Thank you & best regards

Merging addStream with addMediaElement

Thank you for this really awesome library, works flawlessly!
Recently I decided to merge the webcam stream with some prerecorded video
I would like to place such video at the left bottom corner of the entire frame (similar to Loom)

// my webcam feed acting as a background
merger.addStream(camera, { x: 0, y: 0, width: 1366, height: 768 });
// video I want to place in the corner of webcam feed in the form of a circle
merger.addMediaElement('circle', document.getElementById('video'), {
  draw: (ctx, frame, done) => {
    // video size is 1280x720, I need only a circle in the center of it
    const x = 0, y = 0, width = 1280, height = 720;
    ctx.beginPath();
    ctx.arc(x + width/2, y + height/2, width/2, 0, Math.PI*2, true);
    ctx.closePath();
    ctx.clip();
    ctx.drawImage(frame, x, y, width, height);
    ctx.restore();
    done();
  }
});

This gives me just a large circle in the center of main frame with video overlayed on top of webcam
Looks like this code has clipped the whole merger frame not only the video frame

Similar to this but everything outside a circle is black:
image

Could you please explain what is ctx and frame when I use draw for addMediaElement?
I would be obliged if you could point me into the correct direction for achieving my goal!

Bandwidth

Hi - I'd like to use dist/video-stream-merger โ€“ would you be interested in publishing it to NPM?

audio and video are not synchronous

First of all thank you for this library. Makes working with MediaStreams much easier.

I implemented this in an app but some users reported and showed me that videos that get recorded this way have a delayed video stream. My guess is that this happens due to the usage of the canvas element that gets recorded. If i record the video stream directly without a canvas or this library there is no audio/video delay.

Is anyone experiencing the same or knows how to fix this?

Crossfade between streams

HI!
It would be pretty needfull to get a way to xfade between two streams and to fade in/out a stream.
Is there any way to do this with a custom draw method????

Many thanks for your great work!!!

Audio time not sync with video when add/remove audio stream

I try publishing a stream to Wowza. Dynamically adding/removing audio stream corrupts Wowza endcoder. Wowza wait for audio stream when I remove audio stream from your merger.

Anyway, I fixed by adding the following code. It forces the merger to always has audio stream. Not sure its a good practice, but it works perfectly in all situations.

  // Fixed encoder wrong timing to wowza - pushing empty audio node
  var constantAudioNode = self._audioCtx.createConstantSource()
  constantAudioNode.start()
  constantAudioNode.connect(self._audioDestination)

Full code

VideoStreamMerger.prototype.start = function () {
  var self = this

  self.started = true
  window.requestAnimationFrame(self._draw.bind(self))

  // Fixed encoder wrong timing to wowza - pushing empty audio node
  var constantAudioNode = self._audioCtx.createConstantSource()
  constantAudioNode.start()
  constantAudioNode.connect(self._audioDestination)

  // Add video
  self.result = self._canvas.captureStream(self.fps)

  // Remove "dead" audio track
  var deadTrack = self.result.getAudioTracks()[0]
  if (deadTrack) self.result.removeTrack(deadTrack)

  // Add audio
  var audioTracks = self._audioDestination.stream.getAudioTracks()
  self.result.addTrack(audioTracks[0])
}

Thanks for your good library.

Support iOS Safari

@t-mullen Thanks for your hard work for this library but this library is not working on iOS Safari. We have a scenario where we need to use crop the video from the webcam and it didn't work for us. On further investigation, we found the issue with the patch applied for fixing Audio. After that, we found that the capture stream from canvas isn't working well on iOS Safari though it works fine on other browsers. Please take a look and fix this issue with this library. If you want then we can share the code which worked for us with the limitation that we are using directly canvas to show the video and not passing the stream to the video element.

Question: Multiple VideoStreamMerger to play in sync?

Hi

I was wondering:

  1. if its possible to sync the play between multiple VideoStreamMerger on a page?

  2. Or one VideoStreamMerger to display something like
    Let say [100% x 100%] as showing the full screen of the video.
    I would like the video to show
    [50% x 50%] [white area(probably 10%)] [50% x 50%]
    so its cropped 50% followed by some white area, then the other 50%.

I hope you understand what i'm trying to achieve here :)

CPU usage with merge

I am trying to use your SDK for stream merging. My first impression is this is really amazing and exactly doing what I need. I see one issue with high cpu usage. Is this expected?

Stream stops if the tab is minimized

I use screen and media streams and merge them using this library.
I use webrtc recorder to record the output stream and download it.
Everything works as expected, except when the browser is minimized, the video stream pauses (although audio stream continues) till the browser is minimized, and continues once it's maximized.
My initial suspect was issue #9, so I disabled/enabled the chrome flag and tried, it didn't help.
To zero in on the source, I just recorded the screen stream, they work fine, even if the browser is minimized, I recorded only the video stream and tested it works fine. The only issue is when I am saving the merged feed.

Please check the code source attached below.

Low-resolution merged stream

Hello! Fantastic library, thanks for your hard work!

One thing I'd like to do is be able to merge a MediaStream of my screen share (using screen-record, as demonstrated in your README), and then crop it.

When I merge a screen stream, and then view it in a <video> element, it comes out somewhat low-res and pixelated. However, if I view the screen stream directly with the <video> element, instead of the merged stream, the resolution appears fine.

I've attached a screenshot to demonstrate the issue.

Is this a <canvas> related problem, and is there a potential solution?

screen shot 2018-01-22 at 12 45 24 am

Non-issue: Cordova comparability?

Hey @rationalcoding,

Before I spend hours trying (and possibly failing), would video-stream-merger be able to combine a .mp4 video with a .wav (or AAC) file of the same length on Cordova (iOS and Android)?

Feel free to close this after answering.

Thanks so much!

Flip and merge a stream

How do I flip a video horizontally such that it is mirrored? I only want to mirror one video in the canvas, not sure how to achieve that.

addMediaElement with mute:false and Microphone (from getUserMedia) conflict

Hi ! Thanks for this great library...

I've tried new addMediaElement features and it works well on playing from html video with sound (mute:false). But when i try to merge with camera and microphone from getUserMedia, it throws some error :

Failed to execute 'createMediaElementSource' on 'BaseAudioContext': HTMLMediaElement already connected previously to a different MediaElementSourceNode.

at VideoStreamMerger.addMediaElement (video-stream-merger\src\index.js:130:46)

I believe this was caused by conflict using 2 BaseAudioContext from different source? is there any workaround if i want to merge and use this 2 audio from microphone and video at the same time?

Failed to construct 'AudioContext': The number of hardware contexts provided (6) is greater than or equal to the maximum bound (6)

I've to refresh the video merger stream in my application. I implement this feature by reinstantiating the merger object. However, destroying the merger up to 6 times will cause the error.

Solution:

Add

self._audioCtx.close()

Before

https://github.com/RationalCoding/video-stream-merger/blob/gh-pages/src/index.js#L202

It will release the hardware of the context while self._audioCtx = null won't

destroy merger

Im having an issue that starting video merger creates video elements on the DOM but destroy wont remove them. Is it ok to remove them on destroy? if it is I can create a PR.

Method to update a video stream

Need a method to update a stream in my live streaming app ,the position and size of the video stream may be dynamically changed by user,the api should look like:

merger.updateStream(id|MediaStream,opt)

BTW, Is there a z(-index) option to control the overlap order of video stream ?

Thanks for the good library.

Error thrown in Firefox when merging an audio-only MediaStream

Firefox throws an error in the draw function when merging an audio-only MediaStream.

This line causes the error:

self._ctx.drawImage(video.element, video.x, video.y, video.width, video.height)

Do you think a check could be added to skip audio-only streams in the draw function?

Error

NS_ERROR_NOT_AVAILABLE: index.js:313
    _draw index.js:313
    forEach (index):262
    _draw index.js:309
    <anonymous> (index):974
    invokeTask zone.js:423
    runTask zone.js:195
    invokeTask zone.js:498
    invoke zone.js:487
    timer zone.js:3045

Support for mobile (react-native)

In web is good to use but this module not support for mobile (i'm producing app in platform react-native). Can you suggest for me modules merger-video-stream support for react-native ?

Support Node.js

I am using the package v3.6.3 in nodejs with npm6.14.6
Got window not defined error, changed it to 'this' and it gave error 'document not defined'. as there are createElement codes in there. Is there a node version of it? or how can it be used?
ReferenceError: window is not defined at new VideoStreamMerger (<repo>/node_modules/video-stream-merger/dist/video-stream-merger.js:2:163)

is crop work ๏ผŸ

first thanks for your work,my code have any problem?
I want to implement the cutting function, but it seems that the result is not correct
image
result:
image
it seems just move the screen,but not crop

fps sometime is 0

hi:
i just test your lib. i fond that sometime fps is very slow.

    merger = new VideoStreamMerger({
        width: 640,   
        height: 480,  
        fps: 25    
    });

    merger.start();

image

Audio Issues with Video Merger

Hello I am implementing WebRTC conference app using video-merger.

App consists of One-To-Many Model and One Master Node get streams from each viewers and Master merge all streams and broadcast it.

I allocate merger to each Viewers and merge the each streams including video and audio. and i add video, audio on/off function by removing and adding with addStream() mute options.

The problem is, video works fine but "sometime" audio is not working. Although I set mute option always to false, the audio stream is not added to merger.(video works fine).

It seems the problem somtimes occurs in Chrome. Firefox works fine.

My Audio on/off function code is like this

 AudioOn() {
       var audioMute = false;
       merger.removeStream(stream);
       merger.addStream(stream, {
            x: 0,
            y: 0,
            width: merger.width,
            height: merger.height,
            mute: audioMute,
        });
    }
 AudioOff(){
        var audioMute = true;
       merger.removeStream(stream);
       merger.addStream(stream, {
            x: 0,
            y: 0,
            width: merger.width,
            height: merger.height,
            mute: audioMute,
        });
    }

Is there any problem coding like this? Or any dependencies with Browser?

Questions

@tvedtorama Moved from simple-peer#50

@rationalcoding I think your library looks like a promising solution for this problem, but I have a few questions:

Is the merging logic supported on the browsers that support WebRTC or just on Chrome?

Could you publish the source for your demo, I can't find it?

Is it possible to detect that there are "no streams in the merged stream"? Ie - that the host is currently not transmitting anything?
I guess this could be sent alongside the stream, on the data channel, but anyways...

Question: Reordering multiple streams

I'm dealing with video position dynamically, as a example, for 4 people in a room, here is a similar code:

  const propsFor4Streams = {
    [Directions.VERTICAL]: (index, containerWidth, containerHeight) => ({
        x: 0,
        y: (containerHeight / 2) * index,
        width: containerWidth / 2,
        height: containerHeight / 2,
    })
    ,
    [Directions.FLEX]: (index, containerWidth, containerHeight) => ({
        x: index % 2 && containerWidth / 2,
        y: index >= 2 ? containerHeight / 2 : 0,
        height: containerHeight / 2,
        width: containerWidth / 2
    })
}

One of the 4 people gets the stream merged and send to a streaming service (a machine with a WOWZA running on it) via a webrtc connection:

const { result } = this.streamMerger
const tracks = result.getTracks()
console.log(`Adding ${tracks.length} tracks to peer connection`, tracks)
tracks.forEach(track => this.peerConnection.addTrack(track, result))

The connection works very nicely, but with a poor performance when I use streamMerger.result.
As a test scenario, I used one of the streams inside the video tags that you generated in your code, and in that case it works with a very good performance.
Have you faced anything that looks like this?

Another questions, is there a better way to append a new stream from a new participant in the room?
Every time a user connects, I create the whole merger again, as I must calculate the x,y, width and height for each scenario:

this.streamMerger = new VideoStreamMerger({
      width: 720,
     height: 480,
     frameRate: 29,
     ...config
})

const streams = this.getAllCurrentStreams()
// The compute streams size is where I have a switch case for every scenario
computeStreamsSize(streams).map(({ stream, props }) => this.streamMerger.addStream(stream, props))
this.streamMerger.start()

With this code, the stream in the peer connection stop working, right?
The question is the same, is there a better way to do it all?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.