Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 573
Ravi Kundu Avatar asked Mar 12 '26 02:03

Ravi Kundu


1 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.

like image 93
RReverser Avatar answered Mar 14 '26 15:03

RReverser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!