media-source-stream
feross/mediasource
Deprecated: UseCreates MSE MediaSource objects from readable streams.
Does the reverse of media-recorder-stream.
npm install media-source-stream
Usage
The easiest way to get a compatible readable stream is to use media-recorder-stream, but you can also create your own via FFMPEG.
var getMedia = var MediaRecorderStream = var MediaSourceStream =
Why?
- Modify MediaStreams in realtime, in the browser.
- Send audio/video data over a WebRTC DataChannel.
- Send audio/video over a
net.socket
. - Upload media without needing to finish recording.
API
sourceStream = new MediaSourceStream([opts])
Create a new MediaSourceStream, which is a writable stream.
Optional opts
is the options object to pass to the MediaSource
constructor.
sourceStream.mediaSource
The output MediaSource
object.
Example
Here is an example of how to send video/audio over a WebRTC DataChannel (with simple-peer), without using media channels. You could also do this over WebSockets.
Keep in mind there is a moderate increase in latency, so this is only suitable when MediaStreams aren't an option.
Note: You want to start recording once you already have a connection so that all recorded data is sent. If any initial data is missing, the stream cannot be reconstructed on the other side.