Encode directly to H264 and ouput as an MP4 in node or on the web with WebAssembly! Works with the HTML5 Canvas :)
npm install h264-mp4-encoder
const HME = ;
Dynamic Import / Webpack:
;// To only import the type in TypeScript:;
You can also use
const encoder = await HME;
Use with Webpack
When using this library with Webpack to package onto a browser environment it will report an error because it cannot resolve "fs" which is used by Emscripten's node implementation. To fix this add this to your
/** Construct the H264MP4Encoder. Waits for the WASM to complete loading before returning. */;
How does it work?
This library brings together the public domain minih264 H264 encoder, as well as the MPL 1.1 licenced libmp4v2 to write the H264 NAL unit data into an MP4 file. Both of these are compiled in Emscripten within a Docker image and Webpacked to create easily importable modules. This repo uses submodules that are forks of those two libraries with changes for Emscripten (and to comply with the MPL 1.1 license).
Where is the WebAssembly?
To make packaging considerably easier, I built with Emscripten's
locateFile within the Emscripten Module object.
Building on Ubuntu
You must have docker installed, however all other depdendencies for building for node/web are within the Docker container).
To run the C++ code natively (not using Emscripten) you must have cmake and a compiler:
git submodule update --init --recursivemkdir buildcd buildcmake ..cmake --build --parallel .