Skip to main content

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.

Import path: github.com/bluenviron/gortsplib/v5/pkg/base

URL

URL is an RTSP URL. It is a thin alias over the standard library’s net/url.URL, with RTSP-specific validation and helpers.
type URL url.URL

ParseURL

func ParseURL(s string) (*URL, error)
Parses a raw RTSP URL string. Returns an error if:
  • the scheme is not rtsp or rtsps,
  • the URL contains opaque data,
  • the URL contains a fragment (#).
u, err := base.ParseURL("rtsp://user:pass@192.168.1.1:554/stream")

URL methods

MethodSignatureDescription
String() stringReturns the URL as a string (fmt.Stringer).
Clone() *URLReturns a deep copy of the URL including credentials.
CloneWithoutCredentials() *URLReturns a copy with the User field cleared. Used when sending URLs on the wire.
Hostname() stringHost without port. Strips brackets from IPv6 addresses.
Port() stringPort portion of the host, without the leading colon.

Request

Request represents an RTSP/1.0 request message.
type Request struct {
    Method Method
    URL    *URL
    Header Header
    Body   []byte
}

Fields

Method
Method
required
The RTSP method (e.g., Describe, Setup, Play). See the Methods table.
URL
*URL
The request URL. May be nil when the request targets * (used in some OPTIONS requests).
Header
Header
Map of header fields. Keys are canonical header names; values are HeaderValue ([]string).
Body
[]byte
Optional request body. When non-empty, Content-Length is set automatically during marshaling.

Request methods

MethodSignatureDescription
Unmarshal(br *bufio.Reader) errorReads and parses a request from a buffered reader.
Marshal() ([]byte, error)Serializes the request to a byte slice.
MarshalSize() intReturns the serialized byte length without allocating.
MarshalTo(buf []byte) (int, error)Serializes the request into a pre-allocated buffer.
String() stringReturns the serialized request as a string (fmt.Stringer).

Response

Response represents an RTSP/1.0 response message.
type Response struct {
    StatusCode    StatusCode
    StatusMessage string
    Header        Header
    Body          []byte
}

Fields

StatusCode
StatusCode
required
Numeric status code. See the Status codes table.
StatusMessage
string
Human-readable status message (e.g., "OK"). If empty during marshaling, the standard message for the status code is filled in automatically from StatusMessages.
Header
Header
Map of header fields.
Body
[]byte
Optional response body. Content-Length is set automatically during marshaling.

Response methods

MethodSignatureDescription
Unmarshal(br *bufio.Reader) errorReads and parses a response from a buffered reader.
Marshal() ([]byte, error)Serializes the response to a byte slice.
MarshalSize() intReturns the serialized byte length without allocating.
MarshalTo(buf []byte) (int, error)Serializes the response into a pre-allocated buffer.
String() stringReturns the serialized response as a string (fmt.Stringer).

type HeaderValue []string
type Header map[string]HeaderValue
Header is a map from canonical header name to one or more string values. The same header key can appear more than once in a request or response; all values are collected into the HeaderValue slice. Key normalization follows net/http.CanonicalHeaderKey with RTSP-specific overrides: CSeq, RTP-Info, WWW-Authenticate, and KeyMgmt.

Methods

Method is a string type.
ConstantWire valueDescription
Announce"ANNOUNCE"Publish stream metadata to a server.
Describe"DESCRIBE"Retrieve stream description (SDP) from a server.
GetParameter"GET_PARAMETER"Read a session or stream parameter.
Options"OPTIONS"Query the methods supported by a server or resource.
Pause"PAUSE"Temporarily halt delivery of a stream.
Play"PLAY"Start or resume delivery of a stream.
Record"RECORD"Start recording a stream to a server.
Setup"SETUP"Negotiate transport parameters for a single media.
SetParameter"SET_PARAMETER"Write a session or stream parameter.
Teardown"TEARDOWN"Terminate a session and release server resources.

Status codes

StatusCode is an int type. StatusMessages is a map[StatusCode]string that maps each code to its standard reason phrase.

1xx Informational

ConstantCode
StatusContinue100

2xx Success

ConstantCode
StatusOK200

3xx Redirection

ConstantCode
StatusMovedPermanently301
StatusFound302
StatusSeeOther303
StatusNotModified304
StatusUseProxy305

4xx Client errors

ConstantCodeReason
StatusBadRequest400Bad Request
StatusUnauthorized401Unauthorized
StatusPaymentRequired402Payment Required
StatusForbidden403Forbidden
StatusNotFound404Not Found
StatusMethodNotAllowed405Method Not Allowed
StatusNotAcceptable406Not Acceptable
StatusProxyAuthRequired407Proxy Auth Required
StatusRequestTimeout408Request Timeout
StatusGone410Gone
StatusPreconditionFailed412Precondition Failed
StatusRequestEntityTooLarge413Request Entity Too Large
StatusRequestURITooLong414Request URI Too Long
StatusUnsupportedMediaType415Unsupported Media Type
StatusParameterNotUnderstood451Parameter Not Understood
StatusNotEnoughBandwidth453Not Enough Bandwidth
StatusSessionNotFound454Session Not Found
StatusMethodNotValidInThisState455Method Not Valid In This State
StatusHeaderFieldNotValidForResource456Header Field Not Valid for Resource
StatusInvalidRange457Invalid Range
StatusParameterIsReadOnly458Parameter Is Read-Only
StatusAggregateOperationNotAllowed459Aggregate Operation Not Allowed
StatusOnlyAggregateOperationAllowed460Only Aggregate Operation Allowed
StatusUnsupportedTransport461Unsupported Transport
StatusDestinationUnreachable462Destination Unreachable
StatusDestinationProhibited463Destination Prohibited
StatusDataTransportNotReadyYet464Data Transport Not Ready Yet
StatusNotificationReasonUnknown465Notification Reason Unknown
StatusKeyManagementError466Key Management Error
StatusConnectionAuthorizationRequired470Connection Authorization Required
StatusConnectionCredentialsNotAccepted471Connection Credentials Not Accepted
StatusFailureToEstablishSecureConnection472Failure to Establish Secure Connection

5xx Server errors

ConstantCodeReason
StatusInternalServerError500Internal Server Error
StatusNotImplemented501Not Implemented
StatusBadGateway502Bad Gateway
StatusServiceUnavailable503Service Unavailable
StatusGatewayTimeout504Gateway Timeout
StatusRTSPVersionNotSupported505RTSP Version Not Supported
StatusOptionNotSupported551Option Not Supported
StatusProxyUnavailable553Proxy Unavailable

Code example

Parsing a URL and constructing a response:
import (
    "bufio"
    "github.com/bluenviron/gortsplib/v5/pkg/base"
)

// Parse an RTSP URL
u, err := base.ParseURL("rtsp://admin:password@192.168.1.100:554/live")
if err != nil { ... }

fmt.Println(u.Hostname()) // "192.168.1.100"
fmt.Println(u.Port())     // "554"

// Build a response
res := &base.Response{
    StatusCode: base.StatusOK,
    Header: base.Header{
        "Content-Type": base.HeaderValue{"application/sdp"},
        "CSeq":         base.HeaderValue{"1"},
    },
    Body: sdpBytes,
}

buf, err := res.Marshal()

Build docs developers (and LLMs) love