Skip to main content
1

Install gortsplib

Add the library to your Go module:
Go 1.25 or later is required. Run go version to confirm before proceeding.
2

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.
client-play/main.go
Run it:
You should see log lines like:
defer c.Close() is called immediately after c.Start() succeeds. Place it here — not after later calls — so the client is always cleaned up even when Describe or SetupAll returns an error.
3

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.
4

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.
server/main.go
Run it:
Expected output:
The server now accepts publisher connections on :8554 and streams RTP packets to any number of readers. UDP transport is available on ports 8000/8001, and multicast on 8002/8003.
Implement only the handler methods you need. If you omit OnAnnounce, the server will reject all ANNOUNCE requests automatically.

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.