streamer

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: MIT Imports: 11 Imported by: 0

README

streamer

Go Report Card GitHub last commit GitHub release

Go Package built around spinning up streaming processes

How

Stream exposes a struct called Stream which starts an underlying ffmpeg process to transcode incoming raw RTSP stream to HLS based on parameters.

It provides a handy interface to handle streams

More info on docs

Example usage

import "github.com/riltech/streamer"

func main() {
	stream, id := streamer.NewStream(
		"rtsp://admin:password@host.dyndns.org:447/Streaming/Channel/2", // URI of raw RTSP stream
		"./videos", // Directory where to store video chunks and indexes. Should exist already
		true, // Indicates if stream should be keeping files after it is stopped or clean the directory
		true, // Indicates if Audio should be enabled or not
		streamer.ProcessLoggingOpts{
			Enabled:    true, // Indicates if process logging is enabled
			Compress:   true, // Indicates if logs should be compressed
			Directory:  "/tmp/logs/stream", // Directory to store logs
			MaxAge:     0, // Max age for a log. 0 is infinite
			MaxBackups: 2, // Maximum backups to keep
			MaxSize:    500, // Maximum size of a log in megabytes
		},
		25*time.Second, // Time to wait before declaring a stream start failed
  )
  
  // Returns a waitGroup where the stream checking the underlying process for a successful start
  stream.Start().Wait() 
}

Updates

Added

-hls_flags +program_date_time

to have tag

EXT-X-PROGRAM-DATE-TIME

in m3u8 playlist to have possibility to see absolute time of stream fragment.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IProcess

type IProcess interface {
	Spawn(path, URI string) *exec.Cmd
}

IProcess is an interface around the FFMPEG process

type IStream

type IStream interface {
	Start() *sync.WaitGroup
	Restart() *sync.WaitGroup
	Stop() error
}

IStream is almost like icecream, that's why it is perfect

type Process

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

Process is the main type for creating new processes

func NewProcess

func NewProcess(
	keepFiles bool,
	audio bool,
) *Process

NewProcess creates a new process able to spawn transcoding FFMPEG processes

func (Process) Spawn

func (p Process) Spawn(path, URI string) *exec.Cmd

Spawn creates a new FFMPEG cmd

type ProcessLoggingOpts

type ProcessLoggingOpts struct {
	Enabled    bool   // Option to set logging for transcoding processes
	Directory  string // Directory for the logs
	MaxSize    int    // Maximum size of kept logging files in megabytes
	MaxBackups int    // Maximum number of old log files to retain
	MaxAge     int    // Maximum number of days to retain an old log file.
	Compress   bool   // Indicates if the log rotation should compress the log files
}

ProcessLoggingOpts describes options for process logging

type Stream

type Stream struct {
	ID          string               `json:"id"`
	Path        string               `json:"path"`
	Running     bool                 `json:"running"`
	CMD         *exec.Cmd            `json:"-"`
	Process     IProcess             `json:"-"`
	Mux         *sync.Mutex          `json:"-"`
	Streak      *hotstreak.Hotstreak `json:"-"`
	OriginalURI string               `json:"-"`
	StorePath   string               `json:"-"`
	KeepFiles   bool                 `json:"-"`
	LoggingOpts *ProcessLoggingOpts  `json:"-"`
	Logger      *lumberjack.Logger   `json:"-"`
	WaitTimeOut time.Duration        `json:"-"`
}

Stream describes a given host's streaming

func NewStream

func NewStream(
	URI string,
	storingDirectory string,
	keepFiles bool,
	audio bool,
	loggingOpts ProcessLoggingOpts,
	waitTimeOut time.Duration,
) (*Stream, string)

NewStream creates a new transcoding process for ffmpeg

func (*Stream) Restart

func (strm *Stream) Restart() *sync.WaitGroup

Restart restarts the given CMD

func (*Stream) Start

func (strm *Stream) Start() *sync.WaitGroup

Start is starting a new transcoding process

func (*Stream) Stop

func (strm *Stream) Stop() error

Stop makes sure that the transcoding process is killed correctly

Jump to

Keyboard shortcuts

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