gortmplib

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 26 Imported by: 1

README

gortmplib

Test Lint Go Report Card CodeCov PkgGoDev

RTMP client and server library for the Go programming language, forked from MediaMTX.

This was created to provide Enhanced RTMP features, like multiple video/audio tracks and additional codecs.

Go ≥ 1.25 is required.

Features:

  • Read and write multiple video and audio tracks
  • Read and write tracks encoded with AV1, VP9, H265, H264, Opus, FLAC, MPEG-4 Audio (AAC), MPEG-1/2 Audio (MP3), AC-3, G711 (PCMA, PCMU), LPCM
  • Support most Enhanced RTMP features
  • Support TLS encryption (RTMPS)
  • Support Diffie-hellman based encryption (RTMPE)
  • Support encoding and decoding data with the AMF0 format

WARNING: API is not stable and might be subjected to breaking changes.

Table of contents

Examples

API Documentation

Click to open the API Documentation

Specifications

name area
Action Message Format - AMF0 RTMP
FLV RTMP
RTMP RTMP
Enhanced RTMP v2 RTMP
Codec specifications codecs
Golang project layout project layout

Documentation

Overview

Package gortmplib is a RTMP library for the Go programming language.

Examples are available at https://github.com/bluenviron/gortmplib/tree/main/examples

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	//
	// Target
	//
	// URL of the RTMP server to connect to.
	URL *url.URL
	// Whether to publish or play.
	Publish bool

	//
	// RTMP parameters (all optional)
	//
	// a TLS configuration to connect to RTMPS servers.
	// It defaults to nil.
	TLSConfig *tls.Config

	//
	// system functions (all optional)
	//
	// function used to initialize the TCP client.
	// It defaults to (&net.Dialer{}).DialContext.
	DialContext func(ctx context.Context, network, address string) (net.Conn, error)
	// function used to initialize a TLS connection.
	// When nil, DialContext and tls.Client are used in its place.
	// It defaults to nil.
	DialTLSContext func(ctx context.Context, network string, addr string) (net.Conn, error)
	// contains filtered or unexported fields
}

Client is a client-side RTMP connection.

func (*Client) BytesReceived

func (c *Client) BytesReceived() uint64

BytesReceived returns the number of bytes received.

func (*Client) BytesSent

func (c *Client) BytesSent() uint64

BytesSent returns the number of bytes sent.

func (*Client) Close

func (c *Client) Close()

Close closes the connection.

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context) error

Initialize initializes Client.

func (*Client) NetConn

func (c *Client) NetConn() net.Conn

NetConn returns the underlying net.Conn.

func (*Client) Read

func (c *Client) Read() (message.Message, error)

Read reads a message.

func (*Client) Write

func (c *Client) Write(msg message.Message) error

Write writes a message.

type Conn

type Conn interface {
	BytesReceived() uint64
	BytesSent() uint64
	Read() (message.Message, error)
	Write(msg message.Message) error
}

Conn is implemented by Client and ServerConn.

type OnDataAC3Func

type OnDataAC3Func func(pts time.Duration, frame []byte)

OnDataAC3Func is the prototype of the callback passed to OnDataAC3().

type OnDataAV1Func

type OnDataAV1Func func(pts time.Duration, tu [][]byte)

OnDataAV1Func is the prototype of the callback passed to OnDataAV1().

type OnDataFLACFunc added in v0.4.0

type OnDataFLACFunc func(pts time.Duration, frame []byte)

OnDataFLACFunc is the prototype of the callback passed to OnDataFLAC().

type OnDataG711Func

type OnDataG711Func func(pts time.Duration, samples []byte)

OnDataG711Func is the prototype of the callback passed to OnDataG711().

type OnDataH26xFunc

type OnDataH26xFunc func(pts time.Duration, dts time.Duration, au [][]byte)

OnDataH26xFunc is the prototype of the callback passed to OnDataH26x().

type OnDataLPCMFunc

type OnDataLPCMFunc func(pts time.Duration, samples []byte)

OnDataLPCMFunc is the prototype of the callback passed to OnDataLPCM().

type OnDataMPEG1AudioFunc

type OnDataMPEG1AudioFunc func(pts time.Duration, frame []byte)

OnDataMPEG1AudioFunc is the prototype of the callback passed to OnDataMPEG1Audio().

type OnDataMPEG4AudioFunc

type OnDataMPEG4AudioFunc func(pts time.Duration, au []byte)

OnDataMPEG4AudioFunc is the prototype of the callback passed to OnDataMPEG4Audio().

type OnDataOpusFunc

type OnDataOpusFunc func(pts time.Duration, packet []byte)

OnDataOpusFunc is the prototype of the callback passed to OnDataOpus().

type OnDataVP9Func

type OnDataVP9Func func(pts time.Duration, frame []byte)

OnDataVP9Func is the prototype of the callback passed to OnDataVP9().

type Reader

type Reader struct {
	Conn Conn
	// contains filtered or unexported fields
}

Reader provides functions to read incoming data.

func (*Reader) Initialize

func (r *Reader) Initialize() error

Initialize initializes Reader.

func (*Reader) OnDataAC3

func (r *Reader) OnDataAC3(track *Track, cb OnDataAC3Func)

OnDataAC3 sets a callback that is called when AC-3 data is received.

func (*Reader) OnDataAV1

func (r *Reader) OnDataAV1(track *Track, cb OnDataAV1Func)

OnDataAV1 sets a callback that is called when AV1 data is received.

func (*Reader) OnDataFLAC added in v0.4.0

func (r *Reader) OnDataFLAC(track *Track, cb OnDataFLACFunc)

OnDataFLAC sets a callback that is called when FLAC data is received.

func (*Reader) OnDataG711

func (r *Reader) OnDataG711(track *Track, cb OnDataG711Func)

OnDataG711 sets a callback that is called when G711 data is received.

func (*Reader) OnDataH264

func (r *Reader) OnDataH264(track *Track, cb OnDataH26xFunc)

OnDataH264 sets a callback that is called when H264 data is received.

func (*Reader) OnDataH265

func (r *Reader) OnDataH265(track *Track, cb OnDataH26xFunc)

OnDataH265 sets a callback that is called when H265 data is received.

func (*Reader) OnDataLPCM

func (r *Reader) OnDataLPCM(track *Track, cb OnDataLPCMFunc)

OnDataLPCM sets a callback that is called when LPCM data is received.

func (*Reader) OnDataMPEG1Audio

func (r *Reader) OnDataMPEG1Audio(track *Track, cb OnDataMPEG1AudioFunc)

OnDataMPEG1Audio sets a callback that is called when MPEG-1 Audio data is received.

func (*Reader) OnDataMPEG4Audio

func (r *Reader) OnDataMPEG4Audio(track *Track, cb OnDataMPEG4AudioFunc)

OnDataMPEG4Audio sets a callback that is called when MPEG-4 Audio data is received.

func (*Reader) OnDataOpus

func (r *Reader) OnDataOpus(track *Track, cb OnDataOpusFunc)

OnDataOpus sets a callback that is called when Opus data is received.

func (*Reader) OnDataVP9

func (r *Reader) OnDataVP9(track *Track, cb OnDataVP9Func)

OnDataVP9 sets a callback that is called when VP9 data is received.

func (*Reader) Read

func (r *Reader) Read() error

Read reads data.

func (*Reader) Tracks

func (r *Reader) Tracks() []*Track

Tracks returns detected tracks

type ServerConn

type ServerConn struct {
	RW io.ReadWriter

	FourCcList amf0.StrictArray
	FlashVer   string

	// filled by Accept
	URL     *url.URL
	Publish bool
	// contains filtered or unexported fields
}

ServerConn is a server-side RTMP connection.

func (*ServerConn) Accept

func (c *ServerConn) Accept() error

Accept accepts the connection.

func (*ServerConn) BytesReceived

func (c *ServerConn) BytesReceived() uint64

BytesReceived returns the number of bytes received.

func (*ServerConn) BytesSent

func (c *ServerConn) BytesSent() uint64

BytesSent returns the number of bytes sent.

func (*ServerConn) CheckCredentials

func (c *ServerConn) CheckCredentials(expectedUser string, expectedPass string) error

CheckCredentials checks credentials.

func (*ServerConn) Initialize

func (c *ServerConn) Initialize() error

Initialize initializes ServerConn.

func (*ServerConn) Read

func (c *ServerConn) Read() (message.Message, error)

Read reads a message.

func (*ServerConn) Write

func (c *ServerConn) Write(msg message.Message) error

Write writes a message.

type Track added in v0.2.0

type Track struct {
	Codec codecs.Codec
}

Track is a track.

type Writer

type Writer struct {
	Conn   Conn
	Tracks []*Track
	// contains filtered or unexported fields
}

Writer provides functions to write outgoing data.

func (*Writer) Initialize

func (w *Writer) Initialize() error

Initialize initializes Writer.

func (*Writer) WriteAC3

func (w *Writer) WriteAC3(track *Track, pts time.Duration, frame []byte) error

WriteAC3 writes an AC-3 frame.

func (*Writer) WriteAV1

func (w *Writer) WriteAV1(track *Track, pts time.Duration, tu [][]byte) error

WriteAV1 writes a AV1 temporal unit.

func (*Writer) WriteFLAC added in v0.4.0

func (w *Writer) WriteFLAC(track *Track, pts time.Duration, frame []byte) error

WriteFLAC writes a FLAC frame.

func (*Writer) WriteG711

func (w *Writer) WriteG711(track *Track, pts time.Duration, samples []byte) error

WriteG711 writes G711 samples.

func (*Writer) WriteH264

func (w *Writer) WriteH264(track *Track, pts time.Duration, dts time.Duration, au [][]byte) error

WriteH264 writes a H264 access unit.

func (*Writer) WriteH265

func (w *Writer) WriteH265(track *Track, pts time.Duration, dts time.Duration, au [][]byte) error

WriteH265 writes a H265 access unit.

func (*Writer) WriteLPCM

func (w *Writer) WriteLPCM(track *Track, pts time.Duration, samples []byte) error

WriteLPCM writes LPCM samples.

func (*Writer) WriteMPEG1Audio

func (w *Writer) WriteMPEG1Audio(track *Track, pts time.Duration, frame []byte) error

WriteMPEG1Audio writes a MPEG-1 Audio frame.

func (*Writer) WriteMPEG4Audio

func (w *Writer) WriteMPEG4Audio(track *Track, pts time.Duration, au []byte) error

WriteMPEG4Audio writes a MPEG-4 Audio access unit.

func (*Writer) WriteOpus

func (w *Writer) WriteOpus(track *Track, pts time.Duration, pkt []byte) error

WriteOpus writes a Opus packet.

func (*Writer) WriteVP9

func (w *Writer) WriteVP9(track *Track, pts time.Duration, frame []byte) error

WriteVP9 writes a VP9 frame.

Directories

Path Synopsis
examples
client-publish-h264 command
Package main contains an example.
Package main contains an example.
client-publish-mpeg4audio command
Package main contains an example.
Package main contains an example.
client-read command
Package main contains an example.
Package main contains an example.
server command
Package main contains an example.
Package main contains an example.
pkg
amf0
Package amf0 contains an AMF0 decoder and encoder.
Package amf0 contains an AMF0 decoder and encoder.
bytecounter
Package bytecounter contains a reader/writer that allows to count bytes.
Package bytecounter contains a reader/writer that allows to count bytes.
chunk
Package chunk implements RTMP chunks.
Package chunk implements RTMP chunks.
codecs
Package codecs contains codec definitions.
Package codecs contains codec definitions.
handshake
Package handshake contains the RTMP handshake mechanism.
Package handshake contains the RTMP handshake mechanism.
message
Package message contains a RTMP message reader/writer.
Package message contains a RTMP message reader/writer.
rawmessage
Package rawmessage contains a RTMP raw message reader/writer.
Package rawmessage contains a RTMP raw message reader/writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL