Socket
Socket
Sign inDemoInstall

extendable-media-recorder

Package Overview
Dependencies
Maintainers
1
Versions
379
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.1.5 to 7.1.6

13

build/es2019/factories/webm-pcm-media-recorder.js

@@ -8,8 +8,3 @@ import { encode, instantiate } from 'media-encoder-host';

const bufferedArrayBuffers = [];
// @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface.
const channelCount = audioTracks.length === 0
? undefined
: audioTracks[0].getSettings().channelCount;
const nativeMediaRecorder = new nativeMediaRecorderConstructor(mediaStream, { mimeType: 'audio/webm;codecs=pcm' });
const sampleRate = audioTracks.length === 0 ? undefined : audioTracks[0].getSettings().sampleRate;
let promisedPartialRecording = null;

@@ -66,2 +61,3 @@ let stopRecording = () => { }; // tslint:disable-line:no-empty

start(timeslice) {
var _a, _b;
/*

@@ -75,2 +71,9 @@ * Bug #6: Chrome will emit a blob without any data when asked to encode a MediaStream with a video track into an audio

if (nativeMediaRecorder.state === 'inactive') {
// Bug #19: Chrome does not expose the correct channelCount property right away.
// @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface.
const channelCount = ((_a = audioTracks[0]) === null || _a === void 0 ? void 0 : _a.getSettings()).channelCount;
const sampleRate = (_b = audioTracks[0]) === null || _b === void 0 ? void 0 : _b.getSettings().sampleRate;
if (channelCount === undefined) {
throw new Error('The channelCount is not defined.');
}
if (sampleRate === undefined) {

@@ -77,0 +80,0 @@ throw new Error('The sampleRate is not defined.');

@@ -882,8 +882,5 @@ (function (global, factory) {

var bufferedArrayBuffers = [];
// @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface.
var channelCount = audioTracks.length === 0 ? undefined : audioTracks[0].getSettings().channelCount;
var nativeMediaRecorder = new nativeMediaRecorderConstructor(mediaStream, {
mimeType: 'audio/webm;codecs=pcm'
});
var sampleRate = audioTracks.length === 0 ? undefined : audioTracks[0].getSettings().sampleRate;
var promisedPartialRecording = null;

@@ -968,2 +965,3 @@ var stopRecording = function stopRecording() {}; // tslint:disable-line:no-empty

start: function start(timeslice) {
var _a, _b;
/*

@@ -977,2 +975,9 @@ * Bug #6: Chrome will emit a blob without any data when asked to encode a MediaStream with a video track into an audio

if (nativeMediaRecorder.state === 'inactive') {
// Bug #19: Chrome does not expose the correct channelCount property right away.
// @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface.
var channelCount = ((_a = audioTracks[0]) === null || _a === void 0 ? void 0 : _a.getSettings()).channelCount;
var sampleRate = (_b = audioTracks[0]) === null || _b === void 0 ? void 0 : _b.getSettings().sampleRate;
if (channelCount === undefined) {
throw new Error('The channelCount is not defined.');
}
if (sampleRate === undefined) {

@@ -979,0 +984,0 @@ throw new Error('The sampleRate is not defined.');

@@ -39,3 +39,3 @@ {

"eslint": "^8.35.0",
"eslint-config-holy-grail": "^55.0.13",
"eslint-config-holy-grail": "^55.0.14",
"extendable-media-recorder-wav-encoder": "^7.0.84",

@@ -59,8 +59,8 @@ "grunt": "^1.6.1",

"pretty-quick": "^3.1.3",
"rimraf": "^4.1.2",
"rollup": "^3.17.3",
"rimraf": "^4.3.0",
"rollup": "^3.18.0",
"sinon": "^15.0.1",
"sinon-chai": "^3.7.0",
"ts-loader": "^9.4.2",
"tsconfig-holy-grail": "^12.0.0",
"tsconfig-holy-grail": "^12.0.1",
"tslint": "^6.1.3",

@@ -96,3 +96,3 @@ "tslint-config-holy-grail": "^54.0.1",

"types": "build/es2019/module.d.ts",
"version": "7.1.5"
"version": "7.1.6"
}

@@ -7,3 +7,3 @@ # extendable-media-recorder

This package provides (a part of) the MediaRecorder API as defined by the [MediaStream Recording](https://w3c.github.io/mediacapture-record) specification. If possible it will use the native implementation which is available in Chrome and Firefox.
This package provides (a part of) the MediaRecorder API as defined by the [MediaStream Recording](https://w3c.github.io/mediacapture-record) specification. If possible it will use the native implementation.

@@ -29,2 +29,4 @@ In addition this package also allows to define custom encoders. Those encoders can be used to render files which are not supported by any browser so far. This does currently only work for audio encoders.

### Using a custom encoder
`extendable-media-recorder` also exports a `register()` function which can be used to define custom encoders. One predefined encoder is available as the [`extendable-media-recorder-wav-encoder` package](https://github.com/chrisguttandin/extendable-media-recorder-wav-encoder). It can be used as shown here.

@@ -42,4 +44,24 @@

### Setting the sample rate
The `MediaRecoder` has no way to modify the sample rate directly. It uses the `sampleRate` of the given `MediaStream`. You can read the value being used like this:
```js
const { sampleRate } = stream.getAudioTracks()[0].getSettings();
```
To modifiy the sample rate of the recording you need to change the `sampleRate` of the `MediaStream`. But that's not possible either. Therefore the most reliable way is to use an `AudioContext` at the desired `sampleRate` to do the resampling.
```js
const audioContext = new AudioContext({ sampleRate: 16000 });
const mediaStreamAudioSourceNode = new MediaStreamAudioSourceNode(audioContext, { mediaStream: stream });
const mediaStreamAudioDestinationNode = new MediaStreamAudioDestinationNode(audioContext);
mediaStreamAudioSourceNode.connect(mediaStreamAudioDestinationNode);
const mediaRecorder = new MediaRecorder(mediaStreamAudioSourceNode.stream);
```
## Inner Workings
Internally two different techniques are used to enable custom encoders. In Chrome the native MediaRecorder is used to encode the stream as webm file with pcm encoded audio. Then a minimal version of [ts-ebml](https://github.com/legokichi/ts-ebml) is used to parse that pcm data to pass it on to the encoder. In other browsers the Web Audio API is used to get the pcm data of the recorded audio.

@@ -16,9 +16,3 @@ import { encode, instantiate } from 'media-encoder-host';

const bufferedArrayBuffers: ArrayBuffer[] = [];
// @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface.
const channelCount =
audioTracks.length === 0
? undefined
: (<MediaTrackSettings & { channelCount?: number }>audioTracks[0].getSettings()).channelCount;
const nativeMediaRecorder = new nativeMediaRecorderConstructor(mediaStream, { mimeType: 'audio/webm;codecs=pcm' });
const sampleRate = audioTracks.length === 0 ? undefined : audioTracks[0].getSettings().sampleRate;

@@ -98,2 +92,11 @@ let promisedPartialRecording: null | Promise<void> = null;

if (nativeMediaRecorder.state === 'inactive') {
// Bug #19: Chrome does not expose the correct channelCount property right away.
// @todo TypeScript v4.4.2 removed the channelCount property from the MediaTrackSettings interface.
const channelCount = (<MediaTrackSettings & { channelCount?: number }>audioTracks[0]?.getSettings()).channelCount;
const sampleRate = audioTracks[0]?.getSettings().sampleRate;
if (channelCount === undefined) {
throw new Error('The channelCount is not defined.');
}
if (sampleRate === undefined) {

@@ -100,0 +103,0 @@ throw new Error('The sampleRate is not defined.');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc