Muxide takes correctly-timestamped, already-encoded audio/video frames and produces a standards-compliant MP4 — pure Rust, minimal external dependencies, no FFmpeg.
Why Muxide Exists
If you're building a recording pipeline in Rust, you know the tradeoffs:
| Approach | Tradeoff |
|---|---|
| FFmpeg CLI/libs | External binary, GPL licensing concerns, "which build is this?" |
| GStreamer | Complex plugin system, C dependencies, heavy runtime |
| Raw MP4 writing | ISO-BMFF expertise required (sample tables, interleaving, moov layout) |
| "Minimal" crates | Often missing fast-start, strict validation, or production ergonomics |
Muxide solves one job cleanly:
Take already-encoded frames with correct timestamps → produce a standards-compliant, immediately-playable MP4 → using pure Rust.
Nothing more. Nothing less.
Installation & Usage
As a Library
use ;
let mut muxer = new
.video?
.build?;
// Write your encoded frames...
muxer.write_video?;
muxer.finish?;
As a CLI Tool
# Install globally
# Or download pre-built binary from releases
# Then use:
# Quick examples:
The CLI tool accepts raw encoded frames from stdin or files and produces MP4 output.
Core Invariant
Muxide enforces a strict contract:
| Your Responsibility | Muxide's Guarantee |
|---|---|
| ✓ Frames are already encoded | ✓ Valid ISO-BMFF (MP4) |
| ✓ Timestamps are monotonic | ✓ Correct sample tables |
| ✓ DTS provided for B-frames | ✓ Fast-start layout |
| ✓ Codec headers in keyframes | ✓ No post-processing needed |
If input violates the contract, Muxide fails fast with explicit errors—no silent corruption, no guessing.
Features
| Category | Supported | Notes |
|---|---|---|
| Video | H.264/AVC | Annex B format |
| H.265/HEVC | Annex B with VPS/SPS/PPS | |
| AV1 | OBU stream format | |
| VP9 | Frame header parsing, resolution/bit-depth/color config extraction | |
| Audio | AAC | All profiles: LC, Main, SSR, LTP, HE, HEv2 |
| Opus | Raw packets, 48kHz | |
| Container | Fast-start | moov before mdat for web playback |
| B-frames | Explicit PTS/DTS support | |
| Fragmented MP4 | For DASH/HLS streaming | |
| Metadata | Title, creation time, language | |
| Quality | World-class errors | Detailed diagnostics, hex dumps, JSON output |
| Production tested | FFmpeg compatibility verified | |
| Comprehensive testing | 80+ tests, property-based validation |
Design Principles
| Principle | Implementation |
|---|---|
| 🦀 Pure Rust | No unsafe, no FFI, no C bindings |
| 📦 Minimal deps | Only essential Rust crates — no external binaries |
| 🧵 Thread-safe | Send + Sync when writer is |
| ✅ Well-tested | Unit, integration, property tests |
| 📜 MIT license | No GPL, no copyleft concerns |
| 🚨 Developer-friendly | Exceptional error messages make debugging 10x faster |
Note:
no_stdis not supported. Muxide requiresstd::io::Write.
Quick Start
use ;
use File;
HEVC/H.265 (4K)
// Requires VPS, SPS, PPS in first keyframe
let mut muxer = new
.video
.build?;
muxer.write_video?;
AV1
// Requires Sequence Header OBU in first keyframe
let mut muxer = new
.video
.build?;
muxer.write_video?;
Opus Audio
// Opus always uses 48kHz internally (per spec)
let mut muxer = new
.video
.audio
.build?;
muxer.write_audio?;
Fragmented MP4 (DASH/HLS)
use Vp9Config;
// H.264
let sps_bytes = vec!;
let pps_bytes = vec!;
let mut muxer = new
.video
.with_sps
.with_pps
.new_with_fragment?;
// H.265
let vps_bytes = vec!;
let sps_bytes = vec!;
let pps_bytes = vec!;
let mut muxer = new
.video
.with_vps
.with_sps
.with_pps
.new_with_fragment?;
// AV1
let seq_header_bytes = vec!;
let mut muxer = new
.video
.with_av1_sequence_header
.new_with_fragment?;
// VP9
let vp9_config = Vp9Config ;
let mut muxer = new
.video
.with_vp9_config
.new_with_fragment?;
// Get init segment (ftyp + moov)
let init_segment = muxer.init_segment;
// Write frames...
muxer.write_video?;
// Get media segments (moof + mdat)
if let Some = muxer.flush_segment
B-Frames with Explicit DTS
// When encoder produces B-frames, provide both PTS and DTS
muxer.write_video_with_dts?;
Command Line Tool
Muxide includes a command-line tool for quick testing and development workflows:
# Install the CLI tool
# Basic video-only muxing
# Video + audio with metadata
# JSON output for automation
# Validate input files without muxing
# Get info about supported codecs
Supported Codecs:
- Video: H.264 (AVC), H.265 (HEVC), AV1
- Audio: AAC (all profiles), Opus
Features:
- Progress reporting with
--verbose - JSON output for CI/CD integration
- Comprehensive error messages
- Fast-start MP4 layout by default
- Metadata support (title, language, creation time)
What Muxide Is Not
Muxide is intentionally focused. It does not:
| Not Supported | Why |
|---|---|
| Encoding/decoding | Use openh264, x264, rav1e, etc. |
| Transcoding | Not a codec library |
| Demuxing/reading MP4 | Write-only by design |
| Timestamp correction | Garbage in = error out |
| Non-MP4 containers | MKV, WebM, AVI not supported |
| DRM/encryption | Out of scope |
Muxide is the last mile: encoder output → playable file.
Use Cases
Muxide is a great fit for:
- 🎥 Screen recorders — capture → encode → mux → ship
- 📹 Camera apps — webcam/IP camera recording pipelines (e.g., CrabCamera integration)
- 🎬 Video editors — export timeline to MP4
- 📡 Streaming — generate fMP4 segments for DASH/HLS
- 🏭 Embedded systems — single binary, no external deps
- 🔬 Scientific apps — deterministic, reproducible output
Probably not a fit if you need encoding, demuxing, or legacy codecs (MPEG-2, etc.).
Example: Fast-Start Proof
The faststart_proof example demonstrates a structural MP4 invariant:
- Two MP4 files are generated from the same encoded inputs
- One with fast-start enabled, one without
- No external tools are used at any stage
$ cargo run --example faststart_proof --release
output: recording_faststart.mp4
layout invariant: moov before mdat = YES
output: recording_normal.mp4
layout invariant: moov before mdat = NO
When served over HTTP, the fast-start file can begin playback without waiting for the full download (player behavior varies, but the layout property is deterministic).
This example is intentionally minimal:
- Timestamps are generated in-code
- No B-frames/DTS paths are exercised
- The goal is container layout correctness, not encoding quality
Performance
Muxide is designed for minimal overhead. Muxing should never be your bottleneck.
| Scenario | Time | Throughput |
|---|---|---|
| 1000 H.264 frames | 264 µs | 3.7M frames/sec |
| 1000 H.264 + fast-start | 362 µs | 2.8M frames/sec |
| 1000 video + 1500 audio | 457 µs | 2.2M frames/sec |
| 100 4K frames (~6.5 MB) | 14 ms | 464 MB/sec |
Note: Benchmarks are based on development hardware. Encoding is typically the bottleneck—muxing overhead is negligible. Run
cargo benchfor your environment (dev-only benchmarks available).AVC
- Format: Annex B (start codes:
00 00 00 01or00 00 01) - First keyframe must contain: SPS and PPS NAL units
- NAL unit types: IDR (keyframe), non-IDR, SPS, PPS
H.265/HEVC
- Format: Annex B (start codes)
- First keyframe must contain: VPS, SPS, and PPS NAL units
- NAL unit types: IDR_W_RADL, IDR_N_LP, CRA, VPS, SPS, PPS
AV1
- Format: OBU (Open Bitstream Unit) stream
- First keyframe must contain: Sequence Header OBU
- OBU types: Sequence Header, Frame, Frame Header, Tile Group
AAC
- Format: ADTS (Audio Data Transport Stream)
- Header: 7-byte ADTS header per frame
- Profiles: LC-AAC recommended
Opus
- Format: Raw Opus packets (no container)
- Sample rate: Always 48000 Hz (Opus specification)
- Channels: 1 (mono) or 2 (stereo)
Documentation
| Resource | Description |
|---|---|
| 📚 API Reference | Complete API documentation |
| 📜 Design Charter | Architecture decisions and rationale |
| 📋 API Contract | Input/output guarantees |
FAQ
FFmpeg is excellent, but:
- External binary dependency (distribution complexity)
- GPL licensing concerns for some builds
- Process orchestration overhead
- "What flags was this built with?" debugging
Muxide is a single cargo add with minimal external dependencies.
No. Muxide is muxing only. For encoding, use:
openh264— H.264 encoding (BSD)rav1e— AV1 encoding (BSD)x264/x265— H.264/HEVC (GPL, via FFI)
Muxide will reject non-monotonic timestamps with a clear error. It does not attempt to "fix" broken input — this is by design to ensure predictable output.
Yes. Muxide has an extensive test suite (unit, integration, property-based tests) and is designed for predictable, deterministic behavior.
License
MIT — no GPL, no copyleft, no surprises.