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:c.Scheme = u.Scheme; c.Host = u.Hostc.Start()c.Announce(u, desc)c.SetupAll(u, desc.Medias)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 callingStartRecording by initializing the Client struct directly.
client-record-options/main.go
Pause and resume
Callc.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 — includingSetupAll — before calling StartRecording on the publisher, because StartRecording resets the control attribute of the medias.
client-play-to-record/main.go