rtmp-runtime
Sans-IO RTMP 1.0 publish engine, both ends: an ingest server that receives a live push from OBS or ffmpeg, and a publish client that pushes to a remote RTMP server. An optional tokio adapter provides sockets.
What it does / what it does not
Does: own the RTMP wire layer for both publishing and playing. That is the handshake, chunk-stream assembly and writing, protocol control messages, AMF0 commands, and the connect, createStream, publish flow on the server/publish side, plus a sans-IO client in ClientMode::Play that runs connect -> createStream -> SetBufferLength + play and reports ClientEvent::Playing, ClientEvent::Media { flv } (FLV tags, first chunk prefixed with the FLV file header), ClientEvent::StreamEnded and ClientEvent::Error. The server hands the received audio, video and data back as FLV bytes (feed them to transmux's FLV demuxer); the client play mode hands the same FLV bytes back through ClientEvent::Media.
Does not: run the complex (HMAC) handshake, support RTMPE/RTMPS, or implement AMF3 beyond decoding AMF3-encoded command messages. There are no sockets in the core: you feed bytes in and write the returned bytes out.
Typical users: a live-ingest origin (multimux's RTMP input and push output), test publishers, capture tooling.
Standards supported
| Standard | Edition | Scope | Status | Notes |
|---|---|---|---|---|
| Adobe RTMP specification 1.0 | 1.0 (vendored adobe_rtmp_1.0, transcribed in docs/rtmp.md) |
§5.2 handshake (simple), §5.3 chunk stream (fmt 0 to 3, 1/2/3-byte csid, extended timestamp), §5.4 protocol control, §6 message format, §7.1 message types, §7.2 command messages for the publish and play flows | Partial | Publish and play (client play mode); no complex handshake. docs/rtmp.md uses its own section numbering |
Adobe AMF0 (referenced as [AMF0] by the RTMP spec) |
Not separately vendored | Value types and the command set used for ingest | Partial | AMF3 commands (type 17) decode like AMF0; Data-AMF3 (15) and Shared-Object (16/19) are out of scope |
| Adobe FLV (file format v10.1) | v10.1 (vendored adobe_flv_f4v_v10_1) |
Server emits FLV tags for audio, video and script data | Full for output | Demux with transmux |
Verified against a real ffmpeg publish capture (tests/fixtures/obs-publish.bin, provenance in tests/fixtures/PROVENANCE.md), replayed whole and in small chunks, and decoded by transmux into an H.264 plus AAC Media.
Features
| Feature | Default | Description |
|---|---|---|
serde |
no | Serialize/Deserialize on ServerEvent, ServerConfig, Amf0Value, Command. |
tokio |
no | io::AsyncRtmpServer, RtmpConnection, io::AsyncRtmpClient, io::RtmpTimeouts and target::RtmpTarget (rtmp://host[:port]/app/key, parsed with url). |
The core is std and needs no runtime; it has #![forbid(unsafe_code)].
Quick start
Replay the real ffmpeg capture through the server session:
use ;
let capture = read.unwrap;
let mut session = with_defaults;
let mut flv = Vecnew;
let mut published = false;
for chunk in capture.chunks
assert!;
Or connect the two roles in memory (a publisher and an ingest server, no socket):
use ;
use ;
let mut config = default;
config.app = "live".into;
config.stream_key = "key".into;
let mut client = new;
let mut server = new;
let mut to_server = client.start;
let = ;
for _ in 0..32
assert!;
With the tokio feature, io::AsyncRtmpServer binds a listener and drives one ServerSession per connection, and io::AsyncRtmpClient publishes to an RtmpTarget URL. See the ingest_to_flv and capture_publish examples.
What is implemented
- Handshake (
handshake): C0/S0, C1/S1, C2/S2, simple form (interoperates with ffmpeg and OBS). - Chunk stream (
chunk): all fourfmtheader forms, extended timestamps, incrementalChunkAssembler(header inheritance,SetChunkSize, partial input),ChunkWriter. - Messages (
message): protocol control (SetChunkSize, Abort, Acknowledgement, WindowAckSize, SetPeerBandwidth), User Control events, the message type catalogue. - AMF0 (
amf0):Amf0ValueandCommandencode and decode. server::ServerSession:connect,createStream,publish, plus the OBS extrasreleaseStreamandFCPublish; replies_result, StreamBegin andonStatus; acknowledgement accounting; optionalexpected_stream_keygate. Events:Connected,Publish,Media,Eof,Unsupported.client::ClientSession: client handshake and the auto-advancing publish flow, thensend_audio,send_video,send_metadata.- Security defaults:
ServerConfig::expected_stream_key = Noneadmits any publisher, so a server reachable from untrusted networks must set a key (compared in constant time).Debugnever prints the stream key. In-progress message size is capped bymax_in_progress_bytes.
Design notes
Bytes-in, (bytes-out, events) engine with partial-input buffering, so it runs on any transport. Wire structures implement symmetric Parse/Serialize; a chunk message length over 24 bits is rejected (FieldOverflow) instead of truncated. RtmpError is #[non_exhaustive].
Related crates
Depends on broadcast-common; transmux (a dev-dependency here) demuxes the FLV the server emits. multimux builds its RTMP input and push on this crate; rtsp-runtime is the sibling sans-IO client and server engine.
MSRV and licence
MSRV 1.95.0. Licensed under MIT OR Apache-2.0.