Documentation
¶
Overview ¶
Package rtmpav moves media between goav and RTMP and RTMPS peers: publishing to YouTube, Twitch, or a local MediaMTX or nginx-rtmp, playing from them, and taking OBS's publish. RTMP is the protocol here, in the standard library alone (the handshake, signed and simple, the chunk stream, AMF0 commands, and Enhanced RTMP's codec negotiation); the media is FLV, which goav's container/flv reads and writes, Enhanced RTMP's HEVC, AV1, VP9, Opus, and multitrack included.
RTMP is the rtmp and rtmps URL scheme, registered with runconfig.Scheme: goav.URI publishes, goav.URIInput plays. Listen is an ingest server whose Input is the live input of one stream.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCodecRefused reports a stream in a codec the server does not take: // it negotiated Enhanced RTMP and listed codecs without this one. Encode // the stream to H.264 or AAC, which every server takes. ErrCodecRefused = errors.New("rtmpav: the server does not take the codec") // ErrStreamEnded reports a live stream whose publisher stopped or // dropped; goav.Reconnect waits for the next. ErrStreamEnded = errors.New("rtmpav: the live stream ended") )
Functions ¶
func RTMP ¶
RTMP is the rtmp and rtmps scheme, an RTMP client for goav.URIInput and goav.URI. Register it under both names:
rtmp := rtmpav.RTMP()
runconfig.Scheme("rtmp", rtmp), runconfig.Scheme("rtmps", rtmp)
A URL names the server, the application, and the stream key: rtmp://host[:port]/app/key, the port 1935 by default and 443 for rtmps, which runs over TLS. A query belongs to the key, as the services that sign keys with one expect.
goav.URI publishes. The destination takes H.264, HEVC, AV1, and VP9 video and AAC, Opus, and FLAC audio packets, and encodes frames to H.264 and AAC, which every server reads. When the run opens it, it connects, offers the Enhanced RTMP codecs, and publishes; a server that answers with the codecs it takes refuses the others with ErrCodecRefused, and one that answers with none is sent what the streams carry. It publishes live: a file routed to it plays at its media time.
goav.URIInput plays a live stream: FLV over RTMP, which the runtime demuxes, Enhanced RTMP included. A publisher that stops ends it with ErrStreamEnded, which goav.Reconnect recovers from, and a read that waits 30s for media fails. A refused connect, publish, or play is a *StatusError.
goav reports the URL with its stream key redacted, as it does userinfo and secret query values; only this scheme sees it.
Types ¶
type Option ¶
type Option func(*config)
Option configures RTMP and Listen.
func WithTLSConfig ¶
WithTLSConfig sets the TLS configuration: the roots and server name an rtmps client trusts (the system's by default), or the certificates that make Listen serve rtmps.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an RTMP ingest: it accepts publishers (OBS, ffmpeg, another goav task publishing rtmp://) and hands each to the live input of its stream. Only the streams an Input names are taken, so the stream key is the publisher's credential.
func Listen ¶
Listen accepts RTMP publishers on addr, or rtmps ones when WithTLSConfig gives it certificates. Close stops it.
The server answers the signed and the simple handshake, connect with the Enhanced RTMP codecs and multitrack goav reads, and createStream and publish for the streams an Input names; it refuses a play, and a publish to a stream no Input names or another publisher holds, with NetStream.Publish.BadName.
func (*Server) Close ¶
Close stops accepting, ends every publish, and wakes the inputs waiting for one.
type StatusError ¶
StatusError is a server's refusal: the command it answered with _error or an error-level onStatus, and the code and description it gave, the stream key replaced wherever the description repeats it.
func (*StatusError) Error ¶
func (e *StatusError) Error() string