Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling into WebAssembly #43

Open
FluorescentHallucinogen opened this issue May 16, 2016 · 4 comments · May be fixed by #63
Open

Compiling into WebAssembly #43

FluorescentHallucinogen opened this issue May 16, 2016 · 4 comments · May be fixed by #63

Comments

@FluorescentHallucinogen

What about compiling videoconverter.js to WebAssembly?

There are experimental native WebAssembly implementations for Google Chrome, Mozilla Firefox, Microsoft Edge and Apple Safari.

@amilajack
Copy link

amilajack commented Jul 15, 2016

@bgrins this would definitely be a welcome feature! It would allow for significant performance gains.

jonasof added a commit to jonasof/videoconverter.js that referenced this issue May 2, 2017
@jonasof jonasof linked a pull request May 2, 2017 that will close this issue
@jonasof
Copy link

jonasof commented May 2, 2017

Hello @FluorescentHallucinogen and @amilajack,

I have compiled videoconverter.js to WebAssembly, see pull request #63.

How

Just change the bellow emcc line from "build_lgpl.sh" and all runs ok. Emscripten does the job.

Before:
emcc -s OUTLINING_LIMIT=100000 -v -s TOTAL_MEMORY=33554432 -O2 ffmpeg.bc -o ../ffmpeg.js --pre-js ../ffmpeg_pre.js --post-js ../ffmpeg_post.js

After:
emcc -v -s TOTAL_MEMORY=33554432 -Os ffmpeg.bc -o ../ffmpeg.js --pre-js ../ffmpeg_pre.js --post-js ../ffmpeg_post.js -s WASM=1 -s "BINARYEN_METHOD='native-wasm'" -s ALLOW_MEMORY_GROWTH=1

Add also "cp ffmpeg.wasm* ../demo"

I removed OUTLINING_LIMIT and add ALLOW_MEMORY_GROWTH=1 to avoid memory table errors.

Demo

See https://jonasof.github.io/videoconverter.js-wasm-demo/ - in WebAssembly version remember to wait disappear the spinner loading icon on right of "run command" button before run any command.

Results

The filesizes are:

ASM.js WebAssembly
ffmpeg.js 20.8 MB 0.2MB
ff.js.mem 3MB
ffmpeg.wasm 12MB
total 23.8MB 12.2MB

I'm using Firefox 52.1.0 ESR.

The small tasks like image manipulation and the benchmark options gave me poor results because in each iteration (there are around 5 for each benchmark) the browser download and parse the full ffmpeg.wasm file (12 MB), while in asm.js the browser only downloads the ffmpeg.js.mem (3MB). This clearly give more advantage to asm.js.

But when running a longer single test - "Video to mp4", WebAssembly performs 3 times more faster than asm.js:

ASM.js WebAssembly
"Video to mp4" 118264ms 25171ms

@timaschew
Copy link

timaschew commented Jul 15, 2018

@jonasof hey do you know how I can use the libx264 codec?

Currently if I try to do that I'm getting this error (even for all_codec version):

Worker has received command
Received command: -t 3 -i input.webm -vf showinfo -strict -2 -c:v libx264 output.mp4.  Processing with 268435456 bits.
ffmpeg version 3.1.3 Copyright (c) 2000-2016 the FFmpeg developers
  built with emcc (Emscripten gcc/clang-like replacement) 1.37.10 (commit 79697257a5378666a9fa0e7215de1e61673dfe8d)
  configuration: --cc=emcc --prefix=/projetos/videoconverter.js/build/ffmpeg/../dist --extra-cflags='-I/projetos/videoconverter.js/build/ffmpeg/../dist/include -v' --enable-cross-compile --target-os=none --arch=x86_32 --cpu=generic --disable-ffplay --disable-ffprobe --disable-ffserver --disable-asm --disable-doc --disable-devices --disable-pthreads --disable-w32threads --disable-network --disable-hwaccels --disable-parsers --disable-bsfs --disable-debug --disable-protocols --disable-indevs --disable-outdevs --enable-protocol=file --enable-libvpx --enable-gpl --extra-libs='/projetos/videoconverter.js/build/ffmpeg/../dist/lib/libx264.a /projetos/videoconverter.js/build/ffmpeg/../dist/lib/libvpx.a'
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
[h264 @ 0xf88d90] Warning: not compiled with thread support, using thread emulation
[aac @ 0xf8c800] Warning: not compiled with thread support, using thread emulation
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.webm':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:00:53.68, start: 0.000000, bitrate: 826 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 691 kb/s, 25.04 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Unknown encoder 'libx264'
Finished processing (took 6160ms)

Your version of asm.js is also not working, but the original page on http://bgrins.github.io/videoconverter.js/demo/ works with that codec.

@jonasof
Copy link

jonasof commented Jul 15, 2018

No @timaschew, I have tried to resolve that issue months ago but I had no success - jonasof/videoconverter.js-wasm-demo#2. Since I was more interested in testing webassembly than the usage of ffmpeg specifically I haven't put much efforts in resolving that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants