Skip to main content
Every RTP stream carries a specific payload format that defines how media is encoded into packets. gortsplib models each format as a Go struct that implements the Format interface, giving you typed access to codec parameters and built-in RTP packetizers/depacketizers.

The Format interface

All format structs live in the github.com/bluenviron/gortsplib/v5/pkg/format package and satisfy this interface:
Most concrete format types additionally expose CreateEncoder() and CreateDecoder() methods that return format-specific RTP encoder/decoder objects.

Formats in a session description

When you call client.Describe(), the library parses the SDP and returns a *description.Session. Each description.Media in desc.Medias holds a []format.Format slice:

Detecting a specific format

Because each codec is a concrete struct, you can use a type assertion to check for it:
The helper desc.FindFormat does this for you and also returns the matching media:

Creating encoders and decoders

Once you have a concrete format value, call CreateDecoder() to receive an RTP depacketizer, or CreateEncoder() to receive an RTP packetizer. The returned objects are format-specific, with typed Decode / Encode methods.
Not every format ships with a built-in encoder or decoder. Formats such as Speex, Vorbis, and G726 require you to supply your own RTP packetizer. See the audio and video reference pages for availability details.

Next steps

Video formats

H264, H265, AV1, VP8, VP9, M-JPEG, MPEG-4 Video, and MPEG-1/2 Video.

Audio formats

Opus, MPEG-4 Audio (AAC), G711, G722, LPCM, AC-3, Speex, and more.