Import path:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/bluenviron/gortsplib/llms.txt
Use this file to discover all available pages before exploring further.
github.com/bluenviron/gortsplib/v5/pkg/format
Format interface
Every RTP payload format implements theFormat interface:
Method descriptions
The RTP clock rate in Hz used for timestamp calculations. For example,
90000 for video
formats and 48000 for Opus audio.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).
The
a=rtpmap SDP attribute value. Returns an empty string for formats with static
payload types where rtpmap is optional.The
a=fmtp attribute as a parsed key-value map. Returns an empty map when no
format parameters are needed.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
| Struct | Codec | Static payload type | Dynamic (96–127) | Encoder pkg | Decoder pkg |
|---|---|---|---|---|---|
H264 | H.264 / AVC | 35 (allowed) | Yes | rtph264 | rtph264 |
H265 | H.265 / HEVC | — | Yes | rtph265 | rtph265 |
AV1 | AV1 | — | Yes | rtpav1 | rtpav1 |
VP9 | VP9 | — | Yes | rtpvp9 | rtpvp9 |
VP8 | VP8 | — | Yes | rtpvp8 | rtpvp8 |
MPEG4Video | MPEG-4 Part 2 video | — | Yes | — | — |
MPEG1Video | MPEG-1/2 video | 32 | No | rtpmpeg1video | rtpmpeg1video |
MJPEG | Motion JPEG | 26 | No | rtpmjpeg | rtpmjpeg |
Opus | Opus / MultiOpus | — | Yes | rtpsimpleaudio | rtpsimpleaudio |
MPEG4Audio | MPEG-4 Audio (Generic) | — | Yes | rtpmpeg4audio | rtpmpeg4audio |
MPEG4AudioLATM | MPEG-4 Audio LATM | — | Yes | — | — |
Vorbis | Vorbis | — | Yes | — | — |
AC3 | AC-3 | — | Yes | rtpac3 | rtpac3 |
G711 | G.711 PCMU/PCMA | 0, 8 | Yes | rtpsimpleaudio | rtpsimpleaudio |
G722 | G.722 | 9 | No | rtpsimpleaudio | rtpsimpleaudio |
G726 | G.726 (16/24/32/40 kbps) | — | Yes | — | — |
LPCM | Linear PCM (L8/L16/L24) | 10, 11 | Yes | rtplpcm | rtplpcm |
MPEG1Audio | MPEG-1/2 audio | 14 | No | rtpmpeg1audio | rtpmpeg1audio |
Speex | Speex | — | Yes | — | — |
KLV | SMPTE 336M KLV | — | Yes | rtpklv | rtpklv |
MPEGTS | MPEG-TS | 33 | No | rtpmpegts | rtpmpegts |
Generic | Unknown / fallback | any | any | — | — |
Encoder and decoder pattern
Formats that carry complex framing (e.g., H.264 NAL unit packetization) provideCreateEncoder() 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).
RTP payload type number. Typically
96 for dynamic assignment. The field name is
PayloadTyp (not PayloadType) to avoid a collision with the interface method.H.264 Sequence Parameter Set NAL unit (without Annex B start code). Serialized
into the
sprop-parameter-sets fmtp attribute.H.264 Picture Parameter Set NAL unit (without Annex B start code). Serialized
alongside
SPS in sprop-parameter-sets.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
| Method | Signature | Description |
|---|---|---|
CreateEncoder | () (*rtph264.Encoder, error) | Returns an H.264 RTP encoder initialized with the format’s payload type and packetization mode. |
CreateDecoder | () (*rtph264.Decoder, error) | Returns an H.264 RTP decoder. |
SafeSetParams | (sps []byte, pps []byte) | Thread-safe setter for SPS and PPS parameters. |
SafeParams | () ([]byte, []byte) | Thread-safe getter for SPS and PPS parameters. |
Example with H264
Codec-specific encoder/decoder packages
Each sub-package underpkg/format/rtp<codec> exposes Encoder and Decoder structs
with codec-specific options:
| Sub-package | Codec |
|---|---|
pkg/format/rtph264 | H.264 |
pkg/format/rtph265 | H.265 |
pkg/format/rtpav1 | AV1 |
pkg/format/rtpvp8 | VP8 |
pkg/format/rtpvp9 | VP9 |
pkg/format/rtpmpeg4audio | MPEG-4 Audio |
pkg/format/rtpac3 | AC-3 |
pkg/format/rtplpcm | Linear PCM |
pkg/format/rtpklv | KLV |
pkg/format/rtpmjpeg | Motion JPEG |
pkg/format/rtpmpeg1audio | MPEG-1 Audio |
pkg/format/rtpmpeg1video | MPEG-1 Video |
pkg/format/rtpmpegts | MPEG-TS |
pkg/format/rtpsimpleaudio | G.711, G.722, Opus |
The
rtpfragmented sub-package provides a generic fragmented-unit encoder/decoder
used internally by several codec packages.