Documentation
¶
Overview ¶
Package matroska provides a high-level Matroska muxer and demuxer.
The package accepts normalized codec frames/access units. It does not parse RTP, repair packet loss, depacketize codecs, or depend on protocol packages.
Index ¶
- Constants
- Variables
- func Descriptor() format.Descriptor
- func Register(registry *format.SimpleRegistry)
- type Attachment
- type AudioConfig
- type BlockAddition
- type BlockAdditionMapping
- type Chapter
- type ChapterDisplay
- type ChapterEdition
- type Codec
- type ContentCompression
- type ContentEncAESSettings
- type ContentEncoding
- type ContentEncryption
- type ContentEncryptionKey
- type CuePoint
- type CuePolicy
- type CueReference
- type CueTrackPosition
- type Demuxer
- func (d *Demuxer) Attachments() []Attachment
- func (d *Demuxer) CanSeek() bool
- func (d *Demuxer) Chapters() []ChapterEdition
- func (d *Demuxer) Cues() []CuePoint
- func (d *Demuxer) DocType() string
- func (d *Demuxer) Info() SegmentInfo
- func (d *Demuxer) ReadCuedPacketAtTime(timeNS int64, dst *Packet) error
- func (d *Demuxer) ReadCuedTrackPacketAtTime(trackID uint32, timeNS int64, dst *Packet) error
- func (d *Demuxer) ReadPacket(dst *Packet) error
- func (d *Demuxer) ReadPacketAtTime(timeNS int64, dst *Packet) error
- func (d *Demuxer) ReadTrackPacketAtTime(trackID uint32, timeNS int64, dst *Packet) error
- func (d *Demuxer) SeekEntries() []SeekEntry
- func (d *Demuxer) SeekToTime(timeNS int64) error
- func (d *Demuxer) SeekToTrackTime(trackID uint32, timeNS int64) error
- func (d *Demuxer) Tags() []Tag
- func (d *Demuxer) Tracks() []Track
- func (d *Demuxer) UnknownAttachmentsElements() []UnknownElement
- func (d *Demuxer) UnknownChaptersElements() []UnknownElement
- func (d *Demuxer) UnknownSegmentElements() []UnknownElement
- func (d *Demuxer) UnknownTagsElements() []UnknownElement
- func (d *Demuxer) UnknownTracksElements() []UnknownElement
- type DemuxerFactory
- type DemuxerOptions
- type FormatDemuxer
- func (d *FormatDemuxer) CanSeek() bool
- func (d *FormatDemuxer) Close() error
- func (d *FormatDemuxer) Format() av.FormatID
- func (d *FormatDemuxer) Open(ctx context.Context, input format.Input, _ format.OpenOptions) error
- func (d *FormatDemuxer) ReadInto(ctx context.Context, out *format.ReadResult) error
- func (d *FormatDemuxer) Seek(ctx context.Context, position time.Duration) error
- func (d *FormatDemuxer) Streams() []av.Stream
- type FormatMuxer
- type LacedPacket
- type LacingMode
- type Muxer
- type MuxerFactory
- type MuxerOptions
- type Packet
- type Prober
- type SeekEntry
- type SegmentInfo
- type SimpleTag
- type Tag
- type TagTarget
- type Track
- type TrackDemuxer
- type TrackMuxer
- type TrackTranslate
- type TrackType
- type UnknownElement
- type VideoColourConfig
- type VideoConfig
- type VideoMasteringMetadataConfig
- type VideoProjectionConfig
Constants ¶
const ( ContentEncodingScopeBlock uint64 = 1 ContentEncodingScopePrivate uint64 = 2 ContentEncodingScopeNext uint64 = 4 ContentEncodingTypeCompression uint64 = 0 ContentEncodingTypeEncryption uint64 = 1 ContentCompAlgoZlib uint64 = 0 ContentCompAlgoBzlib uint64 = 1 ContentCompAlgoLZO1X uint64 = 2 ContentCompAlgoHeaderStripping uint64 = 3 ContentEncAlgoNotEncrypted uint64 = 0 ContentEncAlgoDES uint64 = 1 ContentEncAlgoTripleDES uint64 = 2 ContentEncAlgoTwofish uint64 = 3 ContentEncAlgoBlowfish uint64 = 4 ContentEncAlgoAES uint64 = 5 ContentEncAESCipherModeCTR uint64 = 1 ContentEncAESCipherModeCBC uint64 = 2 ContentSigAlgoNotSigned uint64 = 0 ContentSigAlgoRSA uint64 = 1 ContentSigHashAlgoNotSigned uint64 = 0 ContentSigHashAlgoSHA1 uint64 = 1 ContentSigHashAlgoMD5 uint64 = 2 )
Variables ¶
var ( ErrNilReader = errors.New("matroska: nil reader") ErrNilWriter = errors.New("matroska: nil writer") ErrNilPacket = errors.New("matroska: nil packet") ErrClosed = errors.New("matroska: closed") ErrInvalidTrack = errors.New("matroska: invalid track") ErrUnknownTrack = errors.New("matroska: unknown track") ErrNonSeekableReader = errors.New("matroska: reader is not seekable") ErrTrackAfterWrite = errors.New("matroska: cannot add track after writing packets") ErrUnsupportedCodec = errors.New("matroska: unsupported codec") ErrUnsupportedElement = errors.New("matroska: unsupported element") ErrUnsupportedContentEncoding = errors.New("matroska: content encoding is not supported") ErrLZOContentEncoding = errors.New("matroska: LZO content encoding is not supported") ErrBzip2ContentEncodingWrite = errors.New("matroska: writing bzip2 content encoding is not supported (read-only)") ErrUnsupportedLacing = errors.New("matroska: lacing is not supported") ErrLaceTooLarge = errors.New("matroska: laced block exceeds configured bounds") ErrInvalidData = errors.New("matroska: invalid data") ErrSeekHeadTooSmall = errors.New("matroska: reserved seek head is too small") ErrPayloadTooSmall = errors.New("matroska: packet data capacity too small") ErrTimecodeOverflow = errors.New("matroska: block timecode out of range") )
Functions ¶
func Descriptor ¶
func Descriptor() format.Descriptor
func Register ¶
func Register(registry *format.SimpleRegistry)
Types ¶
type Attachment ¶
type AudioConfig ¶
type BlockAddition ¶
type BlockAdditionMapping ¶
type ChapterDisplay ¶
type ChapterDisplay struct {
String string
Language string
LanguageBCP47 string
Country string
UnknownElements []UnknownElement
}
type ChapterEdition ¶
type ContentCompression ¶
type ContentEncAESSettings ¶
type ContentEncAESSettings struct {
CipherMode uint64
}
type ContentEncoding ¶
type ContentEncoding struct {
Order uint64
Scope uint64
Type uint64
Compression ContentCompression
CompressionSet bool
Encryption ContentEncryption
EncryptionSet bool
}
type ContentEncryption ¶
type ContentEncryptionKey ¶
type CuePolicy ¶
type CuePolicy int
CuePolicy controls which packets are indexed in seekable output.
const ( // CuePolicyDefault indexes audio packets and keyframe video packets. CuePolicyDefault CuePolicy = iota // CuePolicyKeyframes indexes only packets marked as keyframes. CuePolicyKeyframes // CuePolicyAllPackets indexes every written packet or laced block. CuePolicyAllPackets // CuePolicyNone disables cue collection and Cues writing. CuePolicyNone )
type CueReference ¶
type CueTrackPosition ¶
type Demuxer ¶
type Demuxer struct {
// contains filtered or unexported fields
}
func NewDemuxer ¶
func NewDemuxer(r io.Reader, opts DemuxerOptions) (*Demuxer, error)
func (*Demuxer) Attachments ¶
func (d *Demuxer) Attachments() []Attachment
func (*Demuxer) CanSeek ¶
CanSeek reports whether the reader can reposition: it is an io.Seeker that knows its position, which a pipe does not.
func (*Demuxer) Chapters ¶
func (d *Demuxer) Chapters() []ChapterEdition
func (*Demuxer) Info ¶
func (d *Demuxer) Info() SegmentInfo
func (*Demuxer) ReadCuedPacketAtTime ¶
ReadCuedPacketAtTime seeks to the first cue at or after timeNS and reads the cued packet. Exact block cues jump to the block; cluster-only cues scan within the referenced Cluster until the cue's track/time is reached. It does not scan uncued packets between cues; use ReadPacketAtTime when uncued packets should be considered too.
func (*Demuxer) ReadCuedTrackPacketAtTime ¶
ReadCuedTrackPacketAtTime seeks to the first cue for trackID at or after timeNS and reads that cued packet. Exact block cues jump to the block; cluster-only cues scan within the referenced Cluster until the cue's track/time is reached. It does not scan uncued packets between cues; use ReadTrackPacketAtTime when uncued packets should be considered too.
func (*Demuxer) ReadPacket ¶
ReadPacket reads the next packet into dst. The read is zero-allocation by contract: the payload is written into dst.Data's existing capacity (Reset keeps the backing array), so the caller sizes dst.Data once — for example make([]byte, 0, maxPacketSize) — and a payload that does not fit is refused with ErrPayloadTooSmall instead of growing the buffer. io.EOF reports the end of the media.
func (*Demuxer) ReadPacketAtTime ¶
ReadPacketAtTime reads the first packet at or after timeNS. Seekable readers use a direct packet index when Cues are absent or too sparse to identify uncued packets without scanning.
func (*Demuxer) ReadTrackPacketAtTime ¶
ReadTrackPacketAtTime reads the first packet for trackID at or after timeNS. Seekable readers use a direct packet index when Cues are absent or too sparse for that track.
func (*Demuxer) SeekEntries ¶
func (*Demuxer) SeekToTime ¶
func (*Demuxer) SeekToTrackTime ¶
SeekToTrackTime seeks to the nearest preceding cue for trackID and timeNS. If the requested time is before that track's first cue, it seeks to the first cue for the track.
func (*Demuxer) UnknownAttachmentsElements ¶
func (d *Demuxer) UnknownAttachmentsElements() []UnknownElement
func (*Demuxer) UnknownChaptersElements ¶
func (d *Demuxer) UnknownChaptersElements() []UnknownElement
func (*Demuxer) UnknownSegmentElements ¶
func (d *Demuxer) UnknownSegmentElements() []UnknownElement
func (*Demuxer) UnknownTagsElements ¶
func (d *Demuxer) UnknownTagsElements() []UnknownElement
func (*Demuxer) UnknownTracksElements ¶
func (d *Demuxer) UnknownTracksElements() []UnknownElement
type DemuxerFactory ¶
type DemuxerFactory struct{}
func (DemuxerFactory) NewDemuxer ¶
func (DemuxerFactory) NewDemuxer(ctx context.Context, result format.ProbeResult) (format.Demuxer, error)
type DemuxerOptions ¶
type DemuxerOptions struct {
MaxElementSize uint64
MaxLaceFrames int
MaxLacePayload int
ContentEncryptionKeys []ContentEncryptionKey
}
type FormatDemuxer ¶
type FormatDemuxer struct {
// contains filtered or unexported fields
}
FormatDemuxer adapts a Matroska-family demuxer to format.Demuxer. The zero value reads Matroska; NewFormatDemuxer reads a profile through its own demuxer.
func NewFormatDemuxer ¶
func NewFormatDemuxer(format av.FormatID, open func(io.Reader) (TrackDemuxer, error)) *FormatDemuxer
NewFormatDemuxer returns the adapter reading format through the demuxer open returns for each input.
func (*FormatDemuxer) CanSeek ¶
func (d *FormatDemuxer) CanSeek() bool
CanSeek reports whether the opened input can reposition (format.Seeker): the track demuxer's CanSeek when it has one.
func (*FormatDemuxer) Close ¶
func (d *FormatDemuxer) Close() error
func (*FormatDemuxer) Format ¶
func (d *FormatDemuxer) Format() av.FormatID
func (*FormatDemuxer) Open ¶
func (d *FormatDemuxer) Open(ctx context.Context, input format.Input, _ format.OpenOptions) error
func (*FormatDemuxer) ReadInto ¶
func (d *FormatDemuxer) ReadInto(ctx context.Context, out *format.ReadResult) error
func (*FormatDemuxer) Seek ¶
Seek implements format.Seeker: it repositions the demuxer to the nearest cue at or before position (falling back to the demuxer's cluster index when the file carries no Cues), so the next ReadInto resumes at a keyframe-aligned point at or before position. Input opened from a reader that cannot seek reports an error wrapping format.ErrNotSeekable.
func (*FormatDemuxer) Streams ¶
func (d *FormatDemuxer) Streams() []av.Stream
type FormatMuxer ¶
type FormatMuxer struct {
// contains filtered or unexported fields
}
FormatMuxer adapts a Matroska-family muxer to format.Muxer. The zero value writes Matroska; NewFormatMuxer writes a profile through its own muxer.
func NewFormatMuxer ¶
func NewFormatMuxer(format av.FormatID, open func(io.Writer) (TrackMuxer, error)) *FormatMuxer
NewFormatMuxer returns the adapter writing format through the muxer open returns for each output.
func (*FormatMuxer) Close ¶
func (m *FormatMuxer) Close() error
func (*FormatMuxer) Format ¶
func (m *FormatMuxer) Format() av.FormatID
func (*FormatMuxer) Open ¶
func (m *FormatMuxer) Open(ctx context.Context, output format.Output, streams []av.Stream, _ format.OpenOptions) error
func (*FormatMuxer) Write ¶
func (m *FormatMuxer) Write(ctx context.Context, packet *av.Packet, _ *format.WriteResult) error
type LacedPacket ¶
type LacedPacket struct {
TrackID uint32
TimeNS int64
FrameDurationNS int64
ReferenceBlockTimeNS []int64
ReferencePriority uint64
DiscardPaddingNS int64
CodecState []byte
BlockAdditions []BlockAddition
UnknownClusterElements []UnknownElement
Keyframe bool
Invisible bool
Discardable bool
Lacing LacingMode
Frames [][]byte
}
LacedPacket writes multiple frames for one track into a single laced block. Frame timestamps are derived by demuxers from FrameDurationNS when set, or from the track default duration otherwise.
type LacingMode ¶
type LacingMode int
LacingMode selects how multiple frames are packed into one laced block.
const ( // LacingAuto uses fixed-size lacing for equal-sized frames and EBML lacing // otherwise. LacingAuto LacingMode = iota // LacingXiph writes Xiph lacing. LacingXiph // LacingEBML writes EBML lacing. LacingEBML // LacingFixed writes fixed-size lacing and requires equal-sized frames. LacingFixed )
type Muxer ¶
type Muxer struct {
// contains filtered or unexported fields
}
func (*Muxer) WriteLacedPacket ¶
func (m *Muxer) WriteLacedPacket(packet LacedPacket) error
WriteLacedPacket writes multiple frames for one track into one laced block. It uses SimpleBlock unless BlockGroup-only metadata is present. For timestamp-accurate SimpleBlock demuxing, the track should declare DefaultDurationNS. When FrameDurationNS is set, a BlockGroup is written and the demuxer returns that per-frame duration for each laced frame.
func (*Muxer) WritePacket ¶
type MuxerFactory ¶
type MuxerFactory struct{}
type MuxerOptions ¶
type MuxerOptions struct {
DocType string
DocTypeVersion uint64
DocTypeReadVersion uint64
MuxingApp string
WritingApp string
Info SegmentInfo
Attachments []Attachment
Chapters []ChapterEdition
Tags []Tag
UnknownSegmentElements []UnknownElement
UnknownTracksElements []UnknownElement
UnknownAttachmentsElements []UnknownElement
UnknownChaptersElements []UnknownElement
UnknownTagsElements []UnknownElement
TimecodeScaleNS int64
ClusterMaxDurationNS int64
Streaming bool
CueCapacity int
CuePolicy CuePolicy
WriteCRC32 bool
ContentEncryptionKeys []ContentEncryptionKey
ContentEncryptionInitialIV []byte
}
type Packet ¶
type Packet struct {
TrackID uint32
TimeNS int64
DurationNS int64
ReferenceBlockTimeNS []int64
ReferencePriority uint64
DiscardPaddingNS int64
CodecState []byte
BlockAdditions []BlockAddition
Keyframe bool
Invisible bool
Discardable bool
Data []byte
ContentEncryptionPartitions []uint32
UnknownClusterElements []UnknownElement
}
type Prober ¶
type Prober struct{}
func (Prober) Probe ¶
func (Prober) Probe(ctx context.Context, request format.ProbeRequest) (format.ProbeResult, error)
type SegmentInfo ¶
type Tag ¶
type Tag struct {
Target TagTarget
Simple []SimpleTag
UnknownElements []UnknownElement
}
type Track ¶
type Track struct {
ID uint32
UID uint64
Type TrackType
Codec Codec
Name string
Language string
LanguageBCP47 string
CodecName string
TimebaseNum int64
TimebaseDen int64
DefaultDurationNS int64
DefaultDecodedFieldDurationNS int64
TrackTimestampScale float64
TrackTimestampScaleSet bool
TrackOffsetNS int64
TrackOffsetSet bool
MinCache uint64
MinCacheSet bool
MaxCache uint64
MaxCacheSet bool
CodecDecodeAll bool
CodecDecodeAllSet bool
CodecDelayNS int64
SeekPreRollNS int64
FlagEnabled bool
FlagEnabledSet bool
FlagDefault bool
FlagDefaultSet bool
FlagForced bool
FlagForcedSet bool
FlagHearingImpaired bool
FlagHearingImpairedSet bool
FlagVisualImpaired bool
FlagVisualImpairedSet bool
FlagTextDescriptions bool
FlagTextDescriptionsSet bool
FlagOriginal bool
FlagOriginalSet bool
FlagCommentary bool
FlagCommentarySet bool
FlagLacing bool
FlagLacingSet bool
MaxBlockAdditionID uint64
BlockAdditionMappings []BlockAdditionMapping
TrackOverlays []uint64
TrackTranslates []TrackTranslate
ContentEncodings []ContentEncoding
Audio AudioConfig
Video VideoConfig
UnknownElements []UnknownElement
CodecPrivate []byte
}
type TrackDemuxer ¶
TrackDemuxer is the packet demuxer the av adapter reads through: *Demuxer, or a profile's demuxer.
type TrackMuxer ¶
type TrackMuxer interface {
AddTrack(Track) (uint32, error)
WritePacket(Packet) error
Close() error
}
TrackMuxer is the packet muxer the av adapter writes through: *Muxer, or a profile's muxer, such as WebM's, that checks tracks against the profile.
type TrackTranslate ¶
type UnknownElement ¶
type VideoColourConfig ¶
type VideoColourConfig struct {
MatrixCoefficients int
MatrixCoefficientsSet bool
BitsPerChannel int
BitsPerChannelSet bool
ChromaSubsamplingHorz int
ChromaSubsamplingHorzSet bool
ChromaSubsamplingVert int
ChromaSubsamplingVertSet bool
CbSubsamplingHorz int
CbSubsamplingHorzSet bool
CbSubsamplingVert int
CbSubsamplingVertSet bool
ChromaSitingHorz int
ChromaSitingHorzSet bool
ChromaSitingVert int
ChromaSitingVertSet bool
Range int
RangeSet bool
TransferCharacteristics int
TransferCharacteristicsSet bool
Primaries int
PrimariesSet bool
MaxCLL int
MaxCLLSet bool
MaxFALL int
MaxFALLSet bool
MasteringMetadata VideoMasteringMetadataConfig
}
type VideoConfig ¶
type VideoConfig struct {
Width int
Height int
FlagInterlaced int
FlagInterlacedSet bool
FieldOrder int
FieldOrderSet bool
StereoMode int
StereoModeSet bool
AlphaMode int
AlphaModeSet bool
PixelCropBottom int
PixelCropTop int
PixelCropLeft int
PixelCropRight int
DisplayWidth int
DisplayHeight int
DisplayUnit int
AspectRatioType int
AspectRatioTypeSet bool
Colour VideoColourConfig
Projection VideoProjectionConfig
}
type VideoMasteringMetadataConfig ¶
type VideoMasteringMetadataConfig struct {
PrimaryRChromaticityX float64
PrimaryRChromaticityXSet bool
PrimaryRChromaticityY float64
PrimaryRChromaticityYSet bool
PrimaryGChromaticityX float64
PrimaryGChromaticityXSet bool
PrimaryGChromaticityY float64
PrimaryGChromaticityYSet bool
PrimaryBChromaticityX float64
PrimaryBChromaticityXSet bool
PrimaryBChromaticityY float64
PrimaryBChromaticityYSet bool
WhitePointChromaticityX float64
WhitePointChromaticityXSet bool
WhitePointChromaticityY float64
WhitePointChromaticityYSet bool
LuminanceMax float64
LuminanceMaxSet bool
LuminanceMin float64
LuminanceMinSet bool
}