I Picked libmedia, Then Shipped ffmpeg.wasm
A few days ago I wanted to add an all-in-one audio page to ShotEasy, my free browser toolbox where everything runs locally on your device. Convert, trim, change speed and pitch, normalize loudness, strip metadata — the usual small jobs people currently upload files to random websites for.
The obvious candidate for the engine was libmedia. I evaluated it seriously. Then I shipped the page on ffmpeg.wasm instead. This is the trade-off, written down while it's still fresh.
Why libmedia looked right
libmedia is a real multimedia framework in the browser, not a wrapper around one trick. Its AVTranscoder genuinely covers the audio scope I needed: MP3, OGG, AAC, FLAC and WAV outputs; AAC, MP3, Opus, Vorbis and FLAC codecs; and the resample / stretch-pitch pieces you need for sample-rate, speed and pitch work. At evaluation time (2026-11-30) it was at v1.4.0, actively pushed, with about 400 stars.
If the question had been "which library can do the most audio work in a browser," libmedia would have won.
That wasn't the question.
The two reasons I didn't bundle it
1. Licensing. libmedia is LGPL-3.0-or-later. ShotEasy is an MIT-licensed open-source site built from permissive pieces. LGPL obligations are manageable in many projects, but they are a real commitment to take on for one page of a toolbox — and "we'll sort out the license boundary later" is how small projects end up with a problem they can't undo. I didn't want the audio page to change the licensing posture of the whole site.
2. Integration weight. The package I'd need, @libmedia/avtranscoder, is about 3.0 MB unpacked and pulls in roughly a dozen @libmedia/* dependencies — one of them, @libmedia/cheap, is around 12 MB unpacked on its own. The per-codec WASM assets are wired through a custom getWasm mapping, and the demo flow is built around showSaveFilePicker. None of that is unreasonable for a framework. All of it is weight my existing, proven pipeline didn't have.
ShotEasy already runs ffmpeg.wasm for its video tools. Reusing it meant one engine to load, one failure mode to understand, and no new asset plumbing.
What I borrowed instead
Not bundling libmedia didn't mean ignoring it. Its capability model was the best checklist I found for what an audio page should actually do, so I borrowed the checklist:
- Opus as an output format, not just MP3/WAV
- Pitch shifting (±12 semitones), separate from speed
- Sample-rate and mono/stereo controls next to bitrate (32–320 kbps)
The shipped page covers convert/extract, trim, speed, pitch, volume, loudness normalization (−14/−16/−23 LUFS), fade in/out, reverse, loop, and metadata cleanup, outputting MP3, AAC, WAV, OGG, FLAC, M4A and Opus. Video files are accepted too, but only as a soundtrack source — output is always audio-only. It's live at shoteasy.fun/audio-tools.
The part that actually annoyed users: loading
ffmpeg.wasm has a UX trap: it reports progress during execution, but not while the core JS and WASM are downloading. So the loading bar sits still, and a still bar reads as "broken."
The fix was a small shared loader that prefetches the core files with a streaming reader and maps real bytes to a visible percentage — core JS across 2–12%, the WASM across 12–90%, core startup across 92–100% — with a direct-load fallback if prefetch fails. Both the video and audio tools now show a numeric percentage next to the bar. It sounds minor. In practice, "the number is moving" is the difference between waiting and leaving.
Verification, because "it built" is not "it works": the audio page shipped with its own test file, the full suite passed, and the final check was a real-browser run — a 3-second WAV in, a 71.7 KB MP3 out, download successful. That last step is the one I now refuse to skip for WASM tools; unit tests never catch a broken download path.
The lesson I'd keep
Picking a library is two decisions, not one: can it do the work, and what does adopting it commit me to. libmedia passed the first test easily and failed the second for this project — not because it's bad software, but because LGPL obligations plus a dozen-package asset pipeline were the wrong price for one page on a site that already had a working engine.
Borrowing its capability model got me most of the value at none of that cost. That's a trade I'll take again.
原文:https://www.a8q9.cn/en/article/i-picked-libmedia-then-shipped-ffmpeg-wasm-75e389.html