live

package
v0.0.0-...-4543d8f Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 22 Imported by: 0

README

How To

Test - capture MPEG-TS and create mezzanine test files

Terminal A

cd ./live
go test --run TestUdpToMp4V2

Terminal B

.../udpreplay --use-timestamps --host 127.0.0.1 --port 21001 test-file.cap

Appendix

Install udpreplay

Mac prerequisites

  • brew install boost autoconf automake libtool
  git clone git@github.com:elv-serban/udpreplay.git
  ./bootsrap.sh
  ./configure
  make
Encoding parameters - FS-1 MPGEG-TS UDP cap files

	audioParamsTs := &avpipe.TxParams{
		Format:          "fmp4-segment",
		Seekable:        false,
		DurationTs:      -1,
		StartSegmentStr: "1",
		AudioBitrate:    384000, // FS1-19-10-14.ts audio bitrate
		SegDurationTs:   -1,
		SegDuration:     "30.03", // seconds
		Dcodec:          "ac3",
		Ecodec:          "aac", // "aac"
		TxType:          avpipe.TxAudio,
		SampleRate:      48000,
		AudioIndex:      -0,
	}

	videoParamsTs := &avpipe.TxParams{
		Format:          "fmp4-segment",
		Seekable:        false,
		DurationTs:      -1,
		StartSegmentStr: "1",
		VideoBitrate:    20000000, // fox stream bitrate
		SegDurationTs:   -1,
		ForceKeyInt:     120,
		SegDuration:     "30.03",   // seconds
		Ecodec:          "libx264", // libx264 software / h264_videotoolbox mac hardware
		EncHeight:       720,
		EncWidth:        1280,
		TxType:          avpipe.TxVideo,
	}

Documentation

Index

Constants

View Source
const RTMP_SOURCE = "rtmp://localhost:%d/rtmp/Doj1Nr3S"

Variables

View Source
var TESTSaveToDir string

TESTSaveToDir save manifests and segments to this path if not empty string

Functions

func NewRWBuffer

func NewRWBuffer(capacity int) io.ReadWriteCloser

* Creates a RWBuffer which is open for reading/writing. * The writer can write to the buffer until Close(RWBufferWriteClosed) is called. * The reader can read from the buffer until Close(RWBufferReadClosed) is called or * EOF is issued. * An EOF is issued for reader when the writer closed the buffer and there is no data * in the buffer.

Types

type HLSReader

type HLSReader struct {
	Pipe io.ReadWriteCloser //
	Type avpipe.XcType      //
	// contains filtered or unexported fields
}

HLSReader provides a reader interface to an HLS playlist that serves a live MPEG-TS stream. Close the Pipe to clean up.

An HLS playlist may have zero or more audio and video streams. We choose the highest bitrate stream of each type to record. If the master playlist advertises a muxed stream with both audio and video, choose the muxed stream with the highest bitrate.

func NewHLSReader

func NewHLSReader(playlistURL *url.URL, xcType avpipe.XcType) *HLSReader

NewHLSReader creates and returns a media playlist reader, and starts goroutines to download the segments. Close the Reader to clean up.

func NewHLSReaderA

func NewHLSReaderA(a *m3u8.Alternative, masterPlaylistURL *url.URL) (
	lhr *HLSReader, err error)

func NewHLSReaderV

func NewHLSReaderV(v *m3u8.Variant, masterPlaylistURL *url.URL, xcType avpipe.XcType) (
	lhr *HLSReader, err error)

func NewHLSReaders

func NewHLSReaders(playlistURL *url.URL, xcType avpipe.XcType) (
	readers []*HLSReader, err error)

Determines readers based on the desired stream type and the playlistURL, which can be either a master playlist or media playlist.

Read master playlists only once (section 6.3.4 of the spec only says to reload *media* playlists. Also, some servers will return a new session token with each HTTP request for the master, but the same token must be used to maintain playback state.

TODO Probably should change approach to selecting a variant first, then finding the audio/video streams. Also test against different playlists.

func (*HLSReader) Start

func (lhr *HLSReader) Start(endChan chan<- error)

type LiveSource

type LiveSource struct {
	Port int `json:"port,omitempty"`
	Pid  int `json:"pid,omitempty"`
	// contains filtered or unexported fields
}

func NewLiveSource

func NewLiveSource() *LiveSource

func (*LiveSource) Start

func (l *LiveSource) Start(stream string) (err error)

func (*LiveSource) Stop

func (l *LiveSource) Stop() (err error)

type RWBuffer

type RWBuffer struct {
	// contains filtered or unexported fields
}

func (*RWBuffer) Close

func (rwb *RWBuffer) Close() error

io.Closer

func (*RWBuffer) CloseSide

func (rwb *RWBuffer) CloseSide(state RWBufferCloseState) error

func (*RWBuffer) Len

func (rwb *RWBuffer) Len() int

func (*RWBuffer) Read

func (rwb *RWBuffer) Read(buf []byte) (n int, err error)

* Reads one packet at a time into buf. * It is possible avpipe asks for data even less than a packet size, which can cause a partial read. * RWBuffer can keep track of a partial read and will return the rest of the packet in next Read() call.

func (*RWBuffer) Size

func (rwb *RWBuffer) Size() int

func (*RWBuffer) Write

func (rwb *RWBuffer) Write(buf []byte) (n int, err error)

* It simply makes a copy from buf and enqueues the new copy of buf. * For more improvemnt it can avoid copying buffer buf by passing the ownership of buffer buf to rwb (RM).

type RWBufferCloseState

type RWBufferCloseState int
const (
	RWBufferOpen RWBufferCloseState = iota
	RWBufferReadClosed
	RWBufferWriteClosed
	RWBufferClosed
)

type TsReader

type TsReader struct {
	ErrChannel chan error
	// contains filtered or unexported fields
}

func NewTsReader

func NewTsReader(addr string, w io.Writer) *TsReader

Deprecated

func NewTsReaderV2 deprecated

func NewTsReaderV2(addr string) (*TsReader, io.ReadWriteCloser, error)

Deprecated: Reading UDP datagrams are done inside avpipe library and no need to create TsReader anymore (this makes handling different situations like stopping and cancelling a stream extremely difficult). NewTsReaderV2 creates a UDP MPEG-TS reader and returns a TsReader and an io.Reader Starts the necessary goroutines - when the returned reader is closed, it stops all goroutines and cleans up.

func (*TsReader) Close

func (tsr *TsReader) Close()

Jump to

Keyboard shortcuts

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