Documentation
¶
Index ¶
- Constants
- func NewResampler(par *Par, force bool) (*resampler, error)
- func NewRescaler(par *Par, force bool) (*rescaler, error)
- func SetLogging(verbose bool, fn LogFn)
- type Channel
- type ChannelLayout
- type Codec
- func (codec *Codec) ChannelLayouts() []string
- func (codec *Codec) Description() string
- func (codec *Codec) MarshalJSON() ([]byte, error)
- func (codec *Codec) Name() string
- func (codec *Codec) PixelFormats() []string
- func (codec *Codec) Profiles() []string
- func (codec *Codec) SampleFormats() []string
- func (codec *Codec) SampleRates() []int
- func (codec *Codec) String() string
- func (codec *Codec) Type() media.Type
- type Context
- type Decoder
- type DecoderFrameFn
- type DecoderMapFunc
- type Device
- type Encoder
- type EncoderFrameFn
- type EncoderPacketFn
- type Format
- type Frame
- func (frame *Frame) AllocateBuffers() error
- func (frame *Frame) Bytes(plane int) []byte
- func (frame *Frame) ChannelLayout() ff.AVChannelLayout
- func (frame *Frame) Close() error
- func (frame *Frame) Copy() (*Frame, error)
- func (frame *Frame) CopyPropsFromFrame(other *Frame) error
- func (frame *Frame) Float32(plane int) []float32
- func (frame *Frame) FrameRate() ff.AVRational
- func (frame *Frame) FrameSize() int
- func (frame *Frame) FromImage(src image.Image) error
- func (frame *Frame) Height() int
- func (frame *Frame) Image() (image.Image, error)
- func (frame *Frame) IncPts(v int64)
- func (frame *Frame) Int16(plane int) []int16
- func (frame *Frame) IsAllocated() bool
- func (frame *Frame) MakeWritable() error
- func (frame *Frame) NumSamples() int
- func (frame *Frame) PixelFormat() ff.AVPixelFormat
- func (frame *Frame) Pts() int64
- func (frame *Frame) SampleAspectRatio() ff.AVRational
- func (frame *Frame) SampleFormat() ff.AVSampleFormat
- func (frame *Frame) SampleRate() int
- func (frame *Frame) SetFloat32(plane int, data []float32) error
- func (frame *Frame) SetPts(v int64)
- func (frame *Frame) SetTs(secs float64)
- func (frame *Frame) Stride(plane int) int
- func (frame *Frame) String() string
- func (frame *Frame) TimeBase() ff.AVRational
- func (frame *Frame) Ts() float64
- func (frame *Frame) Type() media.Type
- func (frame *Frame) Unref()
- func (frame *Frame) Width() int
- type LogFn
- type LogFunc
- type Manager
- func (manager *Manager) ChannelLayouts() []media.Metadata
- func (manager *Manager) Codecs(t media.Type, name ...string) []media.Metadata
- func (manager *Manager) Create(url string, format media.Format, meta []media.Metadata, streams ...media.Par) (media.Media, error)
- func (manager *Manager) Decode(ctx context.Context, m media.Media, mapFunc media.MapFunc, ...) error
- func (manager *Manager) Errorf(v string, args ...any)
- func (manager *Manager) Formats(t media.Type, name ...string) []media.Format
- func (manager *Manager) Infof(v string, args ...any)
- func (manager *Manager) Open(url string, format media.Format, opts ...string) (media.Media, error)
- func (manager *Manager) PixelFormats() []media.Metadata
- func (manager *Manager) Read(r io.Reader, format media.Format, opts ...string) (media.Media, error)
- func (manager *Manager) SampleFormats() []media.Metadata
- func (manager *Manager) Warningf(v string, args ...any)
- type Metadata
- type Opt
- type Packet
- type Par
- func AudioPar(samplefmt string, channellayout string, samplerate int, opts ...media.Metadata) *Par
- func NewAudioPar(samplefmt string, channellayout string, samplerate int, opts ...media.Metadata) (*Par, error)
- func NewVideoPar(pixfmt string, size string, framerate float64, opts ...media.Metadata) (*Par, error)
- func VideoPar(pixfmt string, size string, framerate float64, opts ...media.Metadata) *Par
- func (ctx *Par) CopyToCodecContext(codec *ff.AVCodecContext) error
- func (ctx *Par) FrameRate() float64
- func (ctx *Par) MarshalJSON() ([]byte, error)
- func (ctx *Par) String() string
- func (ctx *Par) Type() media.Type
- func (ctx *Par) ValidateFromCodec(codec *ff.AVCodec) error
- func (ctx *Par) WidthHeight() string
- type PixelFormat
- type Re
- type Reader
- func (r *Reader) BestStream(t media.Type) int
- func (r *Reader) Close() error
- func (r *Reader) Decode(ctx context.Context, mapfn DecoderMapFunc, decodefn DecoderFrameFn) error
- func (r *Reader) DecodeWithContext(ctx context.Context, decoders *Context, decodefn DecoderFrameFn) error
- func (r *Reader) Duration() time.Duration
- func (r *Reader) Map(fn DecoderMapFunc) (*Context, error)
- func (r *Reader) MarshalJSON() ([]byte, error)
- func (r *Reader) Metadata(keys ...string) []*Metadata
- func (r *Reader) Seek(stream int, secs float64) error
- func (r *Reader) Streams(t media.Type) []*Stream
- func (r *Reader) String() string
- func (r *Reader) Type() media.Type
- type SampleFormat
- type Stream
- type Writer
- func (w *Writer) Close() error
- func (w *Writer) Encode(ctx context.Context, in EncoderFrameFn, out EncoderPacketFn) error
- func (w *Writer) MarshalJSON() ([]byte, error)
- func (w *Writer) Stream(stream int) *Encoder
- func (w *Writer) String() string
- func (w *Writer) Type() media.Type
- func (w *Writer) Write(packet *Packet) error
Constants ¶
const ( PTS_UNDEFINED = ff.AV_NOPTS_VALUE TS_UNDEFINED = -1.0 )
const (
MetaArtwork = "artwork" // Metadata key for artwork, set the value as []byte
)
Variables ¶
This section is empty.
Functions ¶
func NewResampler ¶
Create a new audio resampler which will resample the input frame to the specified channel layout, sample rate and sample format.
func NewRescaler ¶
Create a new rescaler which will rescale the input frame to the specified format, width and height.
func SetLogging ¶ added in v1.6.10
Set logging options, including a callback function
Types ¶
type Channel ¶ added in v1.6.7
func (*Channel) Description ¶ added in v1.6.7
func (*Channel) MarshalJSON ¶ added in v1.6.7
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
func (*Codec) ChannelLayouts ¶ added in v1.6.7
Channel layouts supported by the codec. This is only valid for audio codecs.
func (*Codec) Description ¶ added in v1.6.7
The description of the codec
func (*Codec) MarshalJSON ¶ added in v1.6.7
func (*Codec) PixelFormats ¶ added in v1.6.7
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
Profiles supported by the codec. This is only valid for video codecs.
func (*Codec) SampleFormats ¶ added in v1.6.7
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
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.
type Context ¶ added in v1.6.7
type Context struct {
// contains filtered or unexported fields
}
Decoding context
type Decoder ¶ added in v1.6.7
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶ added in v1.6.7
Create a stream decoder which can decode packets from the input stream
type DecoderFrameFn ¶ added in v1.6.7
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
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 Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
Create an encoder with the given parameters
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 ¶
type EncoderFrameFn ¶
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 ¶
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
type Frame ¶
func (*Frame) AllocateBuffers ¶ added in v1.6.7
Allocate buffers for the frame
func (*Frame) ChannelLayout ¶
func (frame *Frame) ChannelLayout() ff.AVChannelLayout
func (*Frame) Copy ¶ added in v1.6.7
Make a copy of the frame, which should be released by the caller
func (*Frame) CopyPropsFromFrame ¶ added in v1.6.7
Copy properties from another frame
func (*Frame) FrameRate ¶ added in v1.6.7
func (frame *Frame) FrameRate() ff.AVRational
func (*Frame) FromImage ¶ added in v1.6.7
Repurpose a frame and copy image into it. TODO: Support SampleAspectRatio?
func (*Frame) Image ¶
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) IsAllocated ¶ added in v1.6.7
Return true if the frame has allocated buffers
func (*Frame) MakeWritable ¶ added in v1.6.7
Make the frame writable
func (*Frame) NumSamples ¶
func (*Frame) PixelFormat ¶
func (frame *Frame) PixelFormat() ff.AVPixelFormat
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) SetFloat32 ¶ added in v1.6.13
Set plane data from float32 slice
func (*Frame) TimeBase ¶ added in v1.6.7
func (frame *Frame) TimeBase() ff.AVRational
func (*Frame) Ts ¶ added in v1.6.7
Return the timestamp in seconds, or TS_UNDEFINED if the timestamp is undefined or timebase is not set
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
Create a new media manager which enumerates the available codecs, formats and devices
func (*Manager) ChannelLayouts ¶ added in v1.6.7
Return standard channel layouts which can be used for audio
func (*Manager) Codecs ¶ added in v1.6.7
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) PixelFormats ¶ added in v1.6.7
Return all supported pixel formats
func (*Manager) SampleFormats ¶ added in v1.6.7
Return all supported sample formats
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
type Opt ¶
type Opt func(*opts) error
Option which can affect the behaviour of ffmpeg
func OptContext ¶ added in v1.6.7
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
Input format from name or url
func OptMetadata ¶
Append metadata to the output file, including artwork
type Par ¶
type Par struct { ff.AVCodecParameters // contains filtered or unexported fields }
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 (*Par) CopyToCodecContext ¶ added in v1.6.7
func (ctx *Par) CopyToCodecContext(codec *ff.AVCodecContext) error
func (*Par) MarshalJSON ¶
func (*Par) WidthHeight ¶ added in v1.6.7
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
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 (*Reader) BestStream ¶ added in v1.6.7
Return the "best stream" for a specific media type, or -1 if there is no "best stream" for that type.
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
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
Display the reader as a string
func (*Reader) Metadata ¶ added in v1.6.7
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) Streams ¶ added in v1.7.3
Return all streams of a specific type (video, audio, subtitle, data)
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) MarshalJSON ¶ added in v1.7.3
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Create media from io.Writer
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
Display the writer as a string