media

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format interface {
	// The type of the format, which can be combinations of
	// INPUT, OUTPUT, DEVICE, AUDIO, VIDEO and SUBTITLE
	Type() Type

	// The unique name that the format can be referenced as
	Name() string

	// Description of the format
	Description() string
}

A container format for a media file

type Frame

type Frame interface{}

A frame of decoded data

type FrameFunc

type FrameFunc func(int, Frame) error

FrameFunc 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 Manager

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, ...Par) (Media, error)

	// Return supported input and output container formats which match any filter,
	// which can be a name, extension (with preceeding period) or mimetype. The Type
	// can be a combination of DEVICE, INPUT, OUTPUT or ANY to select the right kind of
	// format
	Formats(Type, ...string) []Format

	// Return all supported sample formats
	SampleFormats() []Metadata

	// Return all supported pixel formats
	PixelFormats() []Metadata

	// Return standard channel layouts which can be used for audio,
	// with the number of channels provided. If no channels are provided,
	// then all standard channel layouts are returned.
	ChannelLayouts() []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(Type, ...string) []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)

	// Decode an input stream, determining the streams to be decoded
	// and the function to accept the decoded frames. If MapFunc is nil,
	// all streams are passed through (demultiplexing).
	Decode(context.Context, Media, MapFunc, FrameFunc) error
}

Manager represents a manager for media formats and devices. Create a new manager object using the NewManager function.

	  import "github.com/mutablelogic/go-media/pkg/ffmpeg"

	  manager, err := ffmpeg.NewManager()
	  if err != nil {
		...
      }

Various options are available to control the manager, for logging and affecting decoding, that can be applied when creating the manager by passing them as arguments.

Only one manager can be created. If NewManager is called a second time, the previously created manager is returned, but any new options are applied.

type MapFunc

type MapFunc func(int, Par) (Par, error)

MapFunc return parameters if a stream should be decoded, resampled (for audio streams) or resized (for video streams). 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 Media

type Media interface {
	io.Closer

	// The type of the format, which can be combinations of
	// INPUT or OUTPUT
	Type() Type
}

A container format for a media file, reader, device or network stream

type Par

type Par interface{}

Parameters for a stream or frame

Directories

Path Synopsis
cmd
examples/decode command
examples/demux command
examples/encode command
examples/sdlplayer command
This example demonstrates how to play audio and video files using SDL2.
This example demonstrates how to play audio and video files using SDL2.
examples/server command
ffmpeg/remux command
media command

Jump to

Keyboard shortcuts

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