Play a stream
The following program connects to an RTSP server, describes all available media streams, sets them up, and logs every incoming RTP and RTCP packet.Run it:You should see log lines like:
client-play/main.go
Record a stream
To publish a stream, describe the formats you want to send, call
StartRecording, and then write RTP packets in a loop.client-record/main.go
The
StartRecording call combines connecting, announcing the session description, and entering record state in a single step. For more advanced scenarios — such as encoding RGBA frames to H264 before sending — see the full example at examples/client-record-format-h264/main.go.The H264 encoder example (
examples/client-record-format-h264/main.go) carries a //go:build cgo tag and requires the FFmpeg development libraries. Pure RTP forwarding, as shown above, has no CGO dependency.Build a server
A gortsplib server is built around a handler struct that implements the callbacks you care about. The example below accepts a single publisher and forwards its packets to all readers.Run it:Expected output:The server now accepts publisher connections on
server/main.go
:8554 and streams RTP packets to any number of readers. UDP transport is available on ports 8000/8001, and multicast on 8002/8003.Next steps
Client guide
Configure transport options, authentication, and per-format packet callbacks.
Server guide
Handle authentication, multiple streams, and session lifecycle events.
RTP formats
Encode and decode H264, H265, AV1, AAC, Opus, and more.
Installation
CGO requirements and version pinning details.