Skip to content

SebastiaanYN/FFmpeg-WASI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FFmpeg-WASI

FFmpeg-WASI compiles FFmpeg to WASM. Unlike ffmpeg.wasm the WASM binary is standalone and required no JavaScript glue.

Clone

To get started you can clone the repository and its submodules.

git clone --recursive https://github.com/SebastiaanYN/FFmpeg-WASI.git

Build

Building the project requires several dependencies and steps to be executed. To make it easier to build the project a Dockerfile is provided to build ffmpeg.wasm and ffprobe.wasm.

DOCKER_BUILDKIT=1 docker build -t ffmpeg-wasi --output . .
# or
./build.sh

On Apple M1/M2 machines it might be necessary to set DOCKER_DEFAULT_PLATFORM=linux/amd64.

DOCKER_DEFAULT_PLATFORM=linux/amd64 DOCKER_BUILDKIT=1 docker build -t ffmpeg-wasi --output . .
# or
DOCKER_DEFAULT_PLATFORM=linux/amd64 ./build.sh

Examples

You can use any WASI compatible WASM runtime, like wasmtime and wasmer, to run the binary.

Generating a thumbnail from a video.

wasmtime --dir videos ffmpeg.wasm -- -i videos/video-1080p-60fps-2s.mp4 -ss 1 -vframes 1 videos/out.png

Converting from one video format to another.

wasmtime --dir videos ffmpeg.wasm -- -i videos/video-15s.avi -c:v libx264 videos/out.mp4

Encoders

Currently only zlib and x264 are included in the build, but adding more should be fairly straightforward.

Limitations

Some codecs require multiple iterations over the input/output (like mp4), which means you cannot pipe the input/output. Instead you need to write the file to disk so FFmpeg can read it from there. Depending on where you're running your code this may not be possible.

Additionally, WASI is still a very young technology so some FFmpeg features, like threading and networking, have to be disabled. In the future it might be possible to enable these features.

License

This project is licensed under MIT. Be aware that the licenses of FFmpeg and other dependencies may still apply.

About

FFmpeg compiled to WASM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published