mpeg4audio

package
v2.8.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 2 Imported by: 42

Documentation

Overview

Package mpeg4audio contains utilities to work with MPEG-4 audio codecs.

Index

Constants

View Source
const (
	// MaxAccessUnitSize is the maximum size of an access unit.
	MaxAccessUnitSize = 5 * 1024

	// SamplesPerAccessUnit is the number of samples contained inside an access unit.
	SamplesPerAccessUnit = 1024
)

Variables

This section is empty.

Functions

func CountChannelsFromRawDataBlock added in v2.7.0

func CountChannelsFromRawDataBlock(au []byte) (int, error)

CountChannelsFromRawDataBlock counts channels by parsing the syntactic elements in an AAC raw_data_block. This is used when channel_configuration is 0 and no PCE is present (FFmpeg often omits PCE and uses implicit default ordering).

Per ISO 14496-3, when channel_configuration=0, the channel layout can be determined either from an explicit PCE or inferred from the elements present. Common implicit layouts:

  • 1 CPE = stereo (2 channels)
  • 1 SCE + 1 CPE = 3.0 (3 channels: C, L, R)
  • 1 SCE + 1 CPE + 1 CPE + 1 LFE = 5.1 (6 channels: C, L, R, Ls, Rs, LFE)

Types

type ADTSPacket

type ADTSPacket struct {
	Type       ObjectType
	SampleRate int

	// 0: channel layout defined by a PCE at the start of raw_data_block
	// 1-6: channel count is equal to channel configuration
	// 7: channel count is 8
	// 8-15: reserved
	ChannelConfig uint8

	// Deprecated: replaced by ChannelConfig
	ChannelCount int

	AU []byte
}

ADTSPacket is an ADTS packet. Specification: ISO 14496-3, Table 1.A.5

type ADTSPackets

type ADTSPackets []*ADTSPacket

ADTSPackets is a group of ADTS packets.

func (ADTSPackets) Marshal

func (ps ADTSPackets) Marshal() ([]byte, error)

Marshal encodes ADTS packets into an ADTS stream.

func (*ADTSPackets) Unmarshal

func (ps *ADTSPackets) Unmarshal(buf []byte) error

Unmarshal decodes an ADTS stream into ADTS packets.

type AudioMuxElement added in v2.4.0

type AudioMuxElement struct {
	// when unmarshaling, it must be filled
	MuxConfigPresent bool

	// when unmarshaling,
	// it must be filled when MuxConfigPresent=false
	// and it is filled when MuxConfigPresent=true and there's a config in the element
	StreamMuxConfig *StreamMuxConfig

	// used when MuxConfigPresent=true
	UseSameStreamMux bool

	// Payloads. Indexes are: subframe, program, layer.
	Payloads [][][][]byte
}

AudioMuxElement is an AudioMuxElement. Specification: ISO 14496-3, Table 1.41

func (AudioMuxElement) Marshal added in v2.4.0

func (e AudioMuxElement) Marshal() ([]byte, error)

Marshal encodes an AudioMuxElement.

func (*AudioMuxElement) Unmarshal added in v2.4.0

func (e *AudioMuxElement) Unmarshal(buf []byte) error

Unmarshal decodes an AudioMuxElement.

type AudioSpecificConfig

type AudioSpecificConfig struct {
	Type       ObjectType
	SampleRate int

	// 0: channel layout defined by a PCE either in GASpecificConfig or the start of raw_data_block
	// 1-6: channel count is equal to channel configuration
	// 7: channel count is 8
	// 8-15: reserved
	ChannelConfig uint8

	// Deprecated: replaced by ChannelConfig
	ChannelCount int

	// SBR / PS specific
	ExtensionType       ObjectType
	ExtensionSampleRate int

	// GASpecificConfig
	FrameLengthFlag    bool
	DependsOnCoreCoder bool
	CoreCoderDelay     uint16
}

AudioSpecificConfig is an AudioSpecificConfig. Specification: ISO 14496-3, 1.6.2.1

func (AudioSpecificConfig) Marshal

func (c AudioSpecificConfig) Marshal() ([]byte, error)

Marshal encodes a AudioSpecificConfig.

func (*AudioSpecificConfig) Unmarshal

func (c *AudioSpecificConfig) Unmarshal(buf []byte) error

Unmarshal decodes a AudioSpecificConfig.

func (*AudioSpecificConfig) UnmarshalFromPos deprecated

func (c *AudioSpecificConfig) UnmarshalFromPos(buf []byte, pos *int) error

UnmarshalFromPos decodes a AudioSpecificConfig.

Deprecated: not meant to be public.

type AudioSyncStream added in v2.4.0

type AudioSyncStream struct {
	AudioMuxElements [][]byte
}

AudioSyncStream is an AudioSyncStream. Specification: ISO 14496-3, Table 1.36

func (AudioSyncStream) Marshal added in v2.4.0

func (s AudioSyncStream) Marshal() ([]byte, error)

Marshal encodes an AudioSyncStream.

func (*AudioSyncStream) Unmarshal added in v2.4.0

func (s *AudioSyncStream) Unmarshal(buf []byte) error

Unmarshal decodes an AudioSyncStream.

type Config deprecated

type Config = AudioSpecificConfig

Config is an alias for AudioSpecificConfig.

Deprecated: replaced by AudioSpecificConfig.

type ObjectType

type ObjectType int

ObjectType is a MPEG-4 Audio object type. Specification: ISO 14496-3, Table 1.17

const (
	ObjectTypeAACLC ObjectType = 2
	ObjectTypeSBR   ObjectType = 5
	ObjectTypePS    ObjectType = 29
)

supported types.

type ProgramConfigElement added in v2.7.0

type ProgramConfigElement struct {
	ElementInstanceTag      uint8
	ObjectType              uint8
	SamplingFrequencyIndex  uint8
	NumFrontChannelElements uint8
	NumSideChannelElements  uint8
	NumBackChannelElements  uint8
	NumLFEChannelElements   uint8
	NumAssocDataElements    uint8
	NumValidCCElements      uint8
	ChannelCount            int
}

ProgramConfigElement represents an AAC Program Config Element. Specification: ISO/IEC 14496-3, table 4.2

func ParsePCEFromRawDataBlock added in v2.7.0

func ParsePCEFromRawDataBlock(au []byte) (*ProgramConfigElement, error)

ParsePCEFromRawDataBlock attempts to parse a PCE from the start of an AAC raw_data_block. This is used when channel_configuration is 0 in the ADTS header. The raw_data_block starts with an id_syn_ele (3 bits) which identifies the element type. PCE has id_syn_ele = 5.

type StreamMuxConfig

type StreamMuxConfig struct {
	NumSubFrames     uint
	Programs         []*StreamMuxConfigProgram
	OtherDataPresent bool
	OtherDataLenBits uint32
	CRCCheckPresent  bool
	CRCCheckSum      uint8
}

StreamMuxConfig is a StreamMuxConfig. Specification: ISO 14496-3, Table 1.42

func (StreamMuxConfig) Marshal

func (c StreamMuxConfig) Marshal() ([]byte, error)

Marshal encodes a StreamMuxConfig.

func (*StreamMuxConfig) Unmarshal

func (c *StreamMuxConfig) Unmarshal(buf []byte) error

Unmarshal decodes a StreamMuxConfig.

type StreamMuxConfigLayer

type StreamMuxConfigLayer struct {
	AudioSpecificConfig       *AudioSpecificConfig
	FrameLengthType           uint
	LatmBufferFullness        uint
	FrameLength               uint
	CELPframeLengthTableIndex uint
	HVXCframeLengthTableIndex bool
}

StreamMuxConfigLayer is a layer of a StreamMuxConfig.

type StreamMuxConfigProgram

type StreamMuxConfigProgram struct {
	Layers []*StreamMuxConfigLayer
}

StreamMuxConfigProgram is a program of a StreamMuxConfig.

Jump to

Keyboard shortcuts

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