@strangeape/ffmpeg-audio-wasm
v0.1.1
Published
Audio-only FFmpeg compiled to WebAssembly. No native binaries, no postinstall scripts, works everywhere Node runs.
Downloads
107
Readme
@strangeape/ffmpeg-audio-wasm
Audio-only FFmpeg compiled to WebAssembly. No native binaries, no postinstall scripts, works everywhere Node runs.
1.4MB WASM, single-threaded, no SharedArrayBuffer required.
Supported codecs
| | Encode | Decode | |---|--------|--------| | AAC | yes | yes | | MP3 | | yes | | Vorbis | | yes | | Opus | | yes | | FLAC | | yes | | PCM (various) | yes | yes |
Usage
import { createFFmpegAudio } from '@strangeape/ffmpeg-audio-wasm';
const ffmpeg = await createFFmpegAudio();
// Write input file to virtual FS
ffmpeg.writeFile('/input.wav', wavBuffer);
// Run ffmpeg command
const code = await ffmpeg.exec(['-y', '-i', '/input.wav', '-c:a', 'aac', '-q:a', '0.4', '/output.m4a']);
// Read output
const result = ffmpeg.readFile('/output.m4a');Each createFFmpegAudio() call creates a fresh WASM instance to avoid state issues between runs.
Building the WASM from source
Requires Docker.
bash build/build.shBuilt from FFmpeg 4.4.5 with Emscripten 3.1.50.
