This is forked from MediaStreamRecorder.
MediaStreamRecorder.js - Demos
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 |
A cross-browser implementation to record
- Camera
- Microphone
- Screen (full screen, apps' screens, tab, HTML elements)
- Canvas 2D as well as 3D animations (gaming/etc.)
You can record above four options altogether (in single container).
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.
Browser Support
Browser | Support | Features |
---|---|---|
Firefox | Stable / Aurora / Nightly | Audio+Video (Both local/remote) |
Google Chrome | Stable / Canary / Beta / Dev | Audio+Video (Both local/remote) |
Opera | Stable / NEXT | Audio+Video (Both local/remote) |
Android | Chrome / Firefox / Opera | Audio+Video (Both local/remote) |
Microsoft Edge | Normal Build | Only Audio - No Video - No Canvas - No Screen |
Safari 11 | preview | Only Audio - No Video - No Canvas - No Screen |
There is a similar project: RecordRTC! Demo - Documentation
How to link scripts?
You can install scripts using NPM:
npm install msr-labs # 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 Multiple Videos
Record multiple videos in single WebM file.
var arrayOfStreams = yourVideo screen remoteVideo1 remoteVideo2;var multiStreamRecorder = arrayOfStreams ;
You can add additional streams at runtime:
multiStreamRecorder;
Currently, you can only record 4-maximum videos in single WebM container.
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;
Upload to PHP Server
Your HTML file:
mediaRecorder { // upload each blob to PHP server ;}; { var file = blob 'msr-' + + '.webm' type: 'video/webm' ; // create FormData var formData = ; formData; formData; ;} { var request = ; request { if requestreadyState == 4 && requeststatus == 200 ; }; request; request;}
Save.php file:
Regarding PHP upload issues:
Don't forget to create uploads directory here:
https://path-to-your-server/uploads/ ----- inside same directory as "save.php"
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 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;
Contributors
License
MediaStreamRecorder.js library is released under MIT licence.