ffmpeg.wasm icon indicating copy to clipboard operation
ffmpeg.wasm copied to clipboard

Support For IOS Mobile

Open haroonabp opened this issue 3 years ago • 20 comments

Describe the bug Unhandled Promise Rejection: RangeError: Out of Memory. And then the line of code that the error points to is "await ffmpeg.load();".

To Reproduce Steps to reproduce the behavior:

  1. Try to use FFmpeg on Safari 15.2 or a Chrome browser on an IOS mobile device.

Expected behavior There will not be memory crashes.

Screenshots N/A

Smartphone (please complete the following information):

  • Device: Iphone 12
  • OS: IOS 15.2
  • Browser: Safari and Chrome App
  • Version: 15.2 for Safari and latest Chrome version.

Additional context Add any other context about the problem here.

haroonabp avatar Jan 11 '22 18:01 haroonabp

As has been already noted here - a couple of more findings from my side:

  1. It is actually await this.ffmpeg.load(); that is causing the exception. So it's not about the audio file size or exceeding the memory with await this.ffmpeg.run(); call.
  2. Likely, this happens because of the ffmpeg wasm size (currently 23.7 MB), which is apparently too big for a mobile browser. This is only my speculation, though. Please, correct me if I am wrong.
  3. Other WASM libs (coincidentally much smaller, under 1 MB) cause me no troubles in mobile browsers.
  4. Again, only my speculation, but perhaps streaming the WASM would make things more efficient? https://developers.google.com/web/updates/2018/04/loading-wasm

IvanSivak avatar Jan 11 '22 22:01 IvanSivak

errorlog This is the error log that I get on my iPhone. Usually after "ffmpeg-core.js script loaded" I will get "ffmpeg-core loaded" which I think is referring to the ffmpeg-core.wasm file. So I think it is the ffmpeg wasm size that may be causing the issue.

haroonabp avatar Jan 17 '22 15:01 haroonabp

I'm seeing this same issue on iPad on both iPad OS 15.0 and 15.3 (which is the most recent). I'd love to see this resolved.

stemcoding avatar Feb 04 '22 23:02 stemcoding

same here with iPhone13 iOS 15.2.1

X7md avatar Feb 19 '22 09:02 X7md

same here with iPhone11 iOS 15.3.1

merri-ment avatar Feb 21 '22 03:02 merri-ment

Same here

introvert avatar Feb 25 '22 01:02 introvert

I'm facing the same issue. Is there any workaround for this?

MMouta avatar Mar 01 '22 21:03 MMouta

Same here any workarounds so far?

absurdprofit avatar Apr 04 '22 21:04 absurdprofit

+1 on iPhone 13 Pro Max on iOS 15.4.1

bilinkis avatar Apr 06 '22 14:04 bilinkis

Same here. xcode ios Simulator 15.4 iPhone 13

new WebAssembly.Memory() makes Out of Memory error. INITIAL_MEMORY is 2GB, right?

in case of ammo.js, INITIAL_MEMORY seems to be 64MB.

novogrammer avatar Apr 21 '22 03:04 novogrammer

I built custom core files with Docker CE on wsl2 Ubuntu 20.04. And, It works fine with ios Safari.

see also https://github.com/ffmpegwasm/ffmpeg.wasm/issues/267

setup

$ git clone https://github.com/ffmpegwasm/ffmpeg.wasm-core
$ cd ffmpeg.wasm-core
$ git checkout b59fb55619
$ git submodule update --init --recursive

edit wasm/build-scripts/build-ffmpeg.sh

-  -s INITIAL_MEMORY=2146435072                  # 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB
+  -s INITIAL_MEMORY=1073741824                  # 1GB

or

-  -s INITIAL_MEMORY=2146435072                  # 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB
+  -s INITIAL_MEMORY=33554432                    # 32MB
+  -s MAXIMUM_MEMORY=1073741824                  # 1GB
+  -s ALLOW_MEMORY_GROWTH=1

edit wasm/build-scripts/install-deps.sh

-for cmd in autoconf automake libtool pkg-config
+for cmd in autoconf automake libtool pkg-config ragel

and run

$ bash build-with-docker.sh

I wrote simple WebAssembly.Memory test for test memory allocation. https://gist.github.com/novogrammer/cf4752f447c54e4b76fffe5e737a3064

ios Simulator screenshot below. screenshot_webassembly_memory

novogrammer avatar May 09 '22 19:05 novogrammer

I built custom core files with Docker CE on wsl2 Ubuntu 20.04.

And, It works fine with ios Safari.

see also https://github.com/ffmpegwasm/ffmpeg.wasm/issues/267

setup


$ git clone https://github.com/ffmpegwasm/ffmpeg.wasm-core

$ cd ffmpeg.wasm-core

$ git checkout b59fb55619

$ git submodule update --init --recursive

edit wasm/build-scripts/build-ffmpeg.sh


-  -s INITIAL_MEMORY=2146435072                  # 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB

+  -s INITIAL_MEMORY=1073741824                  # 1GB

or


-  -s INITIAL_MEMORY=2146435072                  # 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB

+  -s INITIAL_MEMORY=33554432                    # 32MB

+  -s MAXIMUM_MEMORY=1073741824                  # 1GB

+  -s ALLOW_MEMORY_GROWTH=1

edit wasm/build-scripts/install-deps.sh


-for cmd in autoconf automake libtool pkg-config

+for cmd in autoconf automake libtool pkg-config ragel

and run


$ bash build-with-docker.sh

I wrote simple WebAssembly.Memory test for test memory allocation.

https://gist.github.com/novogrammer/cf4752f447c54e4b76fffe5e737a3064

ios Simulator screenshot below.

screenshot_webassembly_memory

You're a godsend

absurdprofit avatar May 09 '22 19:05 absurdprofit

I built custom core files with Docker CE on wsl2 Ubuntu 20.04.

And, It works fine with ios Safari.

see also https://github.com/ffmpegwasm/ffmpeg.wasm/issues/267

setup


$ git clone https://github.com/ffmpegwasm/ffmpeg.wasm-core

$ cd ffmpeg.wasm-core

$ git checkout b59fb55619

$ git submodule update --init --recursive

edit wasm/build-scripts/build-ffmpeg.sh


-  -s INITIAL_MEMORY=2146435072                  # 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB

+  -s INITIAL_MEMORY=1073741824                  # 1GB

or


-  -s INITIAL_MEMORY=2146435072                  # 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB

+  -s INITIAL_MEMORY=33554432                    # 32MB

+  -s MAXIMUM_MEMORY=1073741824                  # 1GB

+  -s ALLOW_MEMORY_GROWTH=1

edit wasm/build-scripts/install-deps.sh


-for cmd in autoconf automake libtool pkg-config

+for cmd in autoconf automake libtool pkg-config ragel

and run


$ bash build-with-docker.sh

I wrote simple WebAssembly.Memory test for test memory allocation.

https://gist.github.com/novogrammer/cf4752f447c54e4b76fffe5e737a3064

ios Simulator screenshot below.

screenshot_webassembly_memory

Is there any option where we can split the resulting binary by its component libraries? So only the libraries that will be used for an operation get lazy loaded.

absurdprofit avatar May 10 '22 14:05 absurdprofit

@nxtexe Add a script tag like this, if you want. https://gist.github.com/james2doyle/28a59f8692cec6f334773007b31a1523

novogrammer avatar May 11 '22 03:05 novogrammer

@nxtexe

Add a script tag like this, if you want.

https://gist.github.com/james2doyle/28a59f8692cec6f334773007b31a1523

This wouldn't work much for me since I use ffmpeg in a web worker. But what I mean more specifically is lazy loading the libraries ffmpeg relies on to do certain conversions for example libx264. This way only when this library is specified only its binary would be loaded instead of the entire wasm binary containing all the libraries. Since as we know the full binary is around 25MB this would be very beneficial for lower end devices.

absurdprofit avatar May 11 '22 03:05 absurdprofit

@nxtexe

This wouldn't work much for me since I use ffmpeg in a web worker. But what I mean more specifically is lazy loading the libraries ffmpeg relies on to do certain conversions for example libx264. This way only when this library is specified only its binary would be loaded instead of the entire wasm binary containing all the libraries. Since as we know the full binary is around 25MB this would be very beneficial for lower end devices.

I feel you. I want to reduce the binary size.

I am not familiar to Emscripten and FFmpeg. But, I think dynamic linking is generally a difficult technique.

Based on this static linked program, I think you need to create some custom binaries and switch between them as needed.

I think it's around here. wasm/build-scripts/configure-ffmpeg.sh wasm/build-scripts/build-ffmpeg.sh

novogrammer avatar May 11 '22 04:05 novogrammer

Hello @novogrammer! Thanks for taking the time to create this! I'm currently using FFMPEG WASM to convert files to MP4 using Node.js. I was wondering if you have an endpoint where your custom build is live and where it can be used from. Thanks!

bilinkis avatar May 19 '22 13:05 bilinkis

Hello @bilinkis !

My study project is here. https://github.com/ningen-inc/hello-ffmpeg-wasm

$ npm install
$ npm start

and open http://localhost:3000/ to try this.

novogrammer avatar May 19 '22 14:05 novogrammer

Looks like it's working on iOS! Marvellous work, thank you so much for taking the time!

bilinkis avatar May 19 '22 16:05 bilinkis

I was able to get my converter to work on my iPad using the new ffmpeg-core.js Thanks for doing that! I would be great to get the changes into a new stable release but I'm happy nonetheless.

stemcoding avatar May 20 '22 02:05 stemcoding