go-ffmpreg
empregge- sorry, uh... embedded ffmpeg WASM binary with a small Go library wrapper, using wazero WebAssembly runtime
this provides a singular binary capable of calling into ffmpeg
or ffprobe
(switches on argv0, like busybox)
ffmpeg version: n5.1.6
(the latest version not reliant on pthreads)
yes, you will have to publicly acknowledge the fact you used ffmpreg
as this is GPL
ffmpeg is built with GPLv3 code enabled and with the following external libraries:
for a list of what ffmpeg supports (and what it requires external libaries for) see: https://www.ffmpeg.org/general.html#External-libraries
the resulting binary is passed through many wasm-opt
optimization passes focusing on a balance of speed and size, such that the embedded binary is ~24MB (uncompressed, before in this is gzip compressed to ~8MB)
usage
see cmd/{ffmpeg,ffprobe,ffmpreg}
for examples
ffmpeg may need access to /dev/
and /tmp/
depending on what you are doing, please factor this in when setting up directory mounts
note since wazero runtime is not aware of a "working directory", all paths passed must be absolute relative to filesystem mount
build
podman build --file=build/build.dockerfile
alternatively with far more optimization passes
podman build --file=build/build.dockerfile --build-arg RELEASE=yes
then copy /build/{ffmpeg,ffprobe}
from resulting image
the build system itself is separated into scripts found under build/
, which are called by build/build.dockerfile
. to build ffmpeg with a new external library add a new script for it under build/
that sources build/environ
and outputs library header, archive and pkg-config (if any) to /vendor
in the build image
hacking
the WebAssembly binary (once uncompressed) under embed/
should be useable under any WebAssembly runtime that supports the following: simd, bulk-memory, nontrapping-float-to-int, mutable-globals, sign-ext, reference-types
on top of the above runtime features, this binary expects exported host functions as defined in the wasi snapshot preview 1, and additionally, setjmp, longjmp
future
-
more tests (in particular: ffprobe, 3rd-party libs)
-
update ffmpeg to n7.x.x
(requires wazero to fully support wasm threads proposal)
-
tidy up the ffmpeg patch, in particular add code comments
-
build-tagged output with differing 3rd-party library options?
-
build with libjxl for JPEG XL, may rely on threads
-
build with libx265 for HEVC, may rely on threads
-
some form of AV1 encode / decode
further thanks
viviridian
for showing me how to modify the ffmpeg build-system to support a new binary!