The MediaRecorder()
constructor creates a new MediaRecorder
object that will record a specified MediaStream
.
The object can optionally be configured to record using a specific media container (file type), and, further, can specify the exact codec and codec configuration(s) to use by specifying the codecs
parameter.
new MediaRecorder(stream)
new MediaRecorder(stream, options)
This example shows how to create a media recorder for a specified stream, whose audio bit rate is set to 128 Kbit/sec and whose video bit rate is set to 2.5 Mbit/sec. The recorded media data will be stored in an MP4 wrapper (so if you gather the chunks of media data and save them to disk, they will be in an MP4 file).
if (navigator.mediaDevices.getUserMedia) {
const constraints = { audio: true, video: true };
const chunks = [];
const onSuccess = (stream) => {
const options = {
audioBitsPerSecond: 128000,
videoBitsPerSecond: 2500000,
mimeType: "video/mp4",
};
const mediaRecorder = new MediaRecorder(stream, options);
m = mediaRecorder;
};
}