RecordRTC Documentation / RecordRTC Wiki Pages / RecordRTC Demo / WebRTC Experiments
RecordRTC is a JavaScript-based media-recording library for modern web-browsers (supporting WebRTC getUserMedia API). It is optimized for different devices and browsers to bring all client-side (pluginfree) recording solutions in single place.
Please check dev directory for development files.
- RecordRTC API Reference
- MRecordRTC API Reference
- MediaStreamRecorder API Reference
- StereoAudioRecorder API Reference
- WhammyRecorder API Reference
- Whammy API Reference
- CanvasRecorder API Reference
- GifRecorder API Reference
- Global API Reference
Browsers Support:
How RecordRTC encodes wav/webm?
Media File | Bitrate/Framerate | encoders | Framesize | additional info |
---|
Audio File (WAV) | 1411 kbps | pcm_s16le | 44100 Hz | stereo, s16 |
Video File (WebM) | 60 kb/s | (whammy) vp8 codec yuv420p | -- | SAR 1:1 DAR 4:3, 1k tbr, 1k tbn, 1k tbc (default) |
RecordRTC Demos
- RecordRTC to Node.js
- RecordRTC to PHP
- RecordRTC to ASP.NET MVC
- RecordRTC & HTML-2-Canvas i.e. Canvas/HTML Recording!
- MRecordRTC i.e. Multi-RecordRTC!
- RecordRTC on Ruby!
- RecordRTC over Socket.io
- ffmpeg-asm.js and RecordRTC! Audio/Video Merging & Transcoding!
- RecordRTC / PHP / FFmpeg
- Record Audio and upload to Nodejs server
- ConcatenateBlobs.js - Concatenate multiple recordings in single Blob!
- Remote stream recording
- Mp3 or Wav Recording
How to link?
npm install recordrtc
# you can use with "require" (browserify/nodejs)
var RecordRTC = require('recordrtc');
var recorder = RecordRTC(mediaStream, { type: 'audio'});
or using Bower:
bower install recordrtc
To use it:
<script src="./node_modules/recordrtc/RecordRTC.js"></script>
<script src="//cdn.WebRTC-Experiment.com/RecordRTC.js"></script>
<script src="//www.WebRTC-Experiment.com/RecordRTC.js"></script>
There are some other NPM packages regarding RecordRTC:
How to capture stream?
<script src="https://cdn.rawgit.com/webrtc/adapter/master/adapter.js"></script>
<script>
function successCallback(stream) {
}
function errorCallback(errror) {
}
var mediaConstraints = { video: true, audio: true };
navigator.mediaDevices.getUserMedia(mediaConstraints).then(successCallback).catch(errorCallback);
</script>
Record audio+video in Firefox
You'll be recording both audio/video in single WebM container. Though you can edit RecordRTC.js to record in mp4.
var recordRTC;
function successCallback(stream) {
recordRTC = RecordRTC(MediaStream);
recordRTC.startRecording();
}
function errorCallback(errror) {
}
var mediaConstraints = { video: true, audio: true };
navigator.mediaDevices.getUserMedia(mediaConstraints).then(successCallback).catch(errorCallback);
btnStopRecording.onclick = function () {
recordRTC.stopRecording(function (audioVideoWebMURL) {
video.src = audioVideoWebMURL;
var recordedBlob = recordRTC.getBlob();
recordRTC.getDataURL(function(dataURL) { });
});
};
Demo: AudioVideo-on-Firefox.html
Record only Audio
var recordRTC = RecordRTC(mediaStream);
recordRTC.startRecording();
recordRTC.stopRecording(function(audioURL) {
audio.src = audioURL;
var recordedBlob = recordRTC.getBlob();
recordRTC.getDataURL(function(dataURL) { });
});
Echo Issues
Simply set volume=0
or muted=true
over <audio>
or <video>
element:
videoElement.muted = true;
audioElement.muted = true;
Otherwise, you can pass some media constraints:
function successCallback(stream) {
}
function errorCallback(errror) {
}
var mediaConstraints = {
audio: {
mandatory: {
echoCancellation: false,
googAutoGainControl: false,
googNoiseSuppression: false,
googHighpassFilter: false
},
optional: [{
googAudioMirroring: false
}]
},
};
navigator.mediaDevices.getUserMedia(mediaConstraints).then(successCallback).catch(errorCallback);
Record Video
Everything is optional except type:'video'
:
var options = {
type: 'video'
};
var recordRTC = RecordRTC(mediaStream, options);
recordRTC.startRecording();
recordRTC.stopRecording(function(videoURL) {
video.src = videoURL;
var recordedBlob = recordRTC.getBlob();
recordRTC.getDataURL(function(dataURL) { });
});
Record animated GIF image
Everything is optional except type:'gif'
:
var options = {
type: 'gif',
frameRate: 200,
quality: 10
};
var recordRTC = RecordRTC(mediaStream, options);
recordRTC.startRecording();
recordRTC.stopRecording(function(gifURL) {
mediaElement.src = gifURL;
});
Record a Webpage
You can say it: "HTML/Canvas Recording using RecordRTC"!
<script src="//cdn.WebRTC-Experiment.com/RecordRTC.js"></script>
<script src="//cdn.webrtc-experiment.com/screenshot.js"></script>
<div id="elementToShare" style="width:100%;height:100%;background:green;"></div>
<script>
var elementToShare = document.getElementById('elementToShare');
var recordRTC = RecordRTC(elementToShare, {
type: 'canvas'
});
recordRTC.startRecording();
recordRTC.stopRecording(function(videoURL) {
video.src = videoURL;
var recordedBlob = recordRTC.getBlob();
recordRTC.getDataURL(function(dataURL) { });
});
</script>
See a demo: /Canvas-Recording/
API Reference
initRecorder
It is a function that can be used to initiate recorder however skip getting recording outputs. It will provide maximum accuracy in the outputs after using startRecording
method. Here is how to use it:
var audioRecorder = RecordRTC(mediaStream, {
type: 'audio',
recorderType: StereoAudioRecorder
});
var videoRecorder = RecordRTC(mediaStream, {
type: 'video',
recorderType: WhammyRecorder
});
videoRecorder.initRecorder(function() {
audioRecorder.initRecorder(function() {
videoRecorder.startRecording();
audioRecorder.startRecording();
});
});
After using stopRecording
, you'll see that both WAV/WebM blobs are having following charachteristics:
- Both are having same recording duration i.e. length
- Video recorder is having no blank frames
- Audio recorder is having no empty buffers
This method is really useful to sync audio/video outputs.
setRecordingDuration
You can ask RecordRTC to auto stop recording after specific duration. It accepts one mandatory and one optional argument:
recordRTC.setRecordingDuration(milliseconds, stoppedCallback);
recordRTC.setRecordingDuration(milliseconds).onRecordingStopped(stoppedCallback);
Try a simple demo; paste in the chrome console:
navigator.mediaDevices.getUserMedia({
video: true
}).then(function(stream) {
var recordRTC = RecordRTC(stream, {
type: 'video',
recorderType: WhammyRecorder
});
recordRTC.setRecordingDuration(5 * 1000).onRecordingStopped(function(url) {
console.debug('setRecordingDuration', url);
window.open(url);
})
recordRTC.startRecording();
}).catch(function(error) {
console.error(error);
});
clearRecordedData
This method can be used to clear old recorded frames/buffers. Snippet:
recorder.clearRecordedData();
recorderType
You can force any Recorder by passing this object over RecordRTC constructor:
var audioRecorder = RecordRTC(mediaStream, {
type: 'audio',
recorderType: StereoAudioRecorder
})
It means that ALL_BROWSERS will be using StereoAudioRecorder i.e. WebAudio API for audio recording.
This feature brings remote audio recording support in Firefox, and local audio recording support in Microsoft Edge.
You can even force WhammyRecorder
on Firefox however webp format isn't yet supported in standard Firefox builds. It simply means that, you're skipping MediaRecorder API in Firefox.
disableLogs
You can disable all the RecordRTC logs by passing this Boolean:
var recorder = RecordRTC(mediaStream, {
disableLogs: true
});
numberOfAudioChannels
You can force StereoAudioRecorder to record single-audio-channel only. It allows you reduce WAV file size to half.
var audioRecorder = RecordRTC(audioStream, {
type: 'audio',
recorderType: StereoAudioRecorder,
numberOfAudioChannels: 1
});
It will reduce WAV size to half!
This feature is useful only in Chrome and Microsoft Edge (WAV-recorders). It can work in Firefox as well.
How to set video width/height?
var options = {
type: 'video',
video: {
width: 320,
height: 240
},
canvas: {
width: 320,
height: 240
}
};
var recordVideo = RecordRTC(MediaStream, options);
pauseRecording
RecordRTC pauses recording buffers/frames.
recordRTC.pauseRecording();
resumeRecording
If you're using "initRecorder" then it asks RecordRTC that now its time to record buffers/frames. Otherwise, it asks RecordRTC to not only initialize recorder but also record buffers/frames.
recordRTC.resumeRecording();
getDataURL
Optionally get "DataURL" object instead of "Blob".
recordRTC.getDataURL(function(dataURL) {
mediaElement.src = dataURL;
});
getBlob
Get "Blob" object. A blob object looks similar to input[type=file]
. Which means that you can append it to FormData
and upload to server using XMLHttpRequest object. Even socket.io nowadays supports blob-transmission.
blob = recordRTC.getBlob();
toURL
A virtual URL. It can be used only inside the same browser. You can't share it. It is just providing a preview of the recording.
window.open( recordRTC.toURL() );
save
Invoke save-as dialog. You can pass "fileName" as well; though fileName argument is optional.
recordRTC.save('File Name');
bufferSize
Here is how to customize Buffer-Size for audio recording?
var options = {
bufferSize: 16384
};
var recordRTC = RecordRTC(audioStream, options);
Following values are allowed for buffer-size:
If you passed invalid value then you'll get blank audio.
sampleRate
Here is jow to customize Sample-Rate for audio recording?
var options = {
sampleRate: 96000
};
var recordRTC = RecordRTC(audioStream, options);
Values for sample-rate must be greater than or equal to 22050 and less than or equal to 96000.
If you passed invalid value then you'll get blank audio.
You can pass custom sample-rate values only on Mac (or additionally maybe on Windows 10).
onAudioProcessStarted
Note: "initRecorder" is preferred over this old hack. Both works similarly.
Useful to recover audio/video sync issues inside the browser:
recordAudio = RecordRTC( stream, {
onAudioProcessStarted: function( ) {
recordVideo.startRecording();
}
});
recordVideo = RecordRTC(stream, {
type: 'video'
});
recordAudio.startRecording();
onAudioProcessStarted
fixes shared/exclusive audio gap (a little bit). Because shared audio sometimes causes 100ms delay...
sometime about 400-to-500 ms delay.
Delay depends upon number of applications concurrently requesting same audio devices and CPU/Memory available.
Shared mode is the only mode currently available on 90% of windows systems especially on windows 7.
autoWriteToDisk
Using autoWriteToDisk
; you can suggest RecordRTC to auto-write to indexed-db as soon as you call stopRecording
method.
var recordRTC = RecordRTC(MediaStream, {
autoWriteToDisk: true
});
autoWriteToDisk
is helpful for single stream recording and writing to disk; however for MRecordRTC
; writeToDisk
is preferred one.
writeToDisk
You can write recorded blob to disk using writeToDisk
method:
recordRTC.stopRecording();
recordRTC.writeToDisk();
getFromDisk
You can get recorded blob from disk using getFromDisk
method:
RecordRTC.getFromDisk('all', function(dataURL, type) {
type == 'audio'
type == 'video'
type == 'gif'
});
RecordRTC.getFromDisk('audio', function(dataURL) {
});
For MRecordRTC; you can use word MRecordRTC
instead of RecordRTC
!
Another possible situation!
var recordRTC = RecordRTC(mediaStream);
recordRTC.startRecording();
recordRTC.stopRecording(function(audioURL) {
mediaElement.src = audioURL;
});
recordRTC.getFromDisk(function(dataURL) {
});
In the above example; you can see that recordRTC
instance object is used instead of global RecordRTC
object.
Clarifications
Is WinXP supported?
No WinXP SP2 based "Chrome" support. However, RecordRTC works on WinXP Service Pack 3.
Is Chrome on Android supported?
RecordRTC uses WebAudio API for stereo-audio recording. AFAIK, WebAudio is not supported on android chrome releases, yet.
Firefox merely supports audio-recording on Android devices.
Stereo or Mono?
Audio recording fails for mono
audio. So, try stereo
audio only.
MediaRecorder API (in Firefox) seems using mono-audio-recording instead.
Possible issues/failures:
This section applies only to StereoAudioRecorder:
Do you know "RecordRTC" fails recording audio because following conditions fails:
- Sample rate and channel configuration must be the same for input and output sides on Windows i.e. audio input/output devices mismatch
- Only the Default microphone device can be used for capturing.
- The requesting scheme is none of the following: http, https, chrome, extension's, or file (only works with
--allow-file-access-from-files
) - The browser cannot create/initialize the metadata database for the API under the profile directory
If you see this error message: Uncaught Error: SecurityError: DOM Exception 18
; it means that you're using HTTP
; whilst your webpage is loading worker file (i.e. audio-recorder.js
) from HTTPS
. Both files's (i.e. RecordRTC.js
and audio-recorder.js
) scheme MUST be same!
Web Audio APIs requirements
- If you're on Windows, you have to be running WinXP SP3, Windows Vista or better (will not work on Windows XP SP2 or earlier).
- On Windows, audio input hardware must be set to the same sample rate as audio output hardware.
- On Mac and Windows, the audio input device must be at least stereo (i.e. a mono/single-channel USB microphone WILL NOT work).
Why stereo?
If you explorer chromium code; you'll see that some APIs can only be successfully called for WAV
files with stereo
audio.
Stereo audio is only supported for WAV files.
RecordRTC is unable to record "mono" audio on chrome; however it seems that we can covert channels from "stereo" to "mono" using WebAudio API, though. MediaRecorder API's encoder only support 48k/16k mono audio channel (on Firefox Nightly).
Credits
- Recorderjs for audio recording
- whammy for video recording
- jsGif for gif recording
Spec & Reference
- Web Audio API
- MediaRecorder
- Canvas2D
- MediaStream Recording
- Media Capture and Streams
The domain www.RecordRTC.org is open-sourced here:
License
RecordRTC.js is released under MIT licence . Copyright (c) Muaz Khan.