Documentation
¶
Index ¶
- func Protocols() []string
- type Decoder
- type FrameFn
- type Opt
- type PacketFn
- type Reader
- func (r *Reader) Close() error
- func (r *Reader) Decode(ctx context.Context, packetfn PacketFn, decoder *Decoder) error
- func (r *Reader) Duration() time.Duration
- func (r *Reader) Format() *profile.Format
- func (r *Reader) Metadata(keys ...string) []gomedia.Metadata
- func (r *Reader) Rotation(stream int) int
- func (r *Reader) SampleAspectRatio(stream int) ff.AVRational
- func (r *Reader) Seek(stream int, d time.Duration) error
- func (r *Reader) StartTime(stream int) time.Duration
- func (r *Reader) Streams() map[int]profile.Profile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Protocols ¶
func Protocols() []string
Protocols returns the name of every I/O protocol FFmpeg has registered for reading (e.g. "file", "http", "https", "rtmp", "udp", "tcp", ...) - the URL scheme a Reader's url actually travels over, which is a different axis from a container format: e.g. "rtsp://host/stream" is demuxed by the "rtsp" input format, but reaches the network via the "tcp"/"udp" protocol - "rtsp" itself is typically not in this list. Useful for validating a URL's scheme before passing it to Open/NewReader.
Types ¶
type Decoder ¶
Decoder decodes packets from a set of registered streams into frames, passing each frame to fn. Pass a Decoder to Reader.Decode alongside a PacketFn to decode selected streams while still seeing every packet.
Streams are opted in with Add. A stream that isn't registered is discarded from the decoder's point of view: Reader.Decode still passes its packets to the PacketFn (if any), but they are never sent to a codec.
func NewDecoder ¶
NewDecoder creates an empty Decoder that passes every frame it decodes to fn. Use Add to register which streams should be decoded before passing the Decoder to Reader.Decode.
func (*Decoder) Add ¶
Add registers stream for decoding. Streams which are never registered are left alone by Reader.Decode - this is how you discard a stream from frame decoding without affecting the PacketFn. The options are codec options as key=value pairs, such as "skip_frame=nokey" to only decode keyframes.
type FrameFn ¶
FrameFn is called for each frame a Decoder produces - an *frame.AudioFrame or *frame.VideoFrame for audio/video streams, or a *frame.SubtitleFrame for subtitle streams (which FFmpeg decodes via a completely separate, legacy API). Returning io.EOF stops decoding early without being treated as an error.
type Opt ¶
type Opt func(o *opts) error
func WithInput ¶
WithInput sets the input format and format options for reading. The format parameter specifies the input format name (e.g., "s16le", "mp3"). If format is empty, only the options are set without changing the format. Additional options are key=value pairs (e.g., "sample_rate=22050", "channels=1").
Example:
WithInput("s16le", "sample_rate=22050", "channels=1", "sample_fmt=s16")
WithInput("", "analyzeduration=1000000") // Only set options
type PacketFn ¶
PacketFn is called for each packet read by Reader.Decode. Returning io.EOF stops decoding early without being treated as an error.
type Reader ¶
Reader is a wrapper around an AVFormatContext that provides a higher-level interface for reading media files.
func (*Reader) Decode ¶
Decode packets from the media stream, calling packetfn for every packet read from any stream - use this for stream copying or remuxing without transcoding. If decoder is non-nil, packets from streams registered with decoder.Add are also decoded into frames and passed to the Decoder's FrameFn; streams not registered with the Decoder are left as packets only. packetfn and decoder may not both be nil.
The reading can be interrupted by cancelling the context, or by either callback returning an error or io.EOF. The latter will end the reading process early but will not return an error.
func (*Reader) Metadata ¶
Return the metadata for the media stream, filtering by the specified keys if there are any. Artwork and chapters are excluded even when keys is empty ("no filter") - artwork because it's binary content rather than a descriptive tag, and chapters because each is a structured start/end/tags value rather than a flat string one, so a caller has to ask for the "artwork"/"chapter" key by name to get either back.
func (*Reader) Rotation ¶ added in v1.11.4
Rotation returns how a video stream is rotated to be displayed upright, from its display matrix, in degrees clockwise: 0, 90, 180 or 270, or 0 when it has no display matrix, or one which isn't a quarter turn
func (*Reader) SampleAspectRatio ¶ added in v1.11.1
func (r *Reader) SampleAspectRatio(stream int) ff.AVRational
SampleAspectRatio returns the sample aspect ratio of a video stream, the width of a pixel divided by its height: the container's if it gives one, such as from Matroska's display size, or the codec's, as av_guess_sample_aspect_ratio does without a frame. It's 0:1 if neither gives one, or the stream isn't found.
func (*Reader) Seek ¶
Seek to a specific time in the media stream, in the stream's own timestamps (see StartTime)
func (*Reader) StartTime ¶ added in v1.11.1
StartTime returns the time of the first frame of a stream, in the stream's own timestamps, which isn't zero for some formats, such as MPEG-TS. It's zero if it's unknown, or the stream isn't found.
func (*Reader) Streams ¶
Return every stream in the media file as profiles, keyed by their real stream index — mirroring the shape writer.WithProfile expects, so a caller can remux the whole container directly without dropping any stream:
for i, p := range r.Streams() {
opts = append(opts, writer.WithProfile(i, p))
}
Attached-pic (cover art) streams are omitted; artwork is available via Metadata's "artwork" key instead.