Large size issue in MediaRecorder safari

561 Views Asked by At

While using MediaRecorder in Safari the size of video recorder is almost 15x greater than in Chrome for the same amount of time. Is there any way where we can reduce the final recorded size of the video

I tried changing pixel size of the video

    await navigator.mediaDevices.getUserMedia({
        video: {
            width: { exact: 320 },
            height: { exact: 240 }
        }, audio: true
    });

but still the size of the video is same

1

There are 1 best solutions below

0
On

The recording's file size is also determined by the audio and video bitrates, and Safari's default values for these are much higher than most other browsers.

You can set them to a fixed value by passing them in an object as a second parameter to the MediaRecorder's constructor call.

var rec = new MediaRecorder(mediaStream,
    {
        mimeType: <file mime type>,
        audioBitsPerSecond: <audio bit rate>,
        videoBitsPerSecond: <video bit rate>
    }
);

I found that values around 128,000 to 512,000 result in a decently small file size, but you might want to experiment to find ones that suit your needs.