WebRTC JavaScript Library for Audio+Video+Screen+Canvas (2D+3D animation) Recording
Chrome Extension or Dozens of Simple-Demos and it is Open-Sourced and has API documentation
A demo using promises:
let stream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});
let recorder = new RecordRTCPromisesHandler(stream, {
type: 'video'
});
recorder.startRecording();
const sleep = m => new Promise(r => setTimeout(r, m));
await sleep(3000);
await recorder.stopRecording();
let blob = await recorder.getBlob();
invokeSaveAsDialog(blob);
A demo using normal coding:
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then(async function(stream) {
let recorder = RecordRTC(stream, {
type: 'video'
});
recorder.startRecording();
const sleep = m => new Promise(r => setTimeout(r, m));
await sleep(3000);
recorder.stopRecording(function() {
let blob = recorder.getBlob();
invokeSaveAsDialog(blob);
});
});
Browsers Support
Browser | Operating System | Features |
---|
Google Chrome | Windows + macOS + Ubuntu + Android | audio + video + screen |
Firefox | Windows + macOS + Ubuntu + Android | audio + video + screen |
Opera | Windows + macOS + Ubuntu + Android | audio + video + screen |
Edge (new) | Windows (7 or 8 or 10) and MacOSX | audio + video + screen |
Safari | macOS + iOS (iPhone/iPad) | audio + video |
Codecs Support
Browser | Video | Audio |
---|
Chrome | VP8, VP9, H264, MKV | OPUS/VORBIS, PCM |
Opera | VP8, VP9, H264, MKV | OPUS/VORBIS, PCM |
Firefox | VP8, H264 | OPUS/VORBIS, PCM |
Safari | VP8 | OPUS/VORBIS, PCM |
Edge (new) | VP8, VP9, H264, MKV | OPUS/VORBIS, PCM |
CDN
<script src="https://www.WebRTC-Experiment.com/RecordRTC.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/RecordRTC/5.6.2/RecordRTC.js"></script>
<script src="node_modules/recordrtc/RecordRTC.js"></script>
<script src="bower_components/recordrtc/RecordRTC.js"></script>
Configuration
const recorder = RecordRTC(stream, {
type: 'video',
mimeType: 'video/webm',
recorderType: MediaStreamRecorder,
disableLogs: true,
timeSlice: 1000,
ondataavailable: function(blob) {},
checkForInactiveTracks: false,
onTimeStamp: function(timestamp) {},
bitsPerSecond: 128000,
audioBitsPerSecond: 128000,
videoBitsPerSecond: 128000,
frameInterval: 90,
previewStream: function(stream) {},
video: HTMLVideoElement,
canvas: {
width: 640,
height: 480
},
sampleRate: 96000,
desiredSampRate: 16000,
bufferSize: 16384,
numberOfAudioChannels: 2,
frameRate: 30,
bitrate: 128000,
elementClass: 'multi-streams-mixer'
});
MediaStream parameter
MediaStream parameter accepts following values:
let recorder = RecordRTC(MediaStream || HTMLCanvasElement || HTMLVideoElement || HTMLElement, {});
API
RecordRTC.prototype = {
startRecording: function() {},
stopRecording: function(blobURL) {},
pauseRecording: function() {},
resumeRecording: function() {},
setRecordingDuration: function() {},
reset: function() {},
save: function(fileName) {},
getBlob: function() {},
toURL: function() {},
getDataURL: function(dataURL) {},
getInternalRecorder: function() {},
initRecorder: function() {},
onStateChanged: function(state) {},
writeToDisk: function(audio: Blob, video: Blob, gif: Blob) {},
getFromDisk: function(dataURL, type) {},
setAdvertisementArray: function([webp1, webp2]) {},
clearRecordedData: function() {},
destroy: function() {},
getState: function() {},
state: string,
blob: Blob,
buffer: ArrayBuffer,
version: string,
bufferSize: integer,
sampleRate: integer
}
Please check documentation here: https://recordrtc.org/
Global APIs
let size = bytesToSize(recorder.getBlob().size);
getSeekableBlob(recorder.getBlob(), function(seekableBlob) {
invokeSaveAsDialog(seekableBlob);
});
invokeSaveAsDialog(recorder.getBlob(), 'video.webm');
let browserInfo = {isSafari, isChrome, isFirefox, isEdge, isOpera};
DiskStorage = {
init: function() {},
Fetch: function({audioBlob: Blob, videoBlob: Blob, gifBlob: Blob}) {},
Store: function({audioBlob: Blob, videoBlob: Blob, gifBlob: Blob}) {},
onError: function() {},
dataStoreName: function() {}
};
How to fix echo issues?
- Set
<video>.muted=true
and <video>.volume=0
- Pass
audio: {echoCancellation:true}
on getUserMedia
Wiki
Releases
Unit Tests
Issues/Questions?
Credits
Spec & Reference
- MediaRecorder API
- Web Audio API
- Canvas2D
- Media Capture and Streams
Who is using RecordRTC?
License
RecordRTC.js is released under MIT license . Copyright (c) Muaz Khan.