Skip to content

JorenSix/ffmpeg.audio.wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An audio focused ffmpeg build for the web

FFmpeg claims to be ‘a complete, cross-platform solution to record, convert and stream audio and video’. WebAssembly makes it possible to use ffmpeg in the browser or in node.js. That means that video and audio transcoding in almost any format can be done in the browser. This repository provides a audio focused WebAssembly build of ffmpeg together with some examples on how it can be used.

Transcode audio in the browser
Fig: Demo of transcoding in the browser with ffmpeg.audio.wasm.

Live demos

  • Audio transcoding: transcode from about any format to wav/mp3/opus. The transcoder also supports extracting the first audio stream in video container formats (like mp4, mkv, avi, mov,…).
  • High quality pitch-shifting and time-stretching: modify speed or pitch of your audio files independently.
  • Basic media info: Extracts info on your media files. Details on multi-media encoding, sample-rates, resolutions and so forth can be found.

Contents of this repository

This repository contains:

  • build two builds of ffmpeg.wasm. One is audio focused and another (larger ffmpeg.wasm build) which also contains video encoders.
  • examples The examples show how to use ffmpeg.audio.wasm.
  • js simple wrapper code to call into the WebAssembly module.

Why ffmpeg.audio.wasm?

To allow processing of audio files of any format in the browsers a WebAssembly ffmpeg is very helpful. There are a few WebAssembly builds of ffmpeg but they also include video encoders. Concretely the complete ffmpeg.wasm binary weighs about 20MB while the audio focused one weighs only 5MB (and can be gzipped to 3MB). Since this needs to be downloaded by every user this adds up. In my view, audio transcoding is also better suited as a browser workload compared to video transcoding since the time it takes is measured in seconds not in minutes (as is the case for video transcoding).

ffmpeg.audio.wasm includes the Rubber Band Library for high quality audio pitch-shifting and time-stretching.

The Javascript wrapper is more simple than the one provided by ffmpeg.wasm. It is a single Javascript file that can be used from both node and the browser.

More about the rationale behind "an audio focused ffmpeg build for the web ":https://0110.be/posts/An_audio_focused_ffmpeg_build_for_the_web can be found on my blog.

Limitations

To use WebAssembly modules in browsers CORS needs to be configured correctly on your web server. A working configuration sets these headers: ‘Cross-Origin-Embedder-Policy’ => ‘require-corp’ and ‘Cross-Origin-Opener-Policy’ => ‘same-origin’.

Credits & Licenses

The ffmpeg.wasm binary contains code transpiled from the ffmpeg project and several other modules. Please respect licenses of the various components and, if needed, buy a commercial license for using Rubber Band.

  • FFmpeg ‘a complete, cross-platform solution to record, convert and stream audio and video’ LGPL with GPL licensed parts.
  • ffmpeg.wasm-core a WebAssembly build of ffmpeg aimed to provide both video and audio encoding.
  • ffmpeg.wasm a set of scripts to use the ffmpeg.wasm-core in the browser and in node .
  • ffmpeg-wasm a more recent WebAssembly build of ffmpeg, again aimed to provide both video and audio encoding. The build scripts are more up-to-date and work now (February 2022). I have included the build scripts of that project here, for reference.
  • rubberband Rubber Band Library is a high quality software library for audio time-stretching and pitch-shifting. It permits you to change the tempo and pitch of an audio stream or recording dynamically and independently of one another. The Rubber Band Library is compiled into ffmpeg.audio.wasm. Please respect the
  • Opus ‘Opus is a totally open, royalty-free, highly versatile audio codec’. BSD licensed.
  • Lame LAME is a high quality MPEG Audio Layer III (MP3) encoder licensed under the LGPL.

ffmpeg.audio.wasm by Joren Six at IPEM, Ghent University.

About

An audio focused ffmpeg build for the web.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published