Join us on Discord!
ffmpeg.wasm is a pure Webassembly/Javascript port of FFmpeg. It allows recording, converting and streaming video and audio directly within browsers.
AVI to MP4 Demo
Try it: https://ffmpegwasm.netlify.app
Check the next steps of ffmpeg.wasm HERE
Installation node Since
we are using experimental functions, you need to add flags to run in Node.js
Browser
Or, using an in-browser script tag (only works in some browsers, see list below):
SharedArrayBuffer is only available for isolated cross-origin pages. Therefore, you must host your own server with the headers Cross-Origin-Embedder-Policy: require-corp and Cross-Origin-Opener-Policy: same-origin to use ffmpeg.wasm.
Only browsers with SharedArrayBuffer support
can use ffmpeg.wasm, you can check HERE for the full list.
Using
ffmpeg.wasm provides easy-to-use APIs, to
transcode a video you only need a few lines of code:
Use another version of ffmpeg.wasm-core /@ffmpeg/core For each version of
ffmpeg.wasm
, there is a default version of @ffmpeg/core
(you can find it in devDependencies de package.json), but sometimes you may need to use a newer version of @ffmpeg/core to use the latest/experimental features.
Node
Simply install the specific version you need:
Or use your own version
with custom path
Browser
Note that for webworkers and nodejs support, this will default to a local path, so you’ll try to search for ‘static/js/ffmpeg.core.js’ locally, often resulting in a local resource error. If you want to use a major version hosted on your own domain, you can refer to it relatively like this
:
To view the list of available versions and their changelog, verify: https://github.com/ffmpegwasm/ffmpeg.wasm-core/releases
Use single-threaded version
Multithreading
Multithreading must be configured by external libraries, only the following libraries now support it:
x264
Run it in multithreading mode by default, no need to pass any arguments.
libvpx/webm
You need to pass -row-mt 1, but you can only use one thread to help, it can speed up about 30%
API Documentation
- Supported external libraries
Frequently Asked Questions
What is the license
for ffmpeg.wasm?
There are two components inside ffmpeg.wasm:
@ffmpeg/ffmpeg (https://github.com/ffmpegwasm/ffmpeg.wasm) @ffmpeg/core (
- https://github.com/ffmpegwasm/ffmpeg.wasm-core) @ffmpeg/core
contains WebAssembly code that is extracted from the original FFmpeg C code with minor modifications, but generally follows the same licenses as FFmpeg and its external libraries (as each external library can have its own license).
@ffmpeg/ffmpeg contains a kind of container to handle the complexity of loading the kernel and calling low-level APIs. It is a small code base and licensed under MIT.
Can I use ffmpeg.wasm in Firefox?
Yes, but only for Firefox 79+ with the proper header on both the client and server, visit https://ffmpegwasm.netlify.app to test if your Firefox works.
For more details: #106
What is the maximum input file size?
2 GB, which is a strict limit in WebAssembly. It could become 4GB in the future.
How can I build my own ffmpeg.wasm?
In fact, it’s ffmpeg.wasm-core that most people would like to build.
To build on your own, you can check build.sh within https://github.com/ffmpegwasm/ffmpeg.wasm-core repository.
You can also check out this series of posts to learn more fundamental concepts:
- https://jeromewu.github.io/build-ffmpeg-webassembly-version-part-1-preparation/
- https://jeromewu.github.io/build-ffmpeg-webassembly-version-part-2-compile-with-emscripten/
- https://jeromewu.github.io/build-ffmpeg-webassembly-version-part-3-v0.1/
- https://jeromewu.github.io/build-ffmpeg-webassembly-version-part-4-v0.2/
Why doesn’t it work in my on-premises environment?
When calling ffmpeg.load(), by default it looks for http://localhost:3000/node_modules/@ffmpeg/core/dist/ to download essential files (ffmpeg-core.js, ffmpeg-core.wasm, ffmpeg-core.worker.js). You need to make sure that you have those files served there.
If you have those files serving in another location, you can rewrite the default behavior by calling createFFmpeg():