Getting error "WebAssembly.Memory(): could not allocate memory" when running ffmpeg.wasm on android chrome browser

Viewed 1710

Error in detail:

WebAssembly.Memory(): could not allocate memory
at https://*******/ffmpeg-core.js:22:82
at https://*******/ffmpeg.min.js:1:6506
at f (https://*******/ffmpeg.min.js:1:11322)
at Generator._invoke (https://*******/ffmpeg.min.js:1:11110)
at Generator.next (https://*******/ffmpeg.min.js:1:11747)
at i (https://*******/ffmpeg.min.js:1:4295)
at c (https://*******/ffmpeg.min.js:1:4498)

Code for ffmpeg:

const downloadWithFFMPEG = async () =>{
  const sourceBuffer = await fetch(recordingURL).then(r => r.arrayBuffer());
  await ffmpeg.load();
  await ffmpeg.FS(
    "writeFile",
    "input.webm",
    new Uint8Array(sourceBuffer, 0, sourceBuffer.byteLength)
  );
  await ffmpeg.run("-i", "input.webm", "-c", "copy", "output.mp4")
  const output = ffmpeg.FS("readFile", "output.mp4");
  var link = document.createElement('a')
  link.href = URL.createObjectURL(new Blob([output.buffer], { type: 'video/mp4;codecs=H264' }));
  link.download = this.data;
  link.click();
  recording = false;
}

Brief about problem: The error only comes for android chrome browser. The same code works fine on pc/laptop chrome. Have also enabled Webassembly-thread on chrome://flags for android browser as someone suggested me to do it but still same error. Can someone help me?

2 Answers

You're likely getting this error because there is literally not enough memory on the device.

It's a common issue with Wasm applications (or generally any large apps), because mobile devices are much more constrained in terms of hardware - in this case RAM - than desktop.

It might be a chrome bug. I had same issue on my laptop chrome but when I switched to another browser(Microsoft edge) it worked fine. Usually the browser should clear the memory but unfortunately, it is taking time. You may want to try another browser and see if it works.

Related