ffmpeg

package
v0.0.0-...-9c88ebf Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package ffmpeg is a utility for calling ffmpeg as a command and piping images to it to render a video file.

Index

Constants

View Source
const (
	Framerate          = 24
	ConstantRateFactor = 25
	Name               = "out"
)

Default Settings values

Variables

This section is empty.

Functions

This section is empty.

Types

type Framer

type Framer interface {
	// Frame renders the frame at the given index. The img passed in allows for
	// recycling. If it is nil, a new image should be generated.
	Frame(idx int, img image.Image) (image.Image, error)

	// Frames returns the number of frames to render
	Frames() int
}

Framer provides an interface for rendering frames to ffmpeg.

type Pipeline

type Pipeline struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Pipeline allows the process of encoding and passing an image to the ffmpeg process to happen in parallel to the process of generating frames.

func (*Pipeline) Add

func (p *Pipeline) Add(img image.Image) image.Image

Add an image to the pipeline. A recycled image is returned, but it may be nil.

func (*Pipeline) Wait

func (p *Pipeline) Wait()

Wait for the pipeline to finish processing.

type Proc

type Proc struct {
	Settings
	// contains filtered or unexported fields
}

Proc is a running instance of ffmpeg.

func (*Proc) AddFrame

func (p *Proc) AddFrame(img image.Image) error

AddFrame to the video created by ffmpeg

func (*Proc) Close

func (p *Proc) Close() error

Close the ffmpeg process. This must be called to finish the process.

func (*Proc) Pipeline

func (p *Proc) Pipeline() *Pipeline

Pipeline that operates in 2 stages. Add allows images to be added to the after which they are encoded and sent to the ffmeg process in a parallel go routine. The images are recycled on a pool.

type Settings

type Settings struct {
	Framerate          byte
	Name               string
	ConstantRateFactor byte
	Size               grid.Pt
	Stdout, Stderr     io.Writer
}

Settings for an ffmpeg process

func New

func New(name string) *Settings

New creates Settings with the defined width and height/

func NewByAspect

func NewByAspect(name string, width int, aspect grid.Aspect) *Settings

NewByAspect creates Settings with the provided aspect ratio.

func NewSquare

func NewSquare(name string, width int) *Settings

NewSquare creates Settings with a square aspect ratio.

func NewWidescreen

func NewWidescreen(name string, width int) *Settings

NewWidescreen creates Settings with a Widescreen aspect ratio.

func (*Settings) Args

func (s *Settings) Args() []string

Args to pass into the ffmpeg process.

func (*Settings) ByAspect

func (s *Settings) ByAspect(width int, aspect grid.Aspect) *Settings

ByAspect update the width and height of the settings using the provided aspect ratio.

func (*Settings) Framer

func (s *Settings) Framer(f Framer) (err error)

Framer will iterate through each frame of each framers. They are passed to the ffpeg process through a Pipeline.

func (*Settings) NewProc

func (s *Settings) NewProc() (*Proc, error)

NewProc created from the Settings.

func (*Settings) Run

func (s *Settings) Run(fn func(*Proc) error) (err error)

Run will start and close the ffmpeg Proc, passing the Proc into the provided func for use.

func (*Settings) RunPipeline

func (s *Settings) RunPipeline(fn func(*Pipeline) error) (err error)

RunPipeline creates a Pipeline from the Settings and passes it into the func provided.

func (*Settings) Set

func (s *Settings) Set(width, height int) *Settings

Set the width and height, which must both be multiples of 2.

func (*Settings) SetOut

func (s *Settings) SetOut(out, err io.Writer) *Settings

SetOut sets Stdout and Stderr to be used when creating a Proc.

func (*Settings) SetSize

func (s *Settings) SetSize(size grid.Pt) *Settings

type Sizer

type Sizer interface {
	Size() grid.Pt
}

Sizer returns a size. If Framer fulfills Sizer, that size will be used when calling Settings.Framer.

Jump to

Keyboard shortcuts

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