Documentation
¶
Overview ¶
This is a package for reading, writing and inspecting media files. In order to operate on media, call NewManager() and then use the manager functions to determine capabilities and manage media files and devices.
Index ¶
Constants ¶
const ( MetaArtwork = "artwork" // Metadata key for artwork, sets the value as []byte MetaDuration = "duration" // Metadata key for duration, sets the value as float64 (seconds) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioParameters ¶ added in v1.6.7
type AudioParameters interface {
// Return the channel layout
ChannelLayout() string
// Return the sample format
SampleFormat() string
// Return the sample rate (Hz)
Samplerate() int
}
Audio parameters for encoding or decoding audio data.
type Codec ¶ added in v1.6.1
type Codec interface {
// Return the codec name
Name() string
// Return the codec description
Description() string
// Return the codec type (AUDIO, VIDEO, SUBTITLE, DATA, INPUT, OUTPUT)
Type() Type
}
Codec represents a codec for encoding or decoding media streams.
type Decoder ¶ added in v1.6.7
type Decoder interface {
// Demultiplex media into packets. Pass a packet to a decoder function.
// Stop when the context is cancelled or the end of the media stream is
// reached.
Demux(context.Context, DecoderFunc) error
// Decode media into frames, and resample or resize the frame.
// Stop when the context is cancelled or the end of the media stream is
// reached.
Decode(context.Context, FrameFunc) error
}
Decoder represents a demuliplexer and decoder for a media stream. You can call either Demux or Decode to process the media stream, but not both.
type DecoderFunc ¶ added in v1.6.7
DecoderFunc is a function that decodes a packet. Return io.EOF if you want to stop processing the packets early.
type DecoderMapFunc ¶ added in v1.6.7
type DecoderMapFunc func(Stream) (Parameters, error)
Return parameters if a the stream should be decoded and either resampled or resized. Return nil if you want to ignore the stream, or pass identical stream parameters (stream.Parameters()) if you want to copy the stream without any changes.
type Device ¶ added in v1.6.7
type Device interface {
// Device name, format depends on the device
Name() string
// Description of the device
Description() string
// Flags indicating the type INPUT or OUTPUT, AUDIO or VIDEO
Type() Type
// Whether this is the default device
Default() bool
}
Device represents a device for input or output of media streams.
type Format ¶ added in v1.6.7
type Format interface {
// Name(s) of the format
Name() []string
// Description of the format
Description() string
// Extensions associated with the format, if a stream. Each extension
// should have a preceeding period (ie, ".mp4")
Extensions() []string
// MimeTypes associated with the format
MimeTypes() []string
// Flags indicating the type. INPUT for a demuxer or source, OUTPUT for a muxer or
// sink, DEVICE for a device, FILE for a file. Plus AUDIO, VIDEO, DATA, SUBTITLE.
Type() Type
}
Format represents a container format for input or output of media streams. Use the manager object to get a list of supported formats.
type Frame ¶ added in v1.6.1
type Frame interface {
Parameters
// Number of samples in the frame, for an audio frame.
NumSamples() int
// Return stride for each plane, for a video frame.
Stride(int) int
// Return a frame plane as a byte slice.
Bytes(int) []byte
// Return a frame plane as int16 slice
Int16(int) []int16
// Return the presentation timestamp for the frame or
// a negative number if not set
Time() time.Duration
// Return a frame as an image, which supports the following
// pixel formats: AV_PIX_FMT_GRAY8, AV_PIX_FMT_RGBA,
// AV_PIX_FMT_RGB24, AV_PIX_FMT_YUV420P
Image() (image.Image, error)
}
Frame represents a frame of audio or video data.
type FrameFunc ¶ added in v1.6.7
FrameFunc is a function that processes a frame of audio or video data. Return io.EOF if you want to stop processing the frames early.
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.1
type Manager interface {
// Open a media file or device for reading, from a path or url.
// If a format is specified, then the format will be used to open
// the file. Close the media object when done.
Open(string, Format, ...string) (Media, error)
// Open a media stream for reading. If a format is
// specified, then the format will be used to open the file. Close the
// media object when done. It is the responsibility of the caller to
// also close the reader when done.
Read(io.Reader, Format, ...string) (Media, error)
// Create a media file or device for writing, from a path. If a format is
// specified, then the format will be used to create the file or else
// the format is guessed from the path. If no parameters are provided,
// then the default parameters for the format are used.
Create(string, Format, []Metadata, ...Parameters) (Media, error)
// Create a media stream for writing. The format will be used to
// determine the format and one or more CodecParameters used to
// create the streams. If no parameters are provided, then the
// default parameters for the format are used. It is the responsibility
// of the caller to also close the writer when done.
Write(io.Writer, Format, []Metadata, ...Parameters) (Media, error)
// Return supported input formats which match any filter, which can be
// a name, extension (with preceeding period) or mimetype. The MediaType
// can be NONE (for any) or combinations of DEVICE and STREAM.
InputFormats(Type, ...string) []Format
// Return supported output formats which match any filter, which can be
// a name, extension (with preceeding period) or mimetype. The MediaType
// can be NONE (for any) or combinations of DEVICE and STREAM.
OutputFormats(Type, ...string) []Format
// Return supported devices for a given format.
// Not all devices may be supported on all platforms or listed
// if the device does not support enumeration.
Devices(Format) []Device
// Return all supported channel layouts
ChannelLayouts() []Metadata
// Return all supported sample formats
SampleFormats() []Metadata
// Return all supported pixel formats
PixelFormats() []Metadata
// Return all supported codecs
Codecs() []Metadata
// Return audio parameters for encoding
// ChannelLayout, SampleFormat, Samplerate
AudioParameters(string, string, int) (Parameters, error)
// Return video parameters for encoding
// Width, Height, PixelFormat
VideoParameters(int, int, string) (Parameters, error)
// Return version information for the media manager as a set of
// metadata
Version() []Metadata
// Log error messages with arguments
Errorf(string, ...any)
// Log warning messages with arguments
Warningf(string, ...any)
// Log info messages with arguments
Infof(string, ...any)
}
Manager represents a manager for media formats and devices. Create a new manager object using the NewManager function.
func NewManager ¶ added in v1.6.7
type Media ¶
type Media interface {
io.Closer
// Return a decoding context for the media stream, and
// map the streams to decoders. If no function is provided
// (ie, the argument is nil) then all streams are demultiplexed.
// Will return an error if called on a writer.
Decoder(DecoderMapFunc) (Decoder, error)
// Multiplex media into packets. Pass a packet to a muxer function.
// Stop when the context is cancelled or the end of the media stream is
// signalled. Will return an error if called on a reader.
Mux(context.Context, MuxFunc) error
// Return INPUT for a demuxer or source, OUTPUT for a muxer or
// sink, DEVICE for a device, FILE for a file or stream.
Type() Type
// Return the metadata for the media, filtering by keys if any
// are included. Use the "artwork" key to return only artwork.
Metadata(...string) []Metadata
}
Media represents a media stream, which can be input or output. A new media object is created using the Manager object
type MediaType ¶
type MediaType uint32
Media type flags
const ( NONE MediaType = 0 UNKNOWN MediaType = (1 << iota) // Usually treated as DATA VIDEO // Video stream AUDIO // Audio stream DATA // Opaque data information usually continuous SUBTITLE // Subtitle stream INPUT // Demuxer OUTPUT // Muxer FILE // File or byte stream DEVICE // Device rather than stream CODEC // Codec // Set minimum and maximum values MIN = UNKNOWN MAX = CODEC // Convenience values ANY = NONE )
func (MediaType) FlagString ¶ added in v1.6.7
func (MediaType) MarshalJSON ¶ added in v1.6.7
type Metadata ¶ added in v1.6.1
type Metadata interface {
// Return the metadata key for the entry
Key() string
// Return the metadata value for the entry
Value() any
}
Metadata represents a metadata entry for a media stream.
type MuxFunc ¶ added in v1.6.7
MuxFunc is a function that multiplexes a packet. It is repeatedly called with a stream identifier - return a packet for that stream if one is available, or nil if no packet is available for muxing. Return io.EOF to stop multiplexing.
type Opt ¶ added in v1.6.7
type Opt func(*opts) error
type Packet ¶ added in v1.6.1
type Packet interface {
// The packet can be audio, video, subtitle or data.
Type() Type
// The stream identifier for the packet
Id() int
}
Packet represents a packet of demultiplexed data, or a packet to be multiplexed.
type Parameters ¶ added in v1.6.7
type Parameters interface {
AudioParameters
VideoParameters
// Return the media type (AUDIO, VIDEO, SUBTITLE, DATA)
Type() Type
// Return the stream id for encoding, or zero if not set
Id() int
// Return number of planes for a specific PixelFormat
// or SampleFormat and ChannelLayout combination
NumPlanes() int
}
Parameters represents a set of parameters for encoding
type Stream ¶ added in v1.6.1
type Stream interface {
// Return AUDIO, VIDEO, SUBTITLE or DATA
Type() Type
// Return the stream parameters
Parameters() Parameters
}
Stream represents a audio, video, subtitle or data stream within a media file
type VideoParameters ¶ added in v1.6.7
type VideoParameters interface {
// Return the width of the video frame
Width() int
// Return the height of the video frame
Height() int
// Return the pixel format
PixelFormat() string
}
Video parameters for encoding or decoding video data.