Documentation
¶
Overview ¶
Package ffmpeg binds the parts of FFmpeg's C API the pipeline uses, through purego, and refuses library versions it does not name.
Index ¶
- Constants
- Variables
- func Alloc(n int) unsafe.Pointer
- func DecoderSupportsHW(decoderName, hwDevice string) bool
- func Dir() string
- func Free(p unsafe.Pointer)
- func HasDecoder(name string) bool
- func HasDemuxer(name string) bool
- func HasEncoder(name string) bool
- func HasMuxer(name string) bool
- func IsAgain(err error) bool
- func IsEOF(err error) bool
- func Load() error
- func PixelFormat(name string) int32
- func PixelFormatName(f int32) string
- func SampleFormat(name string) int32
- func Version() string
- type Chapter
- type Codec
- type CodecContext
- type CodecParameters
- func (c *CodecParameters) BitRate() int64
- func (c *CodecParameters) Channels() int
- func (c *CodecParameters) CodecID() int32
- func (c *CodecParameters) CodecName() string
- func (c *CodecParameters) Format() int32
- func (c *CodecParameters) Height() int
- func (c *CodecParameters) Profile() int32
- func (c *CodecParameters) Rotation() int
- func (c *CodecParameters) SampleAspectRatio() Rational
- func (c *CodecParameters) SampleRate() int
- func (c *CodecParameters) Type() MediaType
- func (c *CodecParameters) Width() int
- type D3D11Surface
- type Decoder
- type Encoder
- type EncoderConfig
- type Error
- type FormatContext
- func (c *FormatContext) BitRate() int64
- func (c *FormatContext) Chapters() []*Chapter
- func (c *FormatContext) Duration() time.Duration
- func (c *FormatContext) FormatName() string
- func (c *FormatContext) Metadata() map[string]string
- func (c *FormatContext) ReadPacket(p *Packet) error
- func (c *FormatContext) Seek(stream int, minTS, ts, maxTS int64, flags int) error
- func (c *FormatContext) Seekable() bool
- func (c *FormatContext) StartTime() time.Duration
- func (c *FormatContext) Streams() []*Stream
- type Frame
- func (f *Frame) AllocBuffer(w, h int, pixFmt int32) error
- func (f *Frame) BestEffortTimestamp() int64
- func (f *Frame) Channels() int
- func (f *Frame) Clone() *Frame
- func (f *Frame) ColorPrimaries() int32
- func (f *Frame) ColorSpace() int32
- func (f *Frame) ColorTrc() int32
- func (f *Frame) CopyColor(src *Frame)
- func (f *Frame) D3D11() (s D3D11Surface, ok bool)
- func (f *Frame) DurationTS() int64
- func (f *Frame) Format() int32
- func (f *Frame) Free()
- func (f *Frame) FullRange() bool
- func (f *Frame) HDR() bool
- func (f *Frame) Hardware() bool
- func (f *Frame) Height() int
- func (f *Frame) Key() bool
- func (f *Frame) MakeWritable() error
- func (f *Frame) MoveTo(dst *Frame)
- func (f *Frame) NbSamples() int
- func (f *Frame) PTS() int64
- func (f *Frame) Plane(i int) (unsafe.Pointer, int)
- func (f *Frame) SampleRate() int
- func (f *Frame) SetColor(colorspace int32, fullRange bool)
- func (f *Frame) SetGeometry(w, h int, pixFmt int32)
- func (f *Frame) SetPTS(ts int64)
- func (f *Frame) SetPictType(t int32)
- func (f *Frame) SetPlane(i int, data unsafe.Pointer, stride int)
- func (f *Frame) SoftwareFormat() int32
- func (f *Frame) TransferTo(dst *Frame) error
- func (f *Frame) Unref()
- func (f *Frame) VAAPI() (display unsafe.Pointer, surface uint32, ok bool)
- func (f *Frame) Width() int
- type Input
- type InputOptions
- type MediaType
- type Opener
- type Packer
- type Packet
- func (p *Packet) DTS() int64
- func (p *Packet) Data() []byte
- func (p *Packet) DurationTS() int64
- func (p *Packet) Free()
- func (p *Packet) Key() bool
- func (p *Packet) PTS() int64
- func (p *Packet) Pos() int64
- func (p *Packet) SetData(b []byte) error
- func (p *Packet) Size() int
- func (p *Packet) StreamIndex() int
- func (p *Packet) Unref()
- type Rational
- type Resampler
- type Scaler
- type Source
- type Stream
- func (s *Stream) AttachedPicture() bool
- func (s *Stream) AvgFrameRate() Rational
- func (s *Stream) Default() bool
- func (s *Stream) Duration() time.Duration
- func (s *Stream) DurationTS() int64
- func (s *Stream) Forced() bool
- func (s *Stream) FrameCount() int64
- func (s *Stream) ID() int
- func (s *Stream) Index() int
- func (s *Stream) Metadata() map[string]string
- func (s *Stream) Params() *CodecParameters
- func (s *Stream) RealFrameRate() Rational
- func (s *Stream) SampleAspectRatio() Rational
- func (s *Stream) SetDiscard(d int32)
- func (s *Stream) StartTime() int64
- func (s *Stream) TimeBase() Rational
- type Subtitle
- type SubtitleRect
- type Tempo
Constants ¶
const ( SeekBackward = 1 SeekAny = 4 DiscardDefault = 0 DiscardAll = 48 ColorSpaceBT709 = 1 ColorSpaceBT2020NCL = 9 ColorSpaceBT2020CL = 10 PictTypeNone int32 = 0 PictTypeI int32 = 1 ColorPrimariesBT709 = 1 ColorPrimariesUnspecified = 2 ColorPrimariesBT2020 = 9 ColorTrcBT709 = 1 ColorTrcUnspecified = 2 ColorTrcSMPTE2084 = 16 // PQ (HDR10) ColorTrcARIBSTDB67 = 18 // HLG )
const NoPTS int64 = math.MinInt64
NoPTS is AV_NOPTS_VALUE, a timestamp that is not known.
const TimeBase = 1000000
TimeBase is AV_TIME_BASE, the microseconds a format's duration counts.
Variables ¶
var ( // ErrEOF is AVERROR_EOF: the input or a decoder has nothing more. ErrEOF = tag('E', 'O', 'F', ' ') // ErrExit is AVERROR_EXIT: an interrupt callback stopped a call. ErrExit = tag('E', 'X', 'I', 'T') // ErrAgain is AVERROR(EAGAIN): a decoder needs input or output first. ErrAgain = Error(-eagain()) // ErrInvalidData is AVERROR_INVALIDDATA. ErrInvalidData = tag('I', 'N', 'D', 'A') )
var Majors = map[string]int{
"avutil": 61,
"swresample": 7,
"swscale": 10,
"avcodec": 63,
"avformat": 63,
"avfilter": 12,
}
Majors are the library major versions the binding's struct layouts are generated for (FFmpeg 9). Fields only move between majors, so any minor release of these loads.
Functions ¶
func DecoderSupportsHW ¶
DecoderSupportsHW reports whether decoderName supports hwDevice and that hardware device can be opened on this machine.
func Dir ¶
func Dir() string
Dir is the directory the libraries were loaded from, empty for the system's search, once Load succeeded.
func HasDecoder ¶
HasDecoder reports whether FFmpeg has a decoder with name compiled in.
func HasDemuxer ¶
HasDemuxer reports the loaded FFmpeg having the demuxer name, such as "dash", which libraries built without libxml2 lack.
func HasEncoder ¶
HasEncoder reports whether FFmpeg has an encoder with name compiled in.
func Load ¶
func Load() error
Load loads FFmpeg's libraries once, from the first directory of library.Dirs that holds them all at the majors the binding names, and binds their functions. Later calls return the first call's result.
func PixelFormat ¶
PixelFormat is the number of a pixel format FFmpeg names, -1 if none.
func PixelFormatName ¶
PixelFormatName is a pixel format's name.
func SampleFormat ¶
SampleFormat is the number of a sample format FFmpeg names, -1 if none.
Types ¶
type Chapter ¶
type Chapter struct {
// contains filtered or unexported fields
}
The pointer types below stand for FFmpeg's structs; their memory is FFmpeg's, and their methods read and write fields at the offsets layout.go generated.
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
The pointer types below stand for FFmpeg's structs; their memory is FFmpeg's, and their methods read and write fields at the offsets layout.go generated.
type CodecContext ¶
type CodecContext struct {
// contains filtered or unexported fields
}
The pointer types below stand for FFmpeg's structs; their memory is FFmpeg's, and their methods read and write fields at the offsets layout.go generated.
type CodecParameters ¶
type CodecParameters struct {
// contains filtered or unexported fields
}
The pointer types below stand for FFmpeg's structs; their memory is FFmpeg's, and their methods read and write fields at the offsets layout.go generated.
func (*CodecParameters) BitRate ¶
func (c *CodecParameters) BitRate() int64
func (*CodecParameters) Channels ¶
func (c *CodecParameters) Channels() int
func (*CodecParameters) CodecID ¶
func (c *CodecParameters) CodecID() int32
func (*CodecParameters) CodecName ¶
func (c *CodecParameters) CodecName() string
CodecName is the codec's short name, such as "h264".
func (*CodecParameters) Format ¶
func (c *CodecParameters) Format() int32
func (*CodecParameters) Height ¶
func (c *CodecParameters) Height() int
func (*CodecParameters) Profile ¶
func (c *CodecParameters) Profile() int32
func (*CodecParameters) Rotation ¶
func (c *CodecParameters) Rotation() int
Rotation is the clockwise rotation in degrees, a multiple of 90, the stream's display matrix asks the picture to be shown at.
func (*CodecParameters) SampleAspectRatio ¶
func (c *CodecParameters) SampleAspectRatio() Rational
func (*CodecParameters) SampleRate ¶
func (c *CodecParameters) SampleRate() int
func (*CodecParameters) Type ¶
func (c *CodecParameters) Type() MediaType
func (*CodecParameters) Width ¶
func (c *CodecParameters) Width() int
type D3D11Surface ¶
type D3D11Surface struct {
Texture unsafe.Pointer // ID3D11Texture2D
Index int // the array slice
Device unsafe.Pointer // ID3D11Device
Context unsafe.Pointer // ID3D11DeviceContext, used under Lock
// contains filtered or unexported fields
}
D3D11Surface is where a D3D11VA frame decoded: a slice of a texture array on the decoder's device.
func (D3D11Surface) Lock ¶
func (s D3D11Surface) Lock()
Lock takes the lock FFmpeg holds while it uses the device's context.
type Decoder ¶
type Decoder struct {
// HWDevice is the device type it decodes on, empty for software.
HWDevice string
// contains filtered or unexported fields
}
Decoder is an opened decoder for one stream.
func NewDecoder ¶
func NewDecoder(par *CodecParameters, tb Rational, threads int, hwDevice string, extraHW int) (*Decoder, error)
NewDecoder opens a decoder for par's codec, with threads threads (0 for FFmpeg's choice) and, when hwDevice names one, on that hardware device type ("videotoolbox", "d3d11va", "vaapi"), whose pool keeps extraHW surfaces beyond what decoding needs for frames the caller holds. It fails when the codec has no decoder or the device cannot be made for it.
func NewRawDecoder ¶
NewRawDecoder opens a low-latency decoder by codec name (such as "h264") without container parameters, for raw access-unit streams. When hwDevice names a hardware device type ("videotoolbox", "d3d11va", "vaapi"), it opens on that device.
func (*Decoder) DecodeSubtitle ¶
DecodeSubtitle decodes a subtitle packet, returning nil for a packet that completes none.
func (*Decoder) Flush ¶
func (d *Decoder) Flush()
Flush drops the decoder's buffered packets and frames, as after a seek.
func (*Decoder) Receive ¶
Receive takes the next decoded frame into f. ErrAgain means it needs more packets; ErrEOF that it is drained.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is an opened FFmpeg video encoder.
func NewEncoder ¶
func NewEncoder(cfg EncoderConfig) (*Encoder, error)
NewEncoder opens a video encoder with no B-frames for low-latency encoding.
func (*Encoder) Close ¶
func (e *Encoder) Close()
Close frees the encoder and any hardware contexts it owns.
func (*Encoder) Receive ¶
Receive reads the next encoded packet into p. ErrAgain means more frames are needed; ErrEOF that the encoder is drained.
func (*Encoder) Send ¶
Send submits a software frame (or nil to flush). When the encoder uses a hardware frame pool (such as VAAPI), Send uploads f to a hardware surface.
func (*Encoder) SetBitRate ¶
SetBitRate updates the encoder context's target bit rate in bits per second.
type EncoderConfig ¶
type EncoderConfig struct {
Name string // FFmpeg encoder name, e.g. "h264_videotoolbox"
HWDevice string // optional hardware device for frame upload, e.g. "vaapi"
HWFormat string // hardware pixel format when HWDevice is set, e.g. "vaapi"
PixFmt string // software pixel format fed in, e.g. "nv12" or "yuv420p"
Width int
Height int
FPS int
BitRate int64
GOPSize int
ColorSpace int32
FullRange bool
Options map[string]string
}
EncoderConfig configures a low-latency video encoder.
type FormatContext ¶
type FormatContext struct {
// contains filtered or unexported fields
}
The pointer types below stand for FFmpeg's structs; their memory is FFmpeg's, and their methods read and write fields at the offsets layout.go generated.
func (*FormatContext) BitRate ¶
func (c *FormatContext) BitRate() int64
BitRate is the input's total bit rate, 0 when unknown.
func (*FormatContext) Chapters ¶
func (c *FormatContext) Chapters() []*Chapter
Chapters are the input's chapters.
func (*FormatContext) Duration ¶
func (c *FormatContext) Duration() time.Duration
Duration is the input's duration, 0 when unknown.
func (*FormatContext) FormatName ¶
func (c *FormatContext) FormatName() string
FormatName is the demuxer's short name, such as "matroska,webm".
func (*FormatContext) Metadata ¶
func (c *FormatContext) Metadata() map[string]string
Metadata is the container's metadata.
func (*FormatContext) ReadPacket ¶
func (c *FormatContext) ReadPacket(p *Packet) error
ReadPacket reads the next packet into p.
func (*FormatContext) Seek ¶
func (c *FormatContext) Seek(stream int, minTS, ts, maxTS int64, flags int) error
Seek seeks to ts in stream's time base, or microseconds for stream -1, within [minTS, maxTS].
func (*FormatContext) Seekable ¶
func (c *FormatContext) Seekable() bool
Seekable reports the demuxer able to seek, which a live stream's is not.
func (*FormatContext) StartTime ¶
func (c *FormatContext) StartTime() time.Duration
StartTime is the first timestamp's time, 0 when unknown.
func (*FormatContext) Streams ¶
func (c *FormatContext) Streams() []*Stream
Streams are the input's streams.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
The pointer types below stand for FFmpeg's structs; their memory is FFmpeg's, and their methods read and write fields at the offsets layout.go generated.
func (*Frame) AllocBuffer ¶
AllocBuffer allocates buffers for a software video frame of w×h pixels in pixFmt.
func (*Frame) BestEffortTimestamp ¶
func (*Frame) ColorPrimaries ¶
func (*Frame) ColorSpace ¶
func (*Frame) CopyColor ¶
CopyColor gives f src's color space, range, transfer characteristic and primaries.
func (*Frame) D3D11 ¶
func (f *Frame) D3D11() (s D3D11Surface, ok bool)
D3D11 is a D3D11VA frame's surface; ok is false for other frames.
func (*Frame) DurationTS ¶
func (*Frame) HDR ¶
HDR reports a picture with a high dynamic range transfer characteristic (PQ / HDR10 or HLG).
func (*Frame) Hardware ¶
Hardware reports a frame in a hardware surface, which Transfer copies into memory.
func (*Frame) MakeWritable ¶
MakeWritable ensures the frame's buffers can be written in place.
func (*Frame) SampleRate ¶
func (*Frame) SetGeometry ¶
SetGeometry sets a wrapper frame's width, height and pixel format.
func (*Frame) SetPictType ¶
SetPictType sets the frame's picture type (PictTypeNone or PictTypeI).
func (*Frame) SetPlane ¶
SetPlane sets the i-th plane pointer and line size directly, for wrapping caller-owned buffers without copying. Clear it before freeing.
func (*Frame) SoftwareFormat ¶
SoftwareFormat is the pixel format a hardware frame's surface holds, such as nv12 or p010le, -1 for a frame in memory.
func (*Frame) TransferTo ¶
TransferTo copies a hardware frame's picture into dst, in memory.
func (*Frame) Unref ¶
func (f *Frame) Unref()
Unref drops the frame's buffers, keeping it for reuse.
type Input ¶
type Input struct {
Format *FormatContext
// contains filtered or unexported fields
}
Input is an opened media source: its demuxer, and the Go reader and interrupt behind it.
func Open ¶
Open opens url, or src when it is not nil (url then only names it), and reads its streams' information. Setting interrupt makes any blocking call on the input return ErrExit.
type InputOptions ¶
type InputOptions struct {
// Format names the demuxer, such as "hls", instead of probing.
Format string
// Options are the demuxer's options, such as hls' "allowed_extensions".
Options map[string]string
// Open, when not nil, opens every resource the demuxer opens itself.
Open Opener
}
InputOptions are how OpenInput opens its input.
type Opener ¶
Opener opens a resource a demuxer asks for by URL, such as an HLS playlist's segments or keys, as a Source read through Go. Options are what the demuxer passes with the request, such as "offset" and "end_offset" for a byte range. A Source that is an io.Closer is closed when the demuxer closes it.
type Packer ¶
type Packer struct {
// contains filtered or unexported fields
}
Packer wraps a stream's encoded audio packets in IEC 61937 bursts, as S/PDIF and HDMI carry AC-3, E-AC-3, DTS, DTS-HD and TrueHD to a receiver that decodes them, through FFmpeg's spdif muxer. The bursts are 16-bit little-endian words, which a carrier plays as PCM frames: 2 channels, or 8 for HDMI's high bit rate.
func NewPacker ¶
func NewPacker(par *CodecParameters, dtsHDRate int) (*Packer, error)
NewPacker makes a packer for the stream whose parameters are par: AC-3, E-AC-3, DTS or TrueHD, whose access units it gathers into MAT frames. A DTS stream passes its core alone unless dtsHDRate is set: then whole frames, DTS-HD's extension substream with the core, pass as DTS type IV bursts at that IEC 61937 rate, 768000 for HDMI's high bit rate.
func (*Packer) Pack ¶
Pack wraps p, which becomes the packer's to change, and returns the bursts it completed, valid until the next call: none while E-AC-3 gathers the frames of one burst, or TrueHD the 24 access units of a MAT frame. The packet's stream index and timestamps are changed for the muxer.
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
The pointer types below stand for FFmpeg's structs; their memory is FFmpeg's, and their methods read and write fields at the offsets layout.go generated.
func (*Packet) DurationTS ¶
func (*Packet) StreamIndex ¶
type Rational ¶
type Rational struct{ Num, Den int32 }
Rational is AVRational.
type Resampler ¶
type Resampler struct {
// contains filtered or unexported fields
}
Resampler converts decoded audio to interleaved float32 at a rate and channel count, rebuilding its context when the source's format changes.
func NewResampler ¶
NewResampler converts to rate and channels.
type Scaler ¶
type Scaler struct {
// contains filtered or unexported fields
}
Scaler converts video frames to RGBA at a size through swscale's frame API, which follows each frame's color space and range and splits the work over the CPU's cores.
type Source ¶
type Source interface {
io.ReadSeeker
Size() int64
}
Source is what Open reads through Go instead of a URL FFmpeg opens: an HTTP body, or any other seekable stream. Size, when it returns a positive length, lets FFmpeg seek from the end.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
The pointer types below stand for FFmpeg's structs; their memory is FFmpeg's, and their methods read and write fields at the offsets layout.go generated.
func (*Stream) AttachedPicture ¶
AttachedPicture reports a video stream that is only cover art.
func (*Stream) AvgFrameRate ¶
func (*Stream) DurationTS ¶
func (*Stream) FrameCount ¶
func (*Stream) Params ¶
func (s *Stream) Params() *CodecParameters
func (*Stream) RealFrameRate ¶
func (*Stream) SampleAspectRatio ¶
func (*Stream) SetDiscard ¶
SetDiscard sets which of the stream's packets the demuxer drops.
type Subtitle ¶
type Subtitle struct {
// PTS is in microseconds, NoPTS when unknown.
PTS int64
Start, End uint32 // End is math.MaxUint32 when unknown
Rects []SubtitleRect
}
Subtitle is a decoded subtitle: what shows from Start to End milliseconds after PTS, replacing what its stream showed before. No rects clear the screen, as PGS and DVB end a subtitle.
type SubtitleRect ¶
type SubtitleRect struct {
Text string
ASS string
X, Y int
// Image is a bitmap's pixels, premultiplied as image.RGBA is; nil
// for text.
Image *image.RGBA
}
SubtitleRect is one part of a decoded subtitle: plain text, an ASS event line, or a bitmap at X, Y on the stream's canvas.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package library finds FFmpeg's shared libraries: the directory the NSGO_MEDIA_FFMPEG environment variable names, the app's package, beside the executable, then the system's.
|
Package library finds FFmpeg's shared libraries: the directory the NSGO_MEDIA_FFMPEG environment variable names, the app's package, beside the executable, then the system's. |