muaz-khan / RecordRTC

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.
https://www.webrtc-experiment.com/RecordRTC/
MIT License
6.49k stars 1.75k forks source link

"Data cannot be cloned, out of memory." Error for long audio recordings #763

Open omkarv opened 2 years ago

omkarv commented 2 years ago

Thanks for working on this handy library. We've found it really useful and for the most part it has fulfilled its expectations.

Unfortunately, when recording longer durations of audio (say 30-60minutes), we occasionally observe an Out Of Memory error, which results in the entire audio recording failing to save. We don't encounter this issue for recording audio of shorter durations. Here is the error thrown for longer audio durations:

Failed to execute 'postMessage' on 'Worker': Data cannot be cloned, out of memory.

I suspect this occurs, because this library relies on Windows.postMessage to send the binary audio data to a Web Worker, and this API has a limitation on the size of the payload. The payload in my apps case is particularly large because we use the .wav audio format (which is a requirement for us).

Here is how I initialize the handler:

new RecordRTCPromisesHandler(
        this.localStream,
        {
          'audio',
          mimeType: WAV_AUDIO_MIME_TYPE,
          recorderType: StereoAudioRecorder,
          disableLogs: false
        }
      );

Can you suggest any workarounds to this issue? I've tried a solution of segmenting audio into smaller chunks to avoid the OOM error, but this feels like a hack and creates too many files. Thanks