Documentation ¶
Overview ¶
Package process is a wrapper of exec.Cmd for controlling a ffmpeg process. It could be used to run other executables but it is tailored to the specifics of ffmpeg, e.g. only stderr is captured, and some exit codes != 0 plus certain signals are still considered as a non-error exit condition.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Binary string // Path to the ffmpeg binary Args []string // List of arguments for the binary Reconnect bool // Whether to restart the process if it exited ReconnectDelay time.Duration // Duration to wait before restarting the process StaleTimeout time.Duration // Kill the process after this duration if it doesn't produce any output LimitCPU float64 // Kill the process if the CPU usage in percent is above this value LimitMemory uint64 // Kill the process if the memory consumption in bytes is above this value LimitDuration time.Duration // Kill the process if the limits are exceeded for this duration Parser Parser // A parser for the output of the process OnStart func() // A callback which is called after the process started OnExit func() // A callback which is called after the process exited OnStateChange func(from, to string) // A callback which is called after a state changed Logger log.Logger }
Config is the configuration of a process
type Limiter ¶
type Limiter interface { // Start starts the limiter with a psutil.Process. Start(process psutil.Process) error // Stop stops the limiter. The limiter can be reused by calling Start() again Stop() // Current returns the current CPU and memory values Current() (cpu float64, memory uint64) // Limits returns the defined CPU and memory limits. Values < 0 means no limit Limits() (cpu float64, memory uint64) }
type LimiterConfig ¶
type Line ¶
Line represents a line from the output with its timestamp. The line doesn't include any newline character.
type Parser ¶
type Parser interface { // Parse parses the given line and returns an indicator // for progress (e.g. based on the contents of the line, // or previous line, ...) Parse(line string) uint64 // Reset resets any collected statistics or temporary data. // This is called before the process starts and after the // process stopped. The stats are meant to be collected // during the runtime of the process. ResetStats() // ResetLog resets any collected logs. This is called // before the process starts. ResetLog() // Log returns a slice of collected log lines Log() []Line }
Parser is an interface that is accepted by a process for parsing the process' output.
func NewNullParser ¶
func NewNullParser() Parser
NewNullParser returns a dummy parser that isn't doing anything and always returns progress.
type Process ¶
type Process interface { // Status returns the current status of this process Status() Status // Start starts the process. If the process stops by itself // it will restart automatically if it is defined to do so. Start() error // Stop stops the process and will not let it restart // automatically. Stop(wait bool) error // Kill stops the process such that it will restart // automatically if it is defined to do so. Kill(wait bool) error // IsRunning returns whether the process is currently // running or not. IsRunning() bool }
Process represents a process and ways to control it and to extract information.
type Status ¶
type Status struct { State string // State is the current state of the process. See stateType for the known states. States States // States is the cumulative history of states the process had. Order string // Order is the wanted condition of process, either "start" or "stop" Duration time.Duration // Duration is the time since the last change of the state Time time.Time // Time is the time of the last change of the state CPU struct { Current float64 // Used CPU in percent Limit float64 // Limit in percent } Memory struct { Current uint64 // Used memory in bytes Limit uint64 // Limit in bytes } }
Status represents the current status of a process