Skip to main content
Import path: github.com/bluenviron/gortsplib/v5/pkg/format

Format interface

Every RTP payload format implements the Format interface:

Method descriptions

int
The RTP clock rate in Hz used for timestamp calculations. For example, 90000 for video formats and 48000 for Opus audio.
uint8
The RTP payload type number (0–127). Dynamic payload types are in the range 96–127. Some formats use static payload type numbers (e.g., PCMU is 0, PCMA is 8).
string
The a=rtpmap SDP attribute value. Returns an empty string for formats with static payload types where rtpmap is optional.
map[string]string
The a=fmtp attribute as a parsed key-value map. Returns an empty map when no format parameters are needed.
bool
Reports whether the presentation timestamp equals the decode timestamp for the given packet. Returns true on random-access points (e.g., H.264 IDR frames).

Format implementations


Encoder and decoder pattern

Formats that carry complex framing (e.g., H.264 NAL unit packetization) provide CreateEncoder() and CreateDecoder() factory methods. These return codec-specific types from sub-packages under pkg/format/rtp<codec>.

Encoding

Decoding


H264 struct

H264 is the RTP format for the H.264 codec (RFC 6184).
uint8
required
RTP payload type number. Typically 96 for dynamic assignment. The field name is PayloadTyp (not PayloadType) to avoid a collision with the interface method.
[]byte
H.264 Sequence Parameter Set NAL unit (without Annex B start code). Serialized into the sprop-parameter-sets fmtp attribute.
[]byte
H.264 Picture Parameter Set NAL unit (without Annex B start code). Serialized alongside SPS in sprop-parameter-sets.
int
H.264 packetization mode (0 = single NAL unit mode, 1 = non-interleaved mode). Serialized as the packetization-mode fmtp attribute. Defaults to 0.

H264 methods


Example with H264


Codec-specific encoder/decoder packages

Each sub-package under pkg/format/rtp<codec> exposes Encoder and Decoder structs with codec-specific options:
The rtpfragmented sub-package provides a generic fragmented-unit encoder/decoder used internally by several codec packages.