I replaced FFmpeg.wasm with WebCodecs in my browser video tools. Compression went from 97 s to 5.6 s
I run DashUtils , a site with 392 free file tools: image and PDF converters, a video compressor, an MP3 cutter and so on. The rule for every tool is simple. Nothing gets uploaded; the work happens in your browser. Until last week, every video and audio tool ran on FFmpeg.wasm. It handles every format you can think of, but it has costs: A 31 MB engine (about 10 MB compressed) has to download…
I recently migrated from using FFmpeg.wasm to WebCodecs in my browser video tools. The results were impressive: compression time dropped from 97 seconds to just 5.6 seconds. This change was motivated by a disappointing experience with an MP4-to-GIF tool that took too long to convert. After making the switch using Mediabunny WebCodecs, I discovered several factors contributing to the initial slow performance with FFmpeg.wasm.
Firstly, FFmpeg.wasm required a large engine (31 MB) and had issues with multi-threading and hardware acceleration. Secondly, progress updates caused significant page re-rendering during conversion. Thirdly, browser encoders had a bitrate floor that limited compression efficiency. Fourthly, reading pixels back from the GPU and fifthly, bitrate settings often led to unnecessary re-encoding.
By addressing these issues, I was able to significantly improve the performance of my video compression tools. Now, converting a 20-second 1080p clip takes just 5.6 seconds, and a 60-second 1080p clip is reduced to 21 seconds. These improvements were achieved by detecting codec support, using FFmpeg.wasm as a fallback for unsupported formats, throttling progress updates, and optimizing the way audio and video are processed.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.