av

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 19 Imported by: 0

README

go-av

Simple, idiomatic, opinionated wrapper for libav (aka ffmpeg).

Why?

go-ffmpeg is good enough for many cases, but is not sufficient when lower level control is required.

Features

  • Go-native data structures
  • Go-native logging (with *log.Logger)
  • Opinionated but light library for common libav use cases
  • Direct low level libav function access (via avcodec, avformat, etc. sub packages)
  • Option for static and dynamic binding

Goals

  • Idiomatic Go/hide C specific mechanisms
  • Expose low level libav APIs
  • Keep clear library boundaries

Non-Goals

  • Teaching how to use libav
  • Bundling and building libav

Usage/Environment Setup

pkg-config is used for linking, so the ffmpeg libraries and .pc files must be installed from your system's package manager or from source or the PKG_CONFIG_PATH environment variable must be set.

Gotchas

Cgo is very particular with pointers. The Go runtime will actively prevent Go pointers from reaching C code by panicking if tried. However, some libav functions (like *_free_context) require a pointer to a pointer for output.

Fortunately, discovered only by experimentation, stack pointers are able to pass through this boundary with no problem. This means that pointers to local variables are safe to use for these functions. Whether this is intended behaviour is beyond me.

Additional Notes

  • The surface area of the libav API pretty large, so no effort was spent on being complete. Pull requests are more than welcome to improve API coverage.
  • Tested on linux with glibc and musl using ffmpeg 4.3.x.

Documentation

Index

Constants

View Source
const FileOpener = fileOpener(0)
View Source
const NullOpener = nullOpener(0)

Variables

This section is empty.

Functions

func Rat

func Rat(num, den int32) avutil.Rational

Types

type BitstreamFilter

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

func FindBitstreamFilterByName

func FindBitstreamFilterByName(name string) (*BitstreamFilter, error)

type BitstreamFilterContext

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

func NewBitstreamFilterContext

func NewBitstreamFilterContext(filter *BitstreamFilter) (*BitstreamFilterContext, error)

func (*BitstreamFilterContext) FilterPacket

func (ctx *BitstreamFilterContext) FilterPacket(inPacket *Packet) ([]*Packet, error)

func (*BitstreamFilterContext) SetInputCodecParameters

func (ctx *BitstreamFilterContext) SetInputCodecParameters(params *CodecParameters)

func (*BitstreamFilterContext) SetOutputCodecParameters

func (ctx *BitstreamFilterContext) SetOutputCodecParameters(params *CodecParameters)

type BitstreamFilterNotFoundError

type BitstreamFilterNotFoundError string

func (BitstreamFilterNotFoundError) Error

type BufferSink

type BufferSink FilterContext

func (*BufferSink) LinkFrom

func (sink *BufferSink) LinkFrom(src *FilterContext, srcPadIndex int32) error

func (*BufferSink) ReadFrame

func (sink *BufferSink) ReadFrame() (*Frame, error)

func (*BufferSink) ReadFrameReuse

func (sink *BufferSink) ReadFrameReuse(frame *Frame) error

func (*BufferSink) ReadFrames

func (sink *BufferSink) ReadFrames() ([]*Frame, error)

type BufferSource

type BufferSource FilterContext

func (*BufferSource) LinkTo

func (src *BufferSource) LinkTo(dst *FilterContext, dstPadIndex int32) error

func (*BufferSource) WriteFrame

func (src *BufferSource) WriteFrame(frame *Frame) error

type Codec

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

func FindDecoderCodecByID

func FindDecoderCodecByID(codecID avcodec.ID) (*Codec, error)

func FindDecoderCodecByName

func FindDecoderCodecByName(name string) (*Codec, error)

func FindEncoderCodecByID

func FindEncoderCodecByID(codecID avcodec.ID) (*Codec, error)

func FindEncoderCodecByName

func FindEncoderCodecByName(name string) (*Codec, error)

func (*Codec) Name

func (c *Codec) Name() string

func (*Codec) NbPixFmts

func (c *Codec) NbPixFmts() int

func (*Codec) NbSampleFmts

func (c *Codec) NbSampleFmts() int

func (*Codec) PixFmt

func (c *Codec) PixFmt(i int) avutil.PixelFormat

func (*Codec) PixFmts

func (c *Codec) PixFmts() []avutil.PixelFormat

func (*Codec) SampleFmt

func (c *Codec) SampleFmt(i int) avutil.SampleFormat

func (*Codec) SampleFmts

func (c *Codec) SampleFmts() []avutil.SampleFormat

type CodecNotFoundError

type CodecNotFoundError string

func (CodecNotFoundError) Error

func (e CodecNotFoundError) Error() string

type CodecParameters

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

type DecoderContext

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

func NewDecoderContext

func NewDecoderContext(codec *Codec, params *CodecParameters) (*DecoderContext, error)

func (*DecoderContext) BufferSourceArgs

func (ctx *DecoderContext) BufferSourceArgs() string

func (*DecoderContext) Codec

func (ctx *DecoderContext) Codec() *Codec

func (*DecoderContext) CodecID

func (ctx *DecoderContext) CodecID() avcodec.ID

func (*DecoderContext) CodecParameters

func (ctx *DecoderContext) CodecParameters() *CodecParameters

func (*DecoderContext) GetOption

func (ctx *DecoderContext) GetOption(name string) (interface{}, error)

func (*DecoderContext) HwDeviceCtx

func (ctx *DecoderContext) HwDeviceCtx() *HWDeviceContext

func (*DecoderContext) HwFramesCtx

func (ctx *DecoderContext) HwFramesCtx() *HWFramesContext

func (*DecoderContext) NewFrameIterator

func (ctx *DecoderContext) NewFrameIterator(ifc *InputFormatContext, streamIndex int32) *FrameIterator

func (*DecoderContext) Open

func (ctx *DecoderContext) Open() error

func (*DecoderContext) ReceiveFrame

func (ctx *DecoderContext) ReceiveFrame() (*Frame, error)

func (*DecoderContext) ReceiveFrameReuse

func (ctx *DecoderContext) ReceiveFrameReuse(frame *Frame) error

func (*DecoderContext) SendPacket

func (ctx *DecoderContext) SendPacket(packet *Packet) error

func (*DecoderContext) SetGetFormat

func (ctx *DecoderContext) SetGetFormat(f func([]avutil.PixelFormat) avutil.PixelFormat)

func (*DecoderContext) SetHwDeviceCtx

func (ctx *DecoderContext) SetHwDeviceCtx(deviceCtx *HWDeviceContext)

func (*DecoderContext) SetHwFramesCtx

func (ctx *DecoderContext) SetHwFramesCtx(framesCtx *HWFramesContext)

func (*DecoderContext) SetOption

func (ctx *DecoderContext) SetOption(name string, value interface{}) error

type EncoderContext

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

func NewEncoderContext

func NewEncoderContext(codec *Codec, params *CodecParameters) (*EncoderContext, error)

func (*EncoderContext) Codec

func (ctx *EncoderContext) Codec() *Codec

func (*EncoderContext) CodecID

func (ctx *EncoderContext) CodecID() avcodec.ID

func (*EncoderContext) CodecParameters

func (ctx *EncoderContext) CodecParameters() *CodecParameters

func (*EncoderContext) FramePackets

func (ctx *EncoderContext) FramePackets(frame *Frame) ([]*Packet, error)

func (*EncoderContext) GetOption

func (ctx *EncoderContext) GetOption(name string) (interface{}, error)

func (*EncoderContext) HwDeviceCtx

func (ctx *EncoderContext) HwDeviceCtx() *HWDeviceContext

func (*EncoderContext) HwFramesCtx

func (ctx *EncoderContext) HwFramesCtx() *HWFramesContext

func (*EncoderContext) Open

func (ctx *EncoderContext) Open() error

func (*EncoderContext) ReceivePacket

func (ctx *EncoderContext) ReceivePacket() (*Packet, error)

func (*EncoderContext) ReceivePacketReuse

func (ctx *EncoderContext) ReceivePacketReuse(packet *Packet) error

func (*EncoderContext) SendFrame

func (ctx *EncoderContext) SendFrame(frame *Frame) error

func (*EncoderContext) SetGetFormat

func (ctx *EncoderContext) SetGetFormat(f func([]avutil.PixelFormat) avutil.PixelFormat)

func (*EncoderContext) SetHwDeviceCtx

func (ctx *EncoderContext) SetHwDeviceCtx(deviceCtx *HWDeviceContext)

func (*EncoderContext) SetHwFramesCtx

func (ctx *EncoderContext) SetHwFramesCtx(framesCtx *HWFramesContext)

func (*EncoderContext) SetOption

func (ctx *EncoderContext) SetOption(name string, value interface{}) error

type Filter

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

func FindFilterByName

func FindFilterByName(name string) (*Filter, error)

type FilterContext

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

func (*FilterContext) LinkFrom

func (ctx *FilterContext) LinkFrom(padIndex int32, src *FilterContext, srcPadIndex int32) error

func (*FilterContext) LinkTo

func (ctx *FilterContext) LinkTo(padIndex int32, dst *FilterContext, dstPadIndex int32) error

func (*FilterContext) Name

func (ctx *FilterContext) Name() string

type FilterGraph

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

func NewFilterGraph

func NewFilterGraph() (*FilterGraph, error)

func (*FilterGraph) NewBufferSink

func (g *FilterGraph) NewBufferSink(name string) (*BufferSink, error)

func (*FilterGraph) NewBufferSource

func (g *FilterGraph) NewBufferSource(name string, decoder *DecoderContext) (*BufferSource, error)

func (*FilterGraph) NewFilter

func (g *FilterGraph) NewFilter(filter *Filter, name, args string) (*FilterContext, error)

func (*FilterGraph) NewFilterByName

func (g *FilterGraph) NewFilterByName(filterName, name, args string) (*FilterContext, error)

func (*FilterGraph) Parse

func (g *FilterGraph) Parse(desc string) (inputs, outputs []*FilterInOut, _ error)

func (*FilterGraph) SetHWDeviceContext

func (g *FilterGraph) SetHWDeviceContext(ctx *HWDeviceContext)

type FilterInOut

type FilterInOut struct {
	Name          string
	FilterContext *FilterContext
	PadIndex      int32
}

type FilterNotFoundError

type FilterNotFoundError string

func (FilterNotFoundError) Error

func (e FilterNotFoundError) Error() string

type Frame

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

func NewFrame

func NewFrame() *Frame

func (*Frame) Clone

func (f *Frame) Clone() (*Frame, error)

func (*Frame) CopyTo

func (f *Frame) CopyTo(f2 *Frame) error

func (*Frame) HwFramesCtx

func (f *Frame) HwFramesCtx() *HWFramesContext

func (*Frame) Unref

func (f *Frame) Unref()

type FrameIterator

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

func NewFrameIterator

func NewFrameIterator(ifc *InputFormatContext, streamIndex int32) (*FrameIterator, error)

func (*FrameIterator) Next

func (it *FrameIterator) Next(frame *Frame) error

type HWDeviceContext

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

func NewHWDeviceContext

func NewHWDeviceContext(deviceType avutil.HWDeviceType, device string) (*HWDeviceContext, error)

type HWFramesContext

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

func NewHWFramesContext

func NewHWFramesContext(deviceCtx *HWDeviceContext) *HWFramesContext

func (*HWFramesContext) Eq

func (ctx *HWFramesContext) Eq(ctx2 *HWFramesContext) bool

func (*HWFramesContext) Init

func (ctx *HWFramesContext) Init() error

type InputFormatContext

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

func OpenInputFile

func OpenInputFile(input string) (*InputFormatContext, error)

func OpenInputReader

func OpenInputReader(r io.Reader) (*InputFormatContext, error)

func OpenInputWithOpener

func OpenInputWithOpener(opener Opener, url string) (*InputFormatContext, error)

func (*InputFormatContext) FindBestStream

func (ctx *InputFormatContext) FindBestStream(mediaType avutil.MediaType) (int, *Codec, error)

func (*InputFormatContext) GetOption

func (ctx *InputFormatContext) GetOption(name string) (interface{}, error)

func (*InputFormatContext) GuessFramerate

func (ctx *InputFormatContext) GuessFramerate(stream *Stream) avutil.Rational

func (*InputFormatContext) ReadPacket

func (ctx *InputFormatContext) ReadPacket() (*Packet, error)

func (*InputFormatContext) ReadPacketReuse

func (ctx *InputFormatContext) ReadPacketReuse(packet *Packet) error

func (*InputFormatContext) SeekFile

func (ctx *InputFormatContext) SeekFile(streamIndex int32, minTimestamp, timestamp, maxTimestamp int64, flags int32) error

func (*InputFormatContext) SetOpener

func (ctx *InputFormatContext) SetOpener(opener Opener)

func (*InputFormatContext) SetOption

func (ctx *InputFormatContext) SetOption(name string, value interface{}) error

func (*InputFormatContext) SetUrl

func (ctx *InputFormatContext) SetUrl(url string)

func (*InputFormatContext) Stream

func (ctx *InputFormatContext) Stream(i int) *Stream

func (*InputFormatContext) Streams

func (ctx *InputFormatContext) Streams() []*Stream

func (*InputFormatContext) Url

func (ctx *InputFormatContext) Url() string

type Opener

type Opener interface {
	Open(url string, flags int) (io.Closer, error)
}

type Option

type Option func(**avutil.Dictionary) error

func StringOption

func StringOption(name, value string) Option

type OutputFormatContext

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

func NewFileOutputContext

func NewFileOutputContext(formatName string, filename string) (*OutputFormatContext, error)

func NewOutputContext

func NewOutputContext(formatName string) (*OutputFormatContext, error)

func NewWriterOutputContext

func NewWriterOutputContext(formatName string, w io.Writer) (*OutputFormatContext, error)

func (*OutputFormatContext) Close

func (ctx *OutputFormatContext) Close() error

func (*OutputFormatContext) FindBestStream

func (ctx *OutputFormatContext) FindBestStream(mediaType avutil.MediaType) (int, *Codec, error)

func (*OutputFormatContext) GetOption

func (ctx *OutputFormatContext) GetOption(name string) (interface{}, error)

func (*OutputFormatContext) GuessFramerate

func (ctx *OutputFormatContext) GuessFramerate(stream *Stream) avutil.Rational

func (*OutputFormatContext) NewStream

func (ctx *OutputFormatContext) NewStream(codec *Codec) *Stream

func (*OutputFormatContext) SetOpener

func (ctx *OutputFormatContext) SetOpener(opener Opener)

func (*OutputFormatContext) SetOption

func (ctx *OutputFormatContext) SetOption(name string, value interface{}) error

func (*OutputFormatContext) SetUrl

func (ctx *OutputFormatContext) SetUrl(url string)

func (*OutputFormatContext) Stream

func (ctx *OutputFormatContext) Stream(i int) *Stream

func (*OutputFormatContext) Streams

func (ctx *OutputFormatContext) Streams() []*Stream

func (*OutputFormatContext) Url

func (ctx *OutputFormatContext) Url() string

func (*OutputFormatContext) WritePacket

func (ctx *OutputFormatContext) WritePacket(packet *Packet) error

type Packet

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

func NewPacket

func NewPacket() *Packet

func (*Packet) Clone

func (p *Packet) Clone() (*Packet, error)

func (*Packet) CopyTo

func (p *Packet) CopyTo(p2 *Packet) error

func (*Packet) Rescale

func (p *Packet) Rescale(src, dst avutil.Rational)

func (*Packet) Unref

func (p *Packet) Unref()

type Stream

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

func (*Stream) Codecpar

func (s *Stream) Codecpar() *CodecParameters

func (*Stream) FindDecoder

func (s *Stream) FindDecoder()

func (*Stream) GuessFramerate

func (s *Stream) GuessFramerate() avutil.Rational

func (*Stream) SetCodecpar

func (s *Stream) SetCodecpar(params *CodecParameters)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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