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.
#enable-webassembly-simd
in about:flags)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).
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:
transferToImageBitmap()
then into a RGB buffer with WebGLh264-mp4-encoder
which is ~1.7MB.It's still pretty slow compared to native, some ways it could be faster/cleaner:
minih264
library is indeed taking advantage of SIMD (lots of NEON code that doesn't compile there)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.
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.
MIT, see LICENSE.md for details.