Rust Libraries
The Rust implementation provides the reference implementation of the MoQ protocol, along with server-side tools and native applications.
Core Libraries
moq-lite
The core pub/sub transport protocol implementing the moq-lite specification.
Features:
- Broadcasts, tracks, groups, and frames
- Built-in concurrency and deduplication
- QUIC stream management
- Prioritization and backpressure
hang
Media-specific encoding/streaming library built on top of moq-lite.
Features:
- Catalog for track discovery
- Container format (timestamp + codec bitstream)
- Support for H.264/265, VP8/9, AV1, AAC, Opus
moq-mux
Media muxers and demuxers for importing existing formats into MoQ.
Features:
- fMP4/CMAF import
- HLS playlist import
- H.264/H.265 Annex B parsing
- AAC and Opus codec support
Authentication
moq-token
JWT authentication library and CLI tool for generating tokens.
Features:
- HMAC and RSA/ECDSA signing
- Path-based authorization
- Token generation and verification
- Available as library and CLI
Networking
web-transport
QUIC and WebTransport implementation for Rust.
Features:
- Quinn-based QUIC
- WebTransport protocol support
- TLS certificate management
- Server and client modes
moq-native
Opinionated helpers to configure a Quinn QUIC endpoint.
Features:
- TLS certificate management
- QUIC transport configuration
- Connection setup helpers
CLI Tools
moq-cli
Command-line tool for media operations (binary name: moq).
Features:
- Publish video from files or FFmpeg
- Test and development
- Media server deployments
Installation:
cargo install moq-cliUsage:
# Publish a video file
moq publish video.mp4
# Publish from FFmpeg
ffmpeg -i input.mp4 -f mpegts - | moq publish -moq-token-cli
Command-line tool for JWT token management (binary name: moq-token).
Installation:
cargo install moq-token-cliUsage:
# Generate a key
moq-token --key root.jwk generate
# Sign a token
moq-token --key root.jwk sign \
--root "rooms/123" \
--publish "alice" \
--expires 1735689600See Authentication guide for details.
Utilities
moq-clock
Timing and clock utilities for synchronization.
libmoq
C bindings for moq-lite via FFI.
Use cases:
- Integrate with C/C++ applications
- Bindings for other languages
- Legacy system integration
Installation
From crates.io
Add to your Cargo.toml:
[dependencies]
moq-lite = "0.1"
hang = "0.1"From Source
git clone https://github.com/moq-dev/moq
cd moq/rs
cargo build --releaseUsing Nix
# Build moq-relay
nix build github:moq-dev/moq#moq-relay
# Build moq-cli
nix build github:moq-dev/moq#moqQuick Start
Publishing (Rust)
use moq_lite::*;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to relay
let connection = Connection::connect("https://relay.example.com/demo").await?;
// Create a broadcast
let mut broadcast = BroadcastProducer::new("my-broadcast");
// Create a track
let mut track = broadcast.create_track("chat");
// Publish a group with a frame
let mut group = track.append_group();
group.write(b"Hello, MoQ!")?;
group.close()?;
// Publish to connection
connection.publish(&mut broadcast).await?;
Ok(())
}Subscribing (Rust)
use moq_lite::*;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to relay
let connection = Connection::connect("https://relay.example.com/demo").await?;
// Subscribe to a broadcast
let broadcast = connection.consume("my-broadcast").await?;
// Subscribe to a track
let mut track = broadcast.subscribe("chat").await?;
// Read groups and frames
while let Some(group) = track.next_group().await? {
while let Some(frame) = group.read().await? {
println!("Received: {:?}", frame);
}
}
Ok(())
}API Documentation
Full API documentation is available on docs.rs:
Next Steps
- Explore moq-lite - Core protocol
- Explore hang - Media library
- Explore moq-mux - Media import
- Deploy moq-relay - Relay server
- View code examples