gortmplib

package module
v0.0.0-...-da15235 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 28 Imported by: 0

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.24 is required.

Features:

  • Read and write multiple video and audio tracks
  • Read and write tracks encoded with AV1, VP9, H265, H264, Opus, 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)

Current limitations:

  • API is not stable and might be subjected to breaking changes.
  • Codec definitions are borrowed from gortsplib. They will be made independent in the future.

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/codekami45/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 {
	URL       *url.URL
	TLSConfig *tls.Config
	Publish   bool
	// 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 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 *format.AC3, cb OnDataAC3Func)

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

func (*Reader) OnDataAV1

func (r *Reader) OnDataAV1(track *format.AV1, cb OnDataAV1Func)

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

func (*Reader) OnDataG711

func (r *Reader) OnDataG711(track *format.G711, cb OnDataG711Func)

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

func (*Reader) OnDataH264

func (r *Reader) OnDataH264(track *format.H264, cb OnDataH26xFunc)

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

func (*Reader) OnDataH265

func (r *Reader) OnDataH265(track *format.H265, cb OnDataH26xFunc)

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

func (*Reader) OnDataLPCM

func (r *Reader) OnDataLPCM(track *format.LPCM, cb OnDataLPCMFunc)

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

func (*Reader) OnDataMPEG1Audio

func (r *Reader) OnDataMPEG1Audio(track *format.MPEG1Audio, cb OnDataMPEG1AudioFunc)

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

func (*Reader) OnDataMPEG4Audio

func (r *Reader) OnDataMPEG4Audio(track *format.MPEG4Audio, cb OnDataMPEG4AudioFunc)

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

func (*Reader) OnDataOpus

func (r *Reader) OnDataOpus(track *format.Opus, cb OnDataOpusFunc)

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

func (*Reader) OnDataVP9

func (r *Reader) OnDataVP9(track *format.VP9, 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() []format.Format

Tracks returns detected tracks

type ServerConn

type ServerConn struct {
	RW io.ReadWriter

	FourCcList amf0.StrictArray

	// 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 Writer

type Writer struct {
	Conn   Conn
	Tracks []format.Format
	// 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 *format.AC3, pts time.Duration, frame []byte) error

WriteAC3 writes an AC-3 frame.

func (*Writer) WriteAV1

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

WriteAV1 writes a AV1 temporal unit.

func (*Writer) WriteG711

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

WriteG711 writes G711 samples.

func (*Writer) WriteH264

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

WriteH264 writes a H264 access unit.

func (*Writer) WriteH265

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

WriteH265 writes a H265 access unit.

func (*Writer) WriteLPCM

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

WriteLPCM writes LPCM samples.

func (*Writer) WriteMPEG1Audio

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

WriteMPEG1Audio writes a MPEG-1 Audio frame.

func (*Writer) WriteMPEG4Audio

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

WriteMPEG4Audio writes a MPEG-4 Audio access unit.

func (*Writer) WriteOpus

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

WriteOpus writes a Opus packet.

func (*Writer) WriteVP9

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

WriteVP9 writes a VP9 frame.

Directories

Path Synopsis
examples
client-publish-264 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.
h264conf
Package h264conf contains a H264 configuration parser.
Package h264conf contains a H264 configuration parser.
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