MediaStreamRecorder.js - Demos
A cross-browser implementation to record audio/video streams:
- MediaStreamRecorder can record both audio and video in single WebM file on Firefox.
- MediaStreamRecorder can record audio as WAV and video as either WebM or animated gif on Chrome.
MediaStreamRecorder is useful in scenarios where you're planning to submit/upload recorded blobs in realtime to the server! You can get blobs after specific time-intervals.
Demos using MediaStreamRecorder.js library
Experiment Name | Demo | Source Code |
---|---|---|
Audio Recording | Demo | Source |
Video Recording | Demo | Source |
Gif Recording | Demo | Source |
MultiStreamRecorder Demo | Demo | Source |
There is a similar project: RecordRTC! Demo - Documentation
How to link scripts?
You can install scripts using NPM:
npm install msr # or via "bower"bower install msr
Now try node server.js
and open https://localhost:9001/
Test on NPM
var MediaStreamRecorder = ; console; console; var recorder = {};console; console; var multiStreamRecorder = {};console;
- Live NPM test: https://tonicdev.com/npm/msr
Or try npm-test.js
:
cd node_modules
cd msr
node npm-test.js
Then link single/standalone "MediaStreamRecorder.js" file:
<!-- or bower --> <!-- CDN --> <!-- WWW --> <!-- or link specific release -->
Record audio+video
Record audio/wav
How to manually stop recordings?
mediaRecorder;
How to pause recordings?
mediaRecorder;
How to resume recordings?
mediaRecorder;
How to save recordings?
// invoke save-as dialog for all recorded blobsmediaRecorder; // or pass external blob/filemediaRecorder;
How to upload recorded files using PHP?
PHP code:
JavaScript Code:
var fileType = 'video'; // or "audio"var fileName = 'ABCDEF.webm'; // or "wav" or "ogg" var formData = ;formData;formData; ; { var request = ; request { if requestreadyState == 4 && requeststatus == 200 ; }; request; request;}
API Documentation
recorderType
You can force StereoAudioRecorder or WhammyRecorder or similar recorders on Firefox or Edge; even on Chrome and Opera.
All browsers will be using your specified recorder:
// force WebAudio API on all browsers// it allows you record remote audio-streams in Firefox// it also works in Microsoft EdgemediaRecorderrecorderType = StereoAudioRecorder; // force webp based webm encoder on all browsersmediaRecorderrecorderType = WhammyRecorder; // force MediaRecorder API on all browsers// Chrome Canary/Dev already implemented MediaRecorder API however it is still behind a flag.// so this property allows you force MediaRecorder in Chrome.mediaRecorderrecorderType = MediaRecorderWrapper; // force GifRecorder in all browsers. Both WhammyRecorder and MediaRecorder API will be ignored.mediaRecorderrecorderType = GifRecorder;
audioChannels
To choose between Stereo or Mono audio.
It is an integer value that accepts either 1 or 2. "1" means record only left-channel and skip right-one. The default value is "2".
mediaRecorderaudioChannels = 1;
Note: It requires following recorderType:
mediaRecorderrecorderType = StereoAudioRecorder;
bufferSize
You can set following audio-bufferSize values: 0, 256, 512, 1024, 2048, 4096, 8192, and 16384. "0" means: let chrome decide the device's default bufferSize. Default value is "2048".
mediaRecorderbufferSize = 0;
sampleRate
Default "sampleRate" value is "44100". Currently you can't modify sample-rate in windows that's why this property isn't yet exposed to public API.
It accepts values only in range: 22050 to 96000
// set sampleRate for NON-windows systemsmediaRecordersampleRate = 96000;
video
It is recommended to pass your HTMLVideoElement to get most accurate result.
videoRecordervideo = yourHTMLVideoElement;videoRecorder { // record audio here to fix sync issues // Note: MultiStreamRecorder auto handles audio sync issues. videoRecorder; // clear all blank frames audioRecorderstartinterval;};
stop
This method allows you stop recording.
mediaRecorder;
pause
This method allows you pause recording.
mediaRecorder;
resume
This method allows you resume recording.
mediaRecorder;
save
This method allows you save recording to disk (via save-as dialog).
// invoke save-as dialog for all recorded blobsmediaRecorder; // or pass external blob/filemediaRecorder;
canvas
Using this property, you can pass video resolutions:
mediaRecordercanvas = width: 1280 height: 720;
videoWidth and videoHeight
You can stretch video to specific width/height:
mediaRecordervideoWidth = 1280;mediaRecordervideoHeight = 720;
clearOldRecordedFrames
This method allows you clear current video-frames. You can use it to remove blank-frames.
videoRecordervideo = yourHTMLVideoElement;videoRecorder { videoRecorder; // clear all blank frames audioRecorderstartinterval;};
stop
This method allows you stop entire recording process.
mediaRecorder;
start
This method takes "interval" as the only argument and it starts recording process:
mediaRecorderstart5 * 1000; // it takes milliseconds
ondataavailable
This event is fired according to your interval and "stop" method.
mediaRecorder { ;};
onstop
This event is fired when recording is stopped, either by invoking "stop" method or in case of any unexpected error:
mediaRecorder { // recording has been stopped.};
mimeType
This property allows you set output media type:
// video:videoRecordermimeType = 'video/webm';videoRecordermimeType = 'video/mp4'; // audio:audioRecordermimeType = 'audio/webm'; // MediaRecorderWrapperaudioRecordermimeType = 'audio/ogg'; // MediaRecorderWrapperaudioRecordermimeType = 'audio/wav'; // StereoAudioRecorderaudioRecordermimeType = 'audio/pcm'; // StereoAudioRecorder // gif:gifRecordermimeType = 'image/gif'; // GifRecorder
bitsPerSecond
// currently supported only in FirefoxvideoRecorderbitsPerSecond = 12800;
quality
// only chrome---whilst using WhammyRecordervideoRecorderquality = 8;
speed
// only chrome---whilst using WhammyRecordervideoRecorderspeed = 100;
Browser Support
Browser | Support |
---|---|
Firefox | Stable / Aurora / Nightly |
Google Chrome | Stable / Canary / Beta / Dev |
Opera | Stable / NEXT |
Android | Chrome / Firefox / Opera |
Microsoft Edge | Normal Build |
Contributors
License
MediaStreamRecorder.js library is released under MIT licence.