mattdesl / mp4-wasm-encoder

https://mattdesl.github.io/mp4-wasm-encoder/
MIT License
73 stars 2 forks source link

mp4-wasm-encoder

:bulb: Update - Project Moved

See the mp4-h264 module which wraps most of this demo up as a ES module.

What follows below is early R&D / proof-of-concept.


Fast client-side MP4 encoding demo based on a fork of Trevor Sundberg's npm library. Currently only works in Chrome due to OffscreenCanvas.

[ Demo Link ]

A 5 second 1920x1080 60FPS MP4 takes about 7 seconds to encode with Chrome and SIMD enabled (may be faster/slower depending on your hardware).

How is this fast? (for a browser)

This is mostly based on Trevor Sundberg's work with h264-mp4-encoder (thanks!). Here, I've mostly just been exploring how to improve performance:

How it could be faster?

It's still pretty slow compared to native, some ways it could be faster/cleaner:

How can it work on FireFox, mobile phones, etc?

The h264-mp4-encoder already works on most browsers, this demo is just to see how more advanced browser features could make it faster: OffscreenCanvas, dynamic imports in a web worker, WASM, and SIMD.

Just Give me the WASM!

In the h264 folder is a drop-in WASM+JS files for SIMD and non-SIMD supported environments. These must be imported as an ES module, see ./encoder/main.js, but otherwise you can get it running without any dependencies or build tools.

Feel free to use the WASM for your own purposes, though this repo won't be maintained like a typical library, so you might rather use the original non-WASM version at h264-mp4-encoder library which will probably receive more frequent updates.

In future, I plan to wrap some of this R&D work in a more 'official' MP4+GIF encoder library that will receive regular updates.

License

MIT, see LICENSE.md for details.