A browser-based video transcoder that uses FFmpeg compiled to WebAssembly, built entirely in Rust with the Yew framework.
This project provides a pure WebAssembly implementation of video transcoding using FFmpeg. Unlike other solutions that rely on JavaScript bridges, this project compiles FFmpeg directly to WebAssembly and creates direct Rust bindings to it.
- Upload video files directly in your browser
- Convert between various formats (MP4, WebM, MKV, etc.)
- Change video/audio codecs (H.264, H.265, VP9, etc.)
- Adjust bitrate and resolution
- Download processed videos directly in the browser
- Real-time progress tracking
- No server-side processing required
To build this project, you'll need:
-
Rust with the wasm32 target:
rustup target add wasm32-unknown-unknown
-
cargo install wasm-pack
-
git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install latest ./emsdk activate latest source ./emsdk_env.sh # or emsdk_env.bat on Windows
-
Clone the repository:
git clone https://github.com/yourusername/ffmpeg-transcoder.git cd ffmpeg-transcoder
-
Build the project:
wasm-pack build --target web
Note: The first build will take a significant amount of time as it compiles FFmpeg from source. Subsequent builds will be much faster.
-
Serve the application:
# Create a dist directory mkdir -p dist # Copy necessary files cp -r static/* dist/ cp -r pkg dist/ # Serve with your preferred web server python3 -m http.server --directory dist 8080
-
Open your browser to
http://localhost:8080
-
FFmpeg Compilation: During the build process, FFmpeg is compiled to WebAssembly using Emscripten. This is handled by the
build.rs
script. -
C Wrapper: A C wrapper (
ffmpeg_wrapper.c
) is used to create a simplified API around FFmpeg's complex codebase. -
Rust Bindings: The Rust code (
src/ffmpeg.rs
) creates direct bindings to the compiled WebAssembly module. -
UI Layer: The user interface is built with Yew, a Rust framework for creating web applications.
build.rs
- Build script that compiles FFmpeg to WebAssemblysrc/
lib.rs
- Main Rust library entry pointapp.rs
- Yew application componentffmpeg.rs
- Rust bindings to FFmpeg WebAssemblyffmpeg_wrapper.c
- C wrapper around FFmpeg librariesffmpeg_pre.js
- JavaScript utilities for FFmpeg WebAssemblycomponents/
- UI components
static/
- Static files (HTML, CSS)
Video processing can be memory-intensive. This implementation:
- Uses streaming where possible to reduce memory usage
- Sets initial WebAssembly memory to 32MB
- Allows memory growth up to 512MB
- Frees memory as soon as it's no longer needed
This application works in browsers that support WebAssembly and the necessary Web APIs:
- Chrome/Edge (version 79+)
- Firefox (version 72+)
- Safari (version 13.1+)
Mobile browsers may have more limited memory and performance.
- Maximum file size depends on browser memory limitations
- Some codecs might not be available due to patent restrictions
- Complex video processing operations might be slow compared to native applications
This project is licensed under MIT License - see the LICENSE file for details.
- FFmpeg team for their incredible video processing library
- Rust and Yew teams for making WebAssembly development possible
- Emscripten project for the WebAssembly compiler infrastructure