Expand description
rtmp-rs: Production RTMP client/server library
This library provides a complete RTMP implementation supporting:
- Server mode for receiving streams from OBS, ffmpeg, etc.
- Client mode for pulling streams from remote RTMP servers
- H.264 video and AAC audio codec support
- GOP buffering for late-joiner support
- Lenient parsing for encoder compatibility (OBS quirks)
§Example: Simple Server
use rtmp_rs::{RtmpServer, ServerConfig, RtmpHandler, AuthResult};
use rtmp_rs::session::SessionContext;
use rtmp_rs::protocol::message::{ConnectParams, PublishParams};
struct MyHandler;
impl RtmpHandler for MyHandler {
async fn on_connect(&self, _ctx: &SessionContext, _params: &ConnectParams) -> AuthResult {
AuthResult::Accept
}
async fn on_publish(&self, _ctx: &SessionContext, params: &PublishParams) -> AuthResult {
println!("Stream published: {}", params.stream_key);
AuthResult::Accept
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = RtmpServer::new(ServerConfig::default(), MyHandler);
server.run().await?;
Ok(())
}Re-exports§
pub use client::config::ClientConfig;pub use client::connector::RtmpConnector;pub use client::puller::ClientEvent;pub use client::puller::RtmpPuller;pub use error::Error;pub use error::Result;pub use registry::BroadcastFrame;pub use registry::RegistryConfig;pub use registry::StreamKey;pub use registry::StreamRegistry;pub use server::config::ServerConfig;pub use server::handler::AuthResult;pub use server::handler::RtmpHandler;pub use server::listener::RtmpServer;
Modules§
- amf
- AMF (Action Message Format) implementation
- client
- RTMP client implementation
- error
- Unified error types for rtmp-rs
- media
- Media handling for RTMP
- protocol
- RTMP wire protocol implementation
- registry
- Stream registry for pub/sub routing
- server
- RTMP server implementation
- session
- RTMP session state management
- stats
- Statistics and metrics