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 ¶
Set logging options, including a callback function
Types ¶
type ChannelLayout ¶
type ChannelLayout ff.AVChannelLayout
func (*ChannelLayout) Channels ¶
func (ch *ChannelLayout) Channels() []*Channel
func (*ChannelLayout) MarshalJSON ¶
func (ch *ChannelLayout) MarshalJSON() ([]byte, error)
func (*ChannelLayout) Name ¶
func (ch *ChannelLayout) Name() string
func (*ChannelLayout) NumChannels ¶
func (ch *ChannelLayout) NumChannels() int
func (*ChannelLayout) Order ¶
func (ch *ChannelLayout) Order() string
func (*ChannelLayout) String ¶
func (ch *ChannelLayout) String() string
type Codec ¶
func (*Codec) ChannelLayouts ¶
Channel layouts supported by the codec. This is only valid for audio codecs.
func (*Codec) MarshalJSON ¶
func (*Codec) PixelFormats ¶
Pixel formats supported by the codec. This is only valid for video codecs. The first pixel format is the default.
func (*Codec) SampleFormats ¶
Sample formats supported by the codec. This is only valid for audio codecs. The first sample format is the default.
func (*Codec) SampleRates ¶
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 Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
Create a stream decoder which can decode packets from the input stream
type DecoderFrameFn ¶
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 ¶
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 ¶
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 ¶
type Frame ¶
func (*Frame) AllocateBuffers ¶
Allocate buffers for the frame
func (*Frame) ChannelLayout ¶
func (frame *Frame) ChannelLayout() ff.AVChannelLayout
func (*Frame) CopyPropsFromFrame ¶
Copy properties from another frame
func (*Frame) FrameRate ¶
func (frame *Frame) FrameRate() ff.AVRational
func (*Frame) FromImage ¶
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 ¶
Return true if the frame has allocated buffers
func (*Frame) NumSamples ¶
func (*Frame) PixelFormat ¶
func (frame *Frame) PixelFormat() ff.AVPixelFormat
func (*Frame) SampleAspectRatio ¶
func (frame *Frame) SampleAspectRatio() ff.AVRational
func (*Frame) SampleFormat ¶
func (frame *Frame) SampleFormat() ff.AVSampleFormat
func (*Frame) SampleRate ¶
func (*Frame) SetFloat32 ¶
Set plane data from float32 slice
func (*Frame) TimeBase ¶
func (frame *Frame) TimeBase() ff.AVRational
func (*Frame) Ts ¶
Return the timestamp in seconds, or TS_UNDEFINED if the timestamp is undefined or timebase is not set
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
Create a new media manager which enumerates the available codecs, formats and devices
func (*Manager) ChannelLayouts ¶
Return standard channel layouts which can be used for audio
func (*Manager) Codecs ¶
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 ¶
Return all supported pixel formats
func (*Manager) SampleFormats ¶
Return all supported sample formats
type Opt ¶
type Opt func(*opts) error
Option which can affect the behaviour of ffmpeg
func OptContext ¶
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 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 ¶
func (ctx *Par) CopyToCodecContext(codec *ff.AVCodecContext) error
func (*Par) MarshalJSON ¶
func (*Par) WidthHeight ¶
type PixelFormat ¶
type PixelFormat ff.AVPixelFormat
func (*PixelFormat) IsPlanar ¶
func (pixfmt *PixelFormat) IsPlanar() bool
func (*PixelFormat) MarshalJSON ¶
func (pixfmt *PixelFormat) MarshalJSON() ([]byte, error)
func (*PixelFormat) Name ¶
func (pixfmt *PixelFormat) Name() string
func (*PixelFormat) NumPlanes ¶
func (pixfmt *PixelFormat) NumPlanes() int
func (*PixelFormat) String ¶
func (pixfmt *PixelFormat) String() string
type Re ¶
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 ¶
type Reader struct {
// contains filtered or unexported fields
}
Media reader which reads from a URL, file path or device
func (*Reader) BestStream ¶
Return the "best stream" for a specific media type, or -1 if there is no "best stream" for that type.
func (*Reader) Decode ¶
func (r *Reader) Decode(ctx context.Context, mapfn DecoderMapFunc, decodefn DecoderFrameFn) error
func (*Reader) DecodeWithContext ¶
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) Map ¶
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 ¶
Display the reader as a string
func (*Reader) Metadata ¶
Return the metadata for the media stream, filtering by the specified keys if there are any. Artwork is returned with the "artwork" key.
type SampleFormat ¶
type SampleFormat ff.AVSampleFormat
func (*SampleFormat) BytesPerSample ¶
func (samplefmt *SampleFormat) BytesPerSample() int
func (*SampleFormat) IsPlanar ¶
func (samplefmt *SampleFormat) IsPlanar() bool
func (*SampleFormat) MarshalJSON ¶
func (samplefmt *SampleFormat) MarshalJSON() ([]byte, error)
func (*SampleFormat) Name ¶
func (samplefmt *SampleFormat) Name() string
func (*SampleFormat) String ¶
func (samplefmt *SampleFormat) String() string
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func (*Stream) MarshalJSON ¶
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 ¶
Display the writer as a string