$ show openclaw/ffmpeg-wasm
This repository provides a lightweight, LGPL-friendly FFmpeg and FFprobe compiled to WebAssembly for Node.js (and browser via a dedicated worker). It wraps the wasm modules with predictable CLI and TypeScript APIs for media probing, audio extraction, video resizing, thumbnail generation, raw frame output, stream-copy clips, and segmentation. The architecture consists of a TypeScript library that spawns a child process running an Emscripten-generated module, with both buffered (runFfmpeg, runFfprobe) and streaming (execFfmpeg, execFfprobe) APIs. A browser-only ffmpac worker enables the same operations in the included media workbench playground. The build system is sophisticated: it fetches FFmpeg, LAME, and libvpx source, compiles them statically with Emscripten, and produces both Node and browser wasm bundles. The codebase is well-structured, with strict linting, comprehensive unit and E2E tests, and a clear separation of concerns. It is actively maintained and demonstrates strong engineering practices.
The LLM identified 4 files worth highlighting for reuse:
A reusable runner for Emscripten-generated modules in Node.js. It sets blocking mode on stdout/stderr for NODERAWFS compatibility, handles EPIPE errors gracefully during write operations, and correctly captures exit status from Emscripten's onExit callback or thrown ExitStatus. This pattern can be extracted and reused for any Emscripten module that needs reliable I/O in a Node.js child process.
A self-contained utility for forwarding host signals (SIGHUP, SIGINT, SIGTERM) to a child process with a configurable forced kill timeout. It returns a cleanup function that cancels pending exits. This pattern is reusable in any CLI tool that spawns child processes and needs to propagate termination signals while avoiding orphaned processes.
A parameterized build script that fetches FFmpeg, LAME, and libvpx source, configures them with Emscripten for wasm cross-compilation, and produces both Node and browser wasm bundles. It demonstrates non-obvious skill in FFmpeg configure flags, static linking, and pthread support. The script is well-structured and could be adapted for other Emscripten-based FFmpeg builds.
A browser Web Worker that loads Emscripten-generated FFmpeg/FFprobe modules, writes input files to the virtual filesystem, runs the tool with progress reporting, and returns output as ArrayBuffer. It handles timeouts, progress parsing from stderr, and cleanup. This pattern is reusable for any browser-based wasm tool that needs progress feedback and file I/O.