gohlslib

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 24 Imported by: 5

README

gohlslib

Test Lint Go Report Card CodeCov PkgGoDev

HLS client and muxer library for the Go programming language.

Go ≥ 1.18 is required.

This library was forked from MediaMTX, it is currently in alpha stage and implements only the features strictly needed by MediaMTX, but the aim is implementing a wide range of features that allow to read and generate HLS streams.

Client features:

name state
Read MPEG-TS streams OK
Read fMP4 streams OK
Read Low-latency streams TODO
Read H264 tracks OK
Read H265 tracks OK
Read MPEG4 Audio (AAC) tracks OK
Read Opus tracks OK
Read a given variant TODO (currently a single variant is read)

Muxer features:

name state
Generate MPEG-TS streams OK
Generate fMP4 streams OK
Generate Low-latency streams OK
Write H264 tracks OK
Write H265 tracks OK
Write MPEG4 Audio (AAC) tracks OK
Write Opus tracks OK
Save generated segments on disk OK
Generate multi-variant streams TODO

General features:

name state
Parse and produce M3U8 playlists OK
Examples OK

Table of contents

Examples

API Documentation

https://pkg.go.dev/github.com/bluenviron/gohlslib#pkg-index

Standards

Related projects

Documentation

Overview

Package gohlslib is a HLS client and muxer library for the Go programming language.

Examples are available at https://github.com/bluenviron/gohlslib/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 {
	//
	// Parameters (all optional except URI)
	//
	// URI of the playlist.
	URI string
	// HTTP client.
	// It defaults to http.DefaultClient.
	HTTPClient *http.Client
	// function that receives log messages.
	// It defaults to log.Printf.
	Log LogFunc
	// contains filtered or unexported fields
}

Client is a HLS client.

func (*Client) Close

func (c *Client) Close()

Close closes all the Client resources.

func (*Client) OnData

func (c *Client) OnData(forma *Track, cb func(time.Duration, interface{}))

OnData sets a callback that is called when data arrives.

func (*Client) OnTracks

func (c *Client) OnTracks(cb func([]*Track) error)

OnTracks sets a callback that is called when tracks are read.

func (*Client) Start

func (c *Client) Start() error

Start starts the client.

func (*Client) Wait

func (c *Client) Wait() chan error

Wait waits for any error of the Client.

type LogFunc

type LogFunc func(level LogLevel, format string, args ...interface{})

LogFunc is the prototype of the log function.

type LogLevel

type LogLevel int

LogLevel is a log level.

const (
	LogLevelDebug LogLevel = iota + 1
	LogLevelInfo
	LogLevelWarn
	LogLevelError
)

Log levels.

type Muxer

type Muxer struct {
	//
	// parameters (all optional except VideoTrack or AudioTrack).
	//
	// video track.
	VideoTrack *Track
	// audio track.
	AudioTrack *Track
	// Variant to use.
	// It defaults to MuxerVariantLowLatency
	Variant MuxerVariant
	// Number of HLS segments to keep on the server.
	// Segments allow to seek through the stream.
	// Their number doesn't influence latency.
	// It defaults to 7.
	SegmentCount int
	// Minimum duration of each segment.
	// A player usually puts 3 segments in a buffer before reproducing the stream.
	// The final segment duration is also influenced by the interval between IDR frames,
	// since the server changes the duration in order to include at least one IDR frame
	// in each segment.
	// It defaults to 1sec.
	SegmentDuration time.Duration
	// Minimum duration of each part.
	// Parts are used in Low-Latency HLS in place of segments.
	// A player usually puts 3 parts in a buffer before reproducing the stream.
	// Part duration is influenced by the distance between video/audio samples
	// and is adjusted in order to produce segments with a similar duration.
	// It defaults to 200ms.
	PartDuration time.Duration
	// Maximum size of each segment.
	// This prevents RAM exhaustion.
	// It defaults to 50MB.
	SegmentMaxSize uint64
	// Directory in which to save segments.
	// This decreases performance, since saving segments on disk is less performant
	// than saving them on RAM, but allows to preserve RAM.
	Directory string
	// contains filtered or unexported fields
}

Muxer is a HLS muxer.

func (*Muxer) Close

func (m *Muxer) Close()

Close closes a Muxer.

func (*Muxer) Handle added in v0.2.0

func (m *Muxer) Handle(w http.ResponseWriter, r *http.Request)

Handle handles a HTTP request.

func (*Muxer) Start

func (m *Muxer) Start() error

Start initializes the muxer.

func (*Muxer) WriteAudio

func (m *Muxer) WriteAudio(ntp time.Time, pts time.Duration, au []byte) error

WriteAudio writes an audio access unit.

func (*Muxer) WriteH26x

func (m *Muxer) WriteH26x(ntp time.Time, pts time.Duration, au [][]byte) error

WriteH26x writes an H264 or an H265 access unit.

type MuxerVariant

type MuxerVariant int

MuxerVariant is a muxer variant.

const (
	MuxerVariantMPEGTS MuxerVariant = iota + 1
	MuxerVariantFMP4
	MuxerVariantLowLatency
)

supported variants.

type Track

type Track struct {
	codecs.Codec
}

Track is a HLS track.

Directories

Path Synopsis
examples
client command
muxer command
playlist-parser command
pkg
codecparams
Package codecparams contains utilities to deal with codec parameters.
Package codecparams contains utilities to deal with codec parameters.
codecs
Package codecs contains codec definitions.
Package codecs contains codec definitions.
fmp4
Package fmp4 contains a fMP4 reader and writer.
Package fmp4 contains a fMP4 reader and writer.
playlist
Package playlist contains a M3U8 playlist decoder and encoder.
Package playlist contains a M3U8 playlist decoder and encoder.
playlist/primitives
Package primitives contains playlist primitives.
Package primitives contains playlist primitives.
storage
Package storage contains the storage mechanism of segments and parts.
Package storage contains the storage mechanism of segments and parts.

Jump to

Keyboard shortcuts

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