This uses ffmpeg to convert mp4, webm, vp8, vp9, theora, mpeg1 or mpeg2 videos to mp4.
Everything is handled client side. The video is never uploaded to the server.
Pthread support in emscripten is somewhat disabled by browsers right now because of spectre [1] [2]. So this demo first analyzes the video file, extracts its length and then encodes multiple chunks (2 on mobile, 4 on desktop) in paralell in different workers. In the last step, the file is assembled again by stuffing all encoded chunks files into a new container, without re-encoding.
The ffmpeg build is based on
ffmpeg.js.wasm
and optimized for speed (-O3
). Only the h264 encoder and a few
decoders are enabled, resulting in a file size of just 1.8mb (gzipped).
It works okay in Chrome, but it's still awfully slow. It barely
reaches 30fps on an Intel i7 for 720p video. Surprisingly the iPhone 10
isn't far behind. In Firefox/Win workers seem to crash without a trace
after a few seconds (filed under bug
#1592227) -
workarounded here, see the original test case
that exhibits the bug.
Use a very small/short video (or don't and get some coffee). Try this one if you don't have any suitable videos at hand.