# mediastream-to-webm

> WebRTC MediaStreams to live webm data streams.

Latest version **1.0.2** (published 2019-07-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install mediastream-to-webm
pnpm add mediastream-to-webm
yarn add mediastream-to-webm
bun add mediastream-to-webm
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-07-02 |
| First published | 2018-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 386.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Thomas Mullen |
| Maintainers | rationalcoding |

## Links

- npm: https://www.npmjs.com/package/mediastream-to-webm
- npm.io page: https://npm.io/package/mediastream-to-webm

## Dependencies (6)

- [ebml](https://npm.io/package/ebml.md) ^2.2.1
- [inherits](https://npm.io/package/inherits.md) ^2.0.3
- [mediasource](https://npm.io/package/mediasource.md) ^2.1.3
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.3.3
- [webm-cluster-stream](https://npm.io/package/webm-cluster-stream.md) ^1.0.0
- [media-recorder-stream](https://npm.io/package/media-recorder-stream.md) ^2.1.1

## Recent versions

- 1.0.2 (latest) — 2019-07-02
- 1.0.1 — 2018-01-25
- 1.0.0 — 2018-01-25

## README

# mediastream-to-webm

Converts MediaStreams to live WebM streams. Currently only for Chrome.

Allows you to send video/audio as a single outgoing data stream to many peers.

## Features
- Packages webm clusters and headers into standalone chunks that don't require the entire stream.
- Fixes MSE problems with timestamp gaps.
- Abstracts away recording and source buffers.

## Install
```javascript
var MediaStreamToWebm = require('mediastream-to-webm')
```

```html
<script src="dist/mediastream-to-webm.js" />
```

## Usage

```javascript
// Wrap your MediaStream into an encoder
var encodedStream = MediaStreamToWebm.EncodedStream(mediaStream)

// The encoded stream is a ReadableStream
encodedStream.pipe(socket1) 
encodedStream.pipe(socket2) // pipe as many times as you want, at any time, without worrying about the structure of the stream
encodedStream.pipe(socket2)
// ...
```

```javascript
var decodedStream = MediaStreamToWebm.DecodedStream()
socket.pipe(decodedStream) // pipe the encoded stream into the decoded

// The buffered video element is available for us to watch!
var video = decodedStream.videoElement
video.autoplay = true
video.oncanplay = function () {
    video.play()
}
document.body.appendChild(video) 
```

## API
### `MediaStreamToWebm.EncodedStream(mediaStream, opts)`
Encode a MediaStream into a webm data stream.

`mediaStream` - The input MediaStream you want to broadcast.

`opts` - Options object. Default is:

```javascript
{
    interval: 10,
    mimeType: 'video/webm; codecs="opus,vp8"'
}
```

### `MediaStreamToWebm.DecodedStream(opts)`
Decode an encoded webm data stream. Decoded data will be buffered into a video element.

`opts` - Options object. Default is:

```javascript
{
    videoElement: null, // specify an existing video element
    mimeType: 'video/webm; codecs="opus,vp8"'
}
```

## `DecodedStream.videoElement`
The video element that will be buffered with the decoded webm stream.

## Notes
- Currently only works on Chrome (Firefox refuses to accept a webm stream from their own MediaRecorder...)
- This module has additional overhead for live streaming. If you want just want a prerecorded stream, use `media-recorder-stream`.
- Headers are sent with every chunk and this packaged needs to be decoded. You won't be able to pass the data stream directly into a webm player.
- Less efficient and versatile than sending MediaStreams over WebRTC. This "dumb" video stream is not meant to be a replacement for the adaptive bitrate, network-aware SRTP protocol used by WebRTC.

---
_Source: https://npm.io/package/mediastream-to-webm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
