oggreader

package
v4.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 5 Imported by: 15

Documentation

Overview

Package oggreader implements the Ogg media container reader

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWith

func NewWith(in io.Reader) (*OggReader, *OggHeader, error)

NewWith returns a new Ogg reader and Ogg header with an io.Reader input.

Warning: NewWith only parses the first OpusHead (a single logical bitstream/track) and returns a single OggHeader. If you need to handle Ogg containers with multiple Opus headers/tracks, use NewWithOptions and scan pages (e.g. via ParseNextPage) to find and parse each OpusHead.

Types

type HeaderType added in v4.2.0

type HeaderType string
const (
	HeaderOpusID   HeaderType = "OpusHead"
	HeaderOpusTags HeaderType = "OpusTags"
)

type OggHeader

type OggHeader struct {
	ChannelMap   uint8
	Channels     uint8
	OutputGain   uint16
	PreSkip      uint16
	SampleRate   uint32
	Version      uint8
	StreamCount  uint8
	CoupledCount uint8
	// ChannelMapping we store it as a string to be comparable (maps/struct equality)
	// while still holding raw bytes.
	ChannelMapping string
}

OggHeader contains Opus codec metadata parsed from an Opus ID page. This header is extracted from an Ogg page payload that starts with the OpusHead signature (the first page of an Opus stream in an Ogg container).

Use OggPageHeader.OpusPacketType() to classify a page payload as OpusHead, and OggPageHeader.ParseOpusHeader() to parse the OpusHead payload.

https://tools.ietf.org/html/rfc7845.html#section-3

func ParseOpusHead added in v4.2.0

func ParseOpusHead(payload []byte) (*OggHeader, error)

ParseOpusHead parses an Opus head from the page payload.

type OggPageHeader

type OggPageHeader struct {
	GranulePosition uint64

	Serial uint32
	// contains filtered or unexported fields
}

OggPageHeader is the metadata for a Page Pages are the fundamental unit of multiplexing in an Ogg stream

https://tools.ietf.org/html/rfc7845.html#section-1

func (*OggPageHeader) HeaderType added in v4.2.0

func (p *OggPageHeader) HeaderType(payload []byte) (HeaderType, bool)

HeaderType classifies the page.

type OggReader

type OggReader struct {
	// contains filtered or unexported fields
}

OggReader is used to read Ogg files and return page payloads.

func NewWithOptions added in v4.2.0

func NewWithOptions(in io.Reader, options ...Option) (*OggReader, error)

NewWithOptions returns a new Ogg reader.

func (*OggReader) ParseNextPage

func (o *OggReader) ParseNextPage() ([]byte, *OggPageHeader, error)

ParseNextPage reads from stream and returns Ogg page payload, header, and an error if there is incomplete page data.

func (*OggReader) ResetReader

func (o *OggReader) ResetReader(reset func(bytesRead int64) io.Reader)

ResetReader resets the internal stream of OggReader. This is useful for live streams, where the end of the file might be read without the data being finished.

type Option added in v4.2.0

type Option func(*OggReader) error

func WithDoChecksum added in v4.2.0

func WithDoChecksum(doChecksum bool) Option

WithDoChecksum is an option to set the doChecksum flag Default is true.

type OpusTags added in v4.2.0

type OpusTags struct {
	Vendor       string
	UserComments []UserComment
}

OpusTags is the metadata for an OpusTags page. https://www.xiph.org/vorbis/doc/v-comment.html

func ParseOpusTags added in v4.2.0

func ParseOpusTags(payload []byte) (*OpusTags, error)

ParseOpusTags parses an OpusTags from the page payload. https://datatracker.ietf.org/doc/html/rfc7845#section-5.2

type UserComment added in v4.2.0

type UserComment struct {
	Comment string
	Value   string
}

UserComment is a key-value pair of a vorbis comment.

Jump to

Keyboard shortcuts

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