摘要
使用c2w打包ffmpeg-cli到单个wasm二进制,实现ffmpeg可执行文件平台无关运行(Build Once,Run Anywhere)。
Abstract
Using c2w to package the ffmpeg-cli into a single wasm binary, achieving platform-independent execution of the ffmpeg executable (Build Once, Run Anywhere).
原理简介
c2w简介
[https://github.com/ktock/container2wasm]
[https://ktock.github.io/container2wasm-demo/]
Container to WASM converter
container2wasm is a container-to-wasm image converter that enables to run the container on WASM.
Converts a container to WASM with emulation by Bochs (for x86_64 containers) and TinyEMU (for riscv64 containers).
Runs on WASI runtimes (e.g. wasmtime, wamr, wasmer, wasmedge, wazero)
Runs on browser
x86_64 or riscv64 containers are recommended. Other platforms (e.g. arm64) also work (but slow).
This is an experimental software.
Demo page of containers on browser (debian,python,node,vim): https://ktock.github.io/container2wasm-demo/
wasmtime简介
[https://wasmtime.dev/]
A fast and secure runtime for WebAssembly
A Bytecode Alliance project
Fast. Wasmtime is built on the optimizing Cranelift code generator to quickly generate high-quality machine code either at runtime or ahead-of-time. Wasmtime is optimized for efficient instantiation, low-overhead calls between the embedder and wasm, and scalability of concurrent instances.
Secure. Wasmtime's development is strongly focused on correctness and security. Building on top of Rust's runtime safety guarantees, each Wasmtime feature goes through careful review and consideration via an RFC process. Once features are designed and implemented, they undergo 24/7 fuzzing donated by Google's OSS Fuzz. As features stabilize they become part of a release, and when things go wrong we have a well-defined security policy in place to quickly mitigate and patch any issues. We follow best practices for defense-in-depth and integrate protections and mitigations for issues like Spectre. Finally, we're working to push the state-of-the-art by collaborating with academic researchers to formally verify critical parts of Wasmtime and Cranelift.
Configurable. Wasmtime uses sensible defaults, but can also be configured to provide more fine-grained control over things like CPU and memory consumption. Whether you want to run Wasmtime in a tiny environment or on massive servers with many concurrent instances, we've got you covered.
WASI. Wasmtime supports a rich set of APIs for interacting with the host environment through the WASI standard.
Standards Compliant. Wasmtime passes the official WebAssembly test suite, implements the official C API of wasm, and implements future proposals to WebAssembly as well. Wasmtime developers are intimately engaged with the WebAssembly standards process all along the way too.
- wasmtime支持的宿主平台:
v25.0.1: Release Wasmtime 25.0.1 (#9306) Latest
File Name | Size | Last Modified |
---|---|---|
wasi_snapshot_preview1.command.wasm | 52.4 KB | 12 hours ago |
wasi_snapshot_preview1.proxy.wasm | 17 KB | 12 hours ago |
wasi_snapshot_preview1.reactor.wasm | 52.3 KB | 12 hours ago |
wasmtime-dev-aarch64-android-c-api.tar.xz | 13.5 MB | 12 hours ago |
wasmtime-dev-aarch64-android.tar.xz | 7.39 MB | 12 hours ago |
wasmtime-dev-aarch64-linux-c-api.tar.xz | 14.1 MB | 12 hours ago |
wasmtime-dev-aarch64-linux.tar.xz | 7.36 MB | 12 hours ago |
wasmtime-dev-aarch64-macos-c-api.tar.xz | 12.3 MB | 12 hours ago |
wasmtime-dev-aarch64-macos.tar.xz | 6.54 MB | 12 hours ago |
wasmtime-dev-aarch64-windows-c-api.zip | 19.9 MB | 12 hours ago |
wasmtime-dev-aarch64-windows.zip | 8.38 MB | 12 hours ago |
wasmtime-dev-riscv64gc-linux-c-api.tar.xz | 16.3 MB | 12 hours ago |
wasmtime-dev-riscv64gc-linux.tar.xz | 7.88 MB | 12 hours ago |
wasmtime-dev-s390x-linux-c-api.tar.xz | 15.4 MB | 12 hours ago |
wasmtime-dev-s390x-linux.tar.xz | 7.83 MB | 12 hours ago |
wasmtime-dev-src.tar.gz | 142 MB | 12 hours ago |
wasmtime-dev-x86_64-android-c-api.tar.xz | 14 MB | 12 hours ago |
wasmtime-dev-x86_64-android.tar.xz | 8.03 MB | 12 hours ago |
wasmtime-dev-x86_64-linux-c-api.tar.xz | 14.7 MB | 12 hours ago |
wasmtime-dev-x86_64-linux.tar.xz | 8.08 MB | 12 hours ago |
wasmtime-dev-x86_64-macos-c-api.tar.xz | 13.3 MB | 12 hours ago |
wasmtime-dev-x86_64-macos.tar.xz | 7.49 MB | 12 hours ago |
wasmtime-dev-x86_64-mingw-c-api.zip | 23.5 MB | 12 hours ago |
wasmtime-dev-x86_64-mingw.zip | 14.9 MB | 12 hours ago |
wasmtime-dev-x86_64-musl-c-api.tar.xz | 14.7 MB | 12 hours ago |
wasmtime-dev-x86_64-musl.tar.xz | 8.11 MB | 12 hours ago |
wasmtime-dev-x86_64-windows-c-api.zip | 21 MB | 12 hours ago |
wasmtime-dev-x86_64-windows.msi | 8.88 MB | 12 hours ago |
wasmtime-dev-x86_64-windows.zip | 9.17 MB | 12 hours ago |
wasmtime-platform.h | 9.14 KB | 12 hours ago |
Source code (zip) | - | 13 hours ago |
Source code (tar.gz) | - | 13 hours ago |
实现
使用c2w打包ffmpeg-cli进入wasm
[https://github.com/qsbye/ffmpeg.wasm]
[https://gitee.com/qsbye/ffmpeg.wasm] release页面有打包的wasm二进制文件
# 打包/Package
docker pull linuxserver/ffmpeg:version-7.0.2-cli
c2w linuxserver/ffmpeg:version-7.0.2-cli /home/qsbye/ffmpeg-7.0.2-cli.wasm
# 测试/Test
# 安装wasmtime运行时,当然也可以使用wasmer等其他的运行时(未测试)
curl https://wasmtime.dev/install.sh -sSf | bash
wasmtime ffmpeg-7.0.2-cli.wasm
# 转换文件夹下的sheep.mp3到sheep.wav文件
wasmtime run --dir $PWD::/root ffmpeg-7.0.2-cli.wasm -- -i /root/sheep.mp3 /root/sheep.wav
输出:
ffmpeg version 7.0.2 Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 13 (Ubuntu 13.2.0-23ubuntu4)
configuration: --disable-debug --disable-doc --disable-ffplay --enable-alsa --enable-cuda-llvm --enable-cuvid --enable-ffprobe --enable-gpl --enable-libaom --enable-libass --enable-libdav1d --enable-libfdk_aac --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libkvazaar --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libplacebo --enable-librav1e --enable-librist --enable-libshaderc --enable-libsrt --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpl --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-nonfree --enable-nvdec --enable-nvenc --enable-opencl --enable-openssl --enable-stripping --enable-vaapi --enable-vdpau --enable-version3 --enable-vulkan
libavutil 59. 8.100 / 59. 8.100
libavcodec 61. 3.100 / 61. 3.100
libavformat 61. 1.100 / 61. 1.100
libavdevice 61. 1.100 / 61. 1.100
libavfilter 10. 1.100 / 10. 1.100
libswscale 8. 1.100 / 8. 1.100
libswresample 5. 1.100 / 5. 1.100
libpostproc 58. 1.100 / 58. 1.100
Universal media converter
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'