encoding

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Encoding plan configuration related abstractions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EncoderCmd

type EncoderCmd struct {
	// Name of encoding
	Name string
	// SourceFile is uncompressed video source aka mezzanine file
	SourceFile string
	// CompressedFile is a result of compressing InputFile
	CompressedFile string
	// OutputFile contains text output generated from encoder (log output)
	OutputFile string
	// LogFile is additional log file that encoder may generate
	LogFile string
	// WorkDir contains current working directory (a.k.a CWD, PWD)
	WorkDir string
	// Cmd is a actual "executable" encoder commandline with parameters
	Cmd string
}

EncoderCmd defines an encoder command struct.

func (*EncoderCmd) Run

func (s *EncoderCmd) Run() RunResult

Run will run all encoding commands defined for this Plan.

Error is nil if all encoding commands succeed without errors.

TODO: After refactoring lost the ability to control output io.Writer. Maybe need to add option to pass in own io.Writer (for testing purposes?)

type Plan

type Plan struct {
	// Embed PlanConfig struct
	PlanConfig
	// Executable encoder commands
	Commands []EncoderCmd
	// Output directory
	OutDir string
	// contains filtered or unexported fields
}

func NewPlan

func NewPlan(pc PlanConfig, outDir string) Plan

NewPlan will create Plan instance from given PlanConfig.

func (*Plan) Run

func (s *Plan) Run() (PlanResult, error)

Run executes encoding commands part of this Plan.

type PlanConfig

type PlanConfig struct {
	// List of source (mezzanine) video files.
	Inputs  []string
	Schemes []Scheme
}

PlanConfig holds configuration for new Plan creation.

func NewPlanConfigFromJSON

func NewPlanConfigFromJSON(jdoc []byte) (PlanConfig, error)

NewPlanConfigFromJSON will unmarshal JSON into PlanConfig instance.

func (*PlanConfig) IsValid

func (p *PlanConfig) IsValid() (bool, error)

type PlanConfigError

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

PlanConfigError error type defines PlanConfig validation failures.

func (*PlanConfigError) Error

func (e *PlanConfigError) Error() string

func (*PlanConfigError) Reasons

func (e *PlanConfigError) Reasons() []string

type PlanResult

type PlanResult struct {
	StartTime  time.Time
	EndTime    time.Time
	RunResults []RunResult
}

PlanResult holds Plan execution result state.

type RunResult

type RunResult struct {
	EncoderCmd
	Errors []error

	Stats            UsageStat
	VideoDuration    float64
	AvgEncodingSpeed float64
	// contains filtered or unexported fields
}

RunResult contains a status of a single encoding run.

func (*RunResult) AddError

func (s *RunResult) AddError(e error)

func (*RunResult) ExitCode

func (s *RunResult) ExitCode() int

ExitCode returns exit code of executed encoding run.

func (*RunResult) Output

func (s *RunResult) Output() string

Output returns output from encoding run.

For encoders Stdout is usually reserved for piping encoded stream, so diagnostics output usually goes to Stderr.

func (*RunResult) Rusage

func (s *RunResult) Rusage() *syscall.Rusage

type Scheme

type Scheme struct {
	Name       string
	CommandTpl string
}

Scheme is an encoder string with input and output placeholders.

For now it is just an encoding command line string with placeholders for input and output file. Like ffmpeg command with flags.

A Name field will be used when generating output file, so use it sensibly - think of it as as part of some nomenclature scheme.

func (*Scheme) Expand

func (s *Scheme) Expand(sourceFiles []string, outDir string) (cmds []EncoderCmd)

Expand will generate complete encoding commands based on provided "context".

"Context" being input/source files and output directory.

TODO: Not sure about the name Expand(). Also, function body looks busy.

func (*Scheme) MarshalJSON added in v0.3.7

func (s *Scheme) MarshalJSON() ([]byte, error)

MarshalJSON implement Marshaler interface for Scheme type.

func (*Scheme) UnmarshalJSON

func (s *Scheme) UnmarshalJSON(data []byte) error

UnmarshalJSON implement Unmarshaler interface for Scheme type.

type UsageStat

type UsageStat struct {
	// Human friendly representations of time duration
	HStime   string
	HUtime   string
	HElapsed string
	// time.Duration is nanoseconds
	Stime   time.Duration
	Utime   time.Duration
	Elapsed time.Duration
	// MaxRss is KB
	MaxRss int64
}

UsageStat contains process resource usage stats.

func NewUsageStat

func NewUsageStat(elapsed time.Duration, rusage *syscall.Rusage) UsageStat

NewUsageStat will create UsageStat instance.

func (*UsageStat) CPUPercent

func (s *UsageStat) CPUPercent() float64

CPUPercent calculates CPU usage in percent.

Jump to

Keyboard shortcuts

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