Skip to main content
To publish a stream, you describe the formats you intend to send, connect to the server, and then write RTP packets in a loop.

Record workflow

1

Define a session description

A description.Session declares every media track and its format. The server uses this information during ANNOUNCE to understand what you will send.
2

Start recording

StartRecording is a one-call shorthand that internally runs:
  1. c.Scheme = u.Scheme; c.Host = u.Host
  2. c.Start()
  3. c.Announce(u, desc)
  4. c.SetupAll(u, desc.Medias)
  5. c.Record()
If you need finer control — for example, to inspect the ANNOUNCE response before proceeding — call Start, Announce, SetupAll, and Record individually instead of using the shorthand.
3

Write RTP packets

Call WritePacketRTP to push a packet to the server. Pass the *description.Media that the packet belongs to.

Complete H264 example

This example announces an H264 format and sends encoded frames at 5 FPS. The encoder uses CGO (FFmpeg); the RTP layer is pure Go.
This file carries a //go:build cgo tag and requires the FFmpeg development libraries:
client-record-format-h264/main.go

Setting client options for recording

You can configure timeouts and transport before calling StartRecording by initializing the Client struct directly.
client-record-options/main.go

Pause and resume

Call c.Pause() to send a PAUSE request that suspends transmission without disconnecting. Call c.Record() to resume.
client-record-pause/main.go
Packet writes to the server while in the paused state will return an error. Ensure your write goroutine handles or gates on the paused state.

Play to record (re-publish)

You can relay a stream from one path to another by combining a reader client and a publisher client. Set up the reader first — including SetupAll — before calling StartRecording on the publisher, because StartRecording resets the control attribute of the medias.
client-play-to-record/main.go
Always call reader.SetupAll before publisher.StartRecording. StartRecording mutates the Control attribute of each description.Media in-place; calling it before SetupAll would break the reader’s SETUP URLs.