ffmpeg

package
v1.7.7 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PTS_UNDEFINED = ff.AV_NOPTS_VALUE
	TS_UNDEFINED  = -1.0
)
View Source
const (
	MetaArtwork = "artwork" // Metadata key for artwork, set the value as []byte
)

Variables

This section is empty.

Functions

func NewResampler

func NewResampler(par *Par, force bool) (*resampler, error)

Create a new audio resampler which will resample the input frame to the specified channel layout, sample rate and sample format.

func NewRescaler

func NewRescaler(par *Par, force bool) (*rescaler, error)

Create a new rescaler which will rescale the input frame to the specified format, width and height.

func SetLogging added in v1.6.10

func SetLogging(verbose bool, fn LogFn)

Set logging options, including a callback function

Types

type Channel added in v1.6.7

type Channel ff.AVChannel

func (*Channel) Description added in v1.6.7

func (ch *Channel) Description() string

func (*Channel) MarshalJSON added in v1.6.7

func (ch *Channel) MarshalJSON() ([]byte, error)

func (*Channel) Name added in v1.6.7

func (ch *Channel) Name() string

func (*Channel) String added in v1.6.7

func (ch *Channel) String() string

type ChannelLayout added in v1.6.7

type ChannelLayout ff.AVChannelLayout

func (*ChannelLayout) Channels added in v1.6.7

func (ch *ChannelLayout) Channels() []*Channel

func (*ChannelLayout) MarshalJSON added in v1.6.7

func (ch *ChannelLayout) MarshalJSON() ([]byte, error)

func (*ChannelLayout) Name added in v1.6.7

func (ch *ChannelLayout) Name() string

func (*ChannelLayout) NumChannels added in v1.6.7

func (ch *ChannelLayout) NumChannels() int

func (*ChannelLayout) Order added in v1.6.7

func (ch *ChannelLayout) Order() string

func (*ChannelLayout) String added in v1.6.7

func (ch *ChannelLayout) String() string

type Codec added in v1.6.7

type Codec ff.AVCodec

func (*Codec) ChannelLayouts added in v1.6.7

func (codec *Codec) ChannelLayouts() []string

Channel layouts supported by the codec. This is only valid for audio codecs.

func (*Codec) Description added in v1.6.7

func (codec *Codec) Description() string

The description of the codec

func (*Codec) MarshalJSON added in v1.6.7

func (codec *Codec) MarshalJSON() ([]byte, error)

func (*Codec) Name added in v1.6.7

func (codec *Codec) Name() string

The name the codec is referred to by

func (*Codec) PixelFormats added in v1.6.7

func (codec *Codec) PixelFormats() []string

Pixel formats supported by the codec. This is only valid for video codecs. The first pixel format is the default.

func (*Codec) Profiles added in v1.6.7

func (codec *Codec) Profiles() []string

Profiles supported by the codec. This is only valid for video codecs.

func (*Codec) SampleFormats added in v1.6.7

func (codec *Codec) SampleFormats() []string

Sample formats supported by the codec. This is only valid for audio codecs. The first sample format is the default.

func (*Codec) SampleRates added in v1.6.7

func (codec *Codec) SampleRates() []int

Sample rates supported by the codec. This is only valid for audio codecs. The first sample rate is the highest, sort the list in reverse order.

func (*Codec) String added in v1.6.7

func (codec *Codec) String() string

func (*Codec) Type added in v1.6.7

func (codec *Codec) Type() media.Type

Return the type of codec

type Context added in v1.6.7

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

Decoding context

func (*Context) C added in v1.6.7

func (decoder *Context) C(stream int) chan *Frame

func (*Context) Close added in v1.6.7

func (c *Context) Close() error

Release resources for the decoding context

type Decoder added in v1.6.7

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

func NewDecoder added in v1.6.7

func NewDecoder(stream *ff.AVStream, dest *Par, force bool) (*Decoder, error)

Create a stream decoder which can decode packets from the input stream

func (*Decoder) Close added in v1.6.7

func (d *Decoder) Close() error

Close the decoder and free any resources

type DecoderFrameFn added in v1.6.7

type DecoderFrameFn func(int, *Frame) error

DecoderFrameFn is a function which is called to send a frame after decoding. It should return nil to continue decoding or io.EOF to stop.

type DecoderMapFunc added in v1.6.7

type DecoderMapFunc func(int, *Par) (*Par, error)

Return parameters if a stream should be decoded and either resampled or resized. Return nil if you want to ignore the stream, or pass back the stream parameters if you want to copy the stream without any changes.

type Device added in v1.6.7

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

type Encoder

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

func NewEncoder

func NewEncoder(ctx *ff.AVFormatContext, stream int, par *Par) (*Encoder, error)

Create an encoder with the given parameters

func (*Encoder) Close

func (encoder *Encoder) Close() error

func (*Encoder) Encode

func (e *Encoder) Encode(frame *Frame, fn EncoderPacketFn) error

Encode a frame and pass packets to the EncoderPacketFn. If the frame is nil, then the encoder will flush any remaining packets. If io.EOF is returned then it indicates that the encoder has ended prematurely.

func (*Encoder) MarshalJSON

func (e *Encoder) MarshalJSON() ([]byte, error)

func (*Encoder) Par

func (e *Encoder) Par() *Par

Return the codec parameters

func (*Encoder) String

func (e *Encoder) String() string

type EncoderFrameFn

type EncoderFrameFn func(int) (*Frame, error)

EncoderFrameFn is a function which is called to receive a frame to encode. It should return nil to continue encoding or io.EOF to stop encoding.

type EncoderPacketFn

type EncoderPacketFn func(*Packet) error

EncoderPacketFn is a function which is called for each packet encoded, with the stream timebase.

type Format added in v1.6.7

type Format struct {
	Input   *ff.AVInputFormat  `json:"input,omitempty"`
	Output  *ff.AVOutputFormat `json:"output,omitempty"`
	Devices []*Device          `json:"devices,omitempty"`
	// contains filtered or unexported fields
}

func (*Format) Description added in v1.6.7

func (f *Format) Description() string

func (*Format) Name added in v1.6.7

func (f *Format) Name() string

func (*Format) String added in v1.6.7

func (f *Format) String() string

func (*Format) Type added in v1.6.7

func (f *Format) Type() media.Type

type Frame

type Frame ff.AVFrame

func NewFrame

func NewFrame(par *Par) (*Frame, error)

Create a new frame and optionally set audio or video parameters

func (*Frame) AllocateBuffers added in v1.6.7

func (frame *Frame) AllocateBuffers() error

Allocate buffers for the frame

func (*Frame) Bytes

func (frame *Frame) Bytes(plane int) []byte

Return plane data as a byte slice

func (*Frame) ChannelLayout

func (frame *Frame) ChannelLayout() ff.AVChannelLayout

func (*Frame) Close added in v1.6.7

func (frame *Frame) Close() error

Release frame resources

func (*Frame) Copy added in v1.6.7

func (frame *Frame) Copy() (*Frame, error)

Make a copy of the frame, which should be released by the caller

func (*Frame) CopyPropsFromFrame added in v1.6.7

func (frame *Frame) CopyPropsFromFrame(other *Frame) error

Copy properties from another frame

func (*Frame) Float32 added in v1.6.7

func (frame *Frame) Float32(plane int) []float32

Return plane data as a float32 slice

func (*Frame) FrameRate added in v1.6.7

func (frame *Frame) FrameRate() ff.AVRational

func (*Frame) FrameSize added in v1.6.7

func (frame *Frame) FrameSize() int

func (*Frame) FromImage added in v1.6.7

func (frame *Frame) FromImage(src image.Image) error

Repurpose a frame and copy image into it. TODO: Support SampleAspectRatio?

func (*Frame) Height

func (frame *Frame) Height() int

func (*Frame) Image

func (frame *Frame) Image() (image.Image, error)

Create an image from a frame. The frame should not be unreferenced until the image is no longer required, but the image can be discarded TODO: Add a copy flag which copies the memory?

func (*Frame) IncPts added in v1.6.7

func (frame *Frame) IncPts(v int64)

Increment presentation timestamp

func (*Frame) Int16

func (frame *Frame) Int16(plane int) []int16

Return plane data as a int16 slice

func (*Frame) IsAllocated added in v1.6.7

func (frame *Frame) IsAllocated() bool

Return true if the frame has allocated buffers

func (*Frame) MakeWritable added in v1.6.7

func (frame *Frame) MakeWritable() error

Make the frame writable

func (*Frame) NumSamples

func (frame *Frame) NumSamples() int

func (*Frame) PixelFormat

func (frame *Frame) PixelFormat() ff.AVPixelFormat

func (*Frame) Pts added in v1.6.7

func (frame *Frame) Pts() int64

Return the presentation timestamp in int64

func (*Frame) SampleAspectRatio added in v1.6.7

func (frame *Frame) SampleAspectRatio() ff.AVRational

func (*Frame) SampleFormat

func (frame *Frame) SampleFormat() ff.AVSampleFormat

func (*Frame) SampleRate added in v1.6.7

func (frame *Frame) SampleRate() int

func (*Frame) SetFloat32 added in v1.6.13

func (frame *Frame) SetFloat32(plane int, data []float32) error

Set plane data from float32 slice

func (*Frame) SetPts added in v1.6.7

func (frame *Frame) SetPts(v int64)

Set the presentation timestamp in int64

func (*Frame) SetTs added in v1.6.13

func (frame *Frame) SetTs(secs float64)

Set timestamp in seconds

func (*Frame) Stride

func (frame *Frame) Stride(plane int) int

Return the stride for a plane (number of bytes in a row)

func (*Frame) String

func (frame *Frame) String() string

func (*Frame) TimeBase added in v1.6.7

func (frame *Frame) TimeBase() ff.AVRational

func (*Frame) Ts added in v1.6.7

func (frame *Frame) Ts() float64

Return the timestamp in seconds, or TS_UNDEFINED if the timestamp is undefined or timebase is not set

func (*Frame) Type

func (frame *Frame) Type() media.Type

Return frame type - AUDIO or VIDEO. Other types are not yet identified and returned as UNKNOWN

func (*Frame) Unref added in v1.6.7

func (frame *Frame) Unref()

Unreference frame buffers

func (*Frame) Width

func (frame *Frame) Width() int

type LogFn added in v1.6.10

type LogFn func(text string)

Logging function

type LogFunc added in v1.6.7

type LogFunc func(string)

Logging function which is used to log messages

type Manager added in v1.6.7

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

func NewManager added in v1.6.7

func NewManager(opt ...Opt) (*Manager, error)

Create a new media manager which enumerates the available codecs, formats and devices

func (*Manager) ChannelLayouts added in v1.6.7

func (manager *Manager) ChannelLayouts() []media.Metadata

Return standard channel layouts which can be used for audio

func (*Manager) Codecs added in v1.6.7

func (manager *Manager) Codecs(t media.Type, name ...string) []media.Metadata

Return all supported codecs, of a specific type or all if ANY is used. If any names is provided, then only the codecs with those names are returned. Codecs can be AUDIO, VIDEO and SUBTITLE

func (*Manager) Create added in v1.7.3

func (manager *Manager) Create(url string, format media.Format, meta []media.Metadata, streams ...media.Par) (media.Media, error)

func (*Manager) Decode added in v1.7.3

func (manager *Manager) Decode(ctx context.Context, m media.Media, mapFunc media.MapFunc, frameFunc media.FrameFunc) error

func (*Manager) Errorf added in v1.6.7

func (manager *Manager) Errorf(v string, args ...any)

Log error messages

func (*Manager) Formats added in v1.6.7

func (manager *Manager) Formats(t media.Type, name ...string) []media.Format

func (*Manager) Infof added in v1.6.7

func (manager *Manager) Infof(v string, args ...any)

Log info messages

func (*Manager) Open added in v1.6.7

func (manager *Manager) Open(url string, format media.Format, opts ...string) (media.Media, error)

func (*Manager) PixelFormats added in v1.6.7

func (manager *Manager) PixelFormats() []media.Metadata

Return all supported pixel formats

func (*Manager) Read added in v1.7.3

func (manager *Manager) Read(r io.Reader, format media.Format, opts ...string) (media.Media, error)

func (*Manager) SampleFormats added in v1.6.7

func (manager *Manager) SampleFormats() []media.Metadata

Return all supported sample formats

func (*Manager) Warningf added in v1.6.7

func (manager *Manager) Warningf(v string, args ...any)

Log warning messages

type Metadata

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

func NewMetadata

func NewMetadata(key string, value any) *Metadata

Metadata implementation

func (*Metadata) Any added in v1.6.7

func (m *Metadata) Any() any

Returns the value as an interface

func (*Metadata) Bytes added in v1.6.7

func (m *Metadata) Bytes() []byte

Returns the value as a byte slice

func (*Metadata) Image added in v1.6.7

func (m *Metadata) Image() image.Image

Returns the value as an image

func (*Metadata) Key

func (m *Metadata) Key() string

func (*Metadata) String

func (m *Metadata) String() string

func (*Metadata) Value

func (m *Metadata) Value() string

Value returns the value as a string. If the value is a byte slice, it will return the mimetype of the byte slice.

type Opt

type Opt func(*opts) error

Option which can affect the behaviour of ffmpeg

func OptContext added in v1.6.7

func OptContext(context *Context) Opt

New streams with parameters from the context

func OptForce

func OptForce() Opt

Force resampling and resizing on decode, even if the input and output parameters are the same

func OptInputFormat added in v1.6.7

func OptInputFormat(name string) Opt

Input format from name or url

func OptInputOpt added in v1.6.7

func OptInputOpt(opt ...string) Opt

Input format options

func OptLog added in v1.6.7

func OptLog(verbose bool, fn LogFunc) Opt

Set a logging function

func OptMetadata

func OptMetadata(entry ...*Metadata) Opt

Append metadata to the output file, including artwork

func OptOutputFormat

func OptOutputFormat(name string) Opt

Output format from name or url

func OptStream

func OptStream(stream int, par *Par) Opt

New stream with parameters

type Packet added in v1.6.7

type Packet ff.AVPacket

func (*Packet) String added in v1.6.7

func (packet *Packet) String() string

func (*Packet) Ts added in v1.6.7

func (packet *Packet) Ts() float64

Return the timestamp in seconds, or TS_UNDEFINED if the timestamp is undefined or timebase is not set

type Par

type Par struct {
	ff.AVCodecParameters
	// contains filtered or unexported fields
}

func AudioPar

func AudioPar(samplefmt string, channellayout string, samplerate int, opts ...media.Metadata) *Par

Create audio parameters. If there is an error, then this function will panic

func NewAudioPar

func NewAudioPar(samplefmt string, channellayout string, samplerate int, opts ...media.Metadata) (*Par, error)

Create new audio parameters with sample format, channel layout and sample rate plus any additional options which is used for creating a stream

func NewVideoPar

func NewVideoPar(pixfmt string, size string, framerate float64, opts ...media.Metadata) (*Par, error)

Create new video parameters with pixel format, frame size, framerate plus any additional options which is used for creating a stream

func VideoPar

func VideoPar(pixfmt string, size string, framerate float64, opts ...media.Metadata) *Par

Create video parameters. If there is an error, then this function will panic

func (*Par) CopyToCodecContext added in v1.6.7

func (ctx *Par) CopyToCodecContext(codec *ff.AVCodecContext) error

func (*Par) FrameRate added in v1.6.7

func (ctx *Par) FrameRate() float64

func (*Par) MarshalJSON

func (ctx *Par) MarshalJSON() ([]byte, error)

func (*Par) String

func (ctx *Par) String() string

func (*Par) Type added in v1.6.7

func (ctx *Par) Type() media.Type

func (*Par) ValidateFromCodec

func (ctx *Par) ValidateFromCodec(codec *ff.AVCodec) error

func (*Par) WidthHeight added in v1.6.7

func (ctx *Par) WidthHeight() string

type PixelFormat added in v1.6.7

type PixelFormat ff.AVPixelFormat

func (*PixelFormat) IsPlanar added in v1.6.7

func (pixfmt *PixelFormat) IsPlanar() bool

func (*PixelFormat) MarshalJSON added in v1.6.7

func (pixfmt *PixelFormat) MarshalJSON() ([]byte, error)

func (*PixelFormat) Name added in v1.6.7

func (pixfmt *PixelFormat) Name() string

func (*PixelFormat) NumPlanes added in v1.6.7

func (pixfmt *PixelFormat) NumPlanes() int

func (*PixelFormat) String added in v1.6.7

func (pixfmt *PixelFormat) String() string

type Re added in v1.6.7

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

Re implements a resampler and rescaler for audio and video frames. May need to extend it for subtitles later on

func NewRe added in v1.6.7

func NewRe(par *Par, force bool) (*Re, error)

Return a new resampler or rescaler, with the destination parameters. If force is true, then the resampler will always resample, even if the destination parameters are the same as the source parameters.

func (*Re) Close added in v1.6.7

func (re *Re) Close() error

Release resources

func (*Re) Frame added in v1.6.7

func (re *Re) Frame(src *Frame) (*Frame, error)

Resample or rescale the source frame and return the destination frame

type Reader added in v1.6.7

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

Media reader which reads from a URL, file path or device

func NewReader added in v1.6.7

func NewReader(r io.Reader, opt ...Opt) (*Reader, error)

Create a new reader from an io.Reader

func Open added in v1.6.7

func Open(url string, opt ...Opt) (*Reader, error)

Open media from a url, file path or device

func (*Reader) BestStream added in v1.6.7

func (r *Reader) BestStream(t media.Type) int

Return the "best stream" for a specific media type, or -1 if there is no "best stream" for that type.

func (*Reader) Close added in v1.6.7

func (r *Reader) Close() error

Close the reader

func (*Reader) Decode added in v1.6.7

func (r *Reader) Decode(ctx context.Context, mapfn DecoderMapFunc, decodefn DecoderFrameFn) error

func (*Reader) DecodeWithContext added in v1.6.7

func (r *Reader) DecodeWithContext(ctx context.Context, decoders *Context, decodefn DecoderFrameFn) error

Decode the media stream into frames. The decodefn is called for each frame decoded from the stream.

The decoding can be interrupted by cancelling the context, or by the decodefn returning an error or io.EOF. The latter will end the decoding process early but will not return an error.

func (*Reader) Duration added in v1.6.7

func (r *Reader) Duration() time.Duration

Return the duration of the media stream, returns zero if unknown

func (*Reader) Map added in v1.6.7

func (r *Reader) Map(fn DecoderMapFunc) (*Context, error)

Map streams to decoders, and return the decoding context The map function is called for each stream and should return the parameters for the destination frame. If any parameters are returned as null, then that stream is ignored

func (*Reader) MarshalJSON added in v1.6.7

func (r *Reader) MarshalJSON() ([]byte, error)

Display the reader as a string

func (*Reader) Metadata added in v1.6.7

func (r *Reader) Metadata(keys ...string) []*Metadata

Return the metadata for the media stream, filtering by the specified keys if there are any. Artwork is returned with the "artwork" key.

func (*Reader) Seek added in v1.7.3

func (r *Reader) Seek(stream int, secs float64) error

Seek to a specific time in the media stream, in seconds

func (*Reader) Streams added in v1.7.3

func (r *Reader) Streams(t media.Type) []*Stream

Return all streams of a specific type (video, audio, subtitle, data)

func (*Reader) String added in v1.6.7

func (r *Reader) String() string

Display the reader as a string

func (*Reader) Type added in v1.6.7

func (r *Reader) Type() media.Type

Return the media type

type SampleFormat added in v1.6.7

type SampleFormat ff.AVSampleFormat

func (*SampleFormat) BytesPerSample added in v1.6.7

func (samplefmt *SampleFormat) BytesPerSample() int

func (*SampleFormat) IsPlanar added in v1.6.7

func (samplefmt *SampleFormat) IsPlanar() bool

func (*SampleFormat) MarshalJSON added in v1.6.7

func (samplefmt *SampleFormat) MarshalJSON() ([]byte, error)

func (*SampleFormat) Name added in v1.6.7

func (samplefmt *SampleFormat) Name() string

func (*SampleFormat) String added in v1.6.7

func (samplefmt *SampleFormat) String() string

type Stream added in v1.7.3

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

func (*Stream) Index added in v1.7.3

func (s *Stream) Index() int

Return the stream index

func (*Stream) MarshalJSON added in v1.7.3

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

func (*Stream) Type added in v1.7.3

func (s *Stream) Type() media.Type

Return the stream type

type Writer

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

Create media from io.Writer

func Create

func Create(url string, opt ...Opt) (*Writer, error)

Create a new writer with a URL and options

func NewWriter

func NewWriter(w io.Writer, opt ...Opt) (*Writer, error)

Create a new writer with an io.Writer and options

func (*Writer) Close

func (w *Writer) Close() error

Close a writer and release resources

func (*Writer) Encode

func (w *Writer) Encode(ctx context.Context, in EncoderFrameFn, out EncoderPacketFn) error

Encode frames from all encoders, calling the callback function to encode the frame. If the callback function returns io.EOF then the encoding for that encoder is stopped after flushing. If the second callback is nil, then packets are written to the output.

func (*Writer) MarshalJSON added in v1.6.7

func (w *Writer) MarshalJSON() ([]byte, error)

Display the writer as a string

func (*Writer) Stream

func (w *Writer) Stream(stream int) *Encoder

Return a "stream" for encoding

func (*Writer) String added in v1.6.7

func (w *Writer) String() string

Display the writer as a string

func (*Writer) Type added in v1.7.3

func (w *Writer) Type() media.Type

Return a "stream" for encoding

func (*Writer) Write

func (w *Writer) Write(packet *Packet) error

Write a packet to the output. If you intercept the packets in the Encode method, then you can use this method to write packets to the output.

Jump to

Keyboard shortcuts

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