mkvcore

package
v0.20.22 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mkvcore provides the core functionality of Matroska/WebM multimedia writer.

The package implements block data writer for EBML based multi-track media container.

Index

Constants

This section is empty.

Variables

View Source
var ErrIgnoreOldFrame = errors.New("too old frame")

ErrIgnoreOldFrame means that a frame has too old timestamp and ignored.

View Source
var ErrInvalidTrackNumber = errors.New("invalid track number")

ErrInvalidTrackNumber means that a track number is invalid. The track number must be larger than 0.

Functions

This section is empty.

Types

type BlockCloser

type BlockCloser interface {
	// Close the stream frame writer.
	// Output Matroska will be closed after closing all FrameWriter.
	Close() error
}

BlockCloser is a Matroska closer interface.

type BlockInterceptor

type BlockInterceptor interface {
	// Intercept reads blocks of each track, filters, and writes.
	Intercept(r []BlockReader, w []BlockWriter)
}

BlockInterceptor is a interface of block stream muxer.

func MustBlockInterceptor

func MustBlockInterceptor(interceptor BlockInterceptor, err error) BlockInterceptor

MustBlockInterceptor panics if creation of a BlockInterceptor fails, such as when the NewMultiTrackBlockSorter function fails.

func NewMultiTrackBlockSorter

func NewMultiTrackBlockSorter(opts ...MultiTrackBlockSorterOption) (BlockInterceptor, error)

NewMultiTrackBlockSorter creates BlockInterceptor, which sorts blocks on multiple tracks by timestamp. Either WithMaxDelayedPackets or WithMaxTimescaleDelay must be specified. If both are specified, then the first rule that is satisfied causes the packets to get written (thus a backlog of a max packets or max time scale will cause any older packets than the one satisfying the rule to be discarded). The index of TrackEntry sorts blocks with the same timestamp. Place the audio track before the video track to meet WebM Interceptor Guidelines.

type BlockReadCloser

type BlockReadCloser interface {
	BlockReader
	BlockCloser
}

BlockReadCloser groups Reader and Closer.

type BlockReadCloserWithTrackEntry

type BlockReadCloserWithTrackEntry interface {
	BlockReadCloser
	TrackEntryGetter
}

BlockReadCloserWithTrackEntry groups BlockReadCloser and TrackEntryGetter.

func NewSimpleBlockReader

func NewSimpleBlockReader(r io.Reader, opts ...BlockReaderOption) ([]BlockReadCloserWithTrackEntry, error)

NewSimpleBlockReader creates BlockReadCloserWithTrackEntry for each track specified as tracks argument. It reads SimpleBlock-s and BlockGroup.Block-s. Any optional data in BlockGroup are dropped. If you need full data, consider implementing a custom reader using ebml.Unmarshal.

Note that, keyframe flag from BlockGroup.Block may be incorrect. If you have knowledge about this, please consider fixing it.

type BlockReadWriterOptionFn

type BlockReadWriterOptionFn func(*BlockReadWriterOptions) error

BlockReadWriterOptionFn configures a BlockReadWriterOptions.

func WithOnErrorHandler

func WithOnErrorHandler(handler func(error)) BlockReadWriterOptionFn

WithOnErrorHandler registers marshal error handler.

func WithOnFatalHandler

func WithOnFatalHandler(handler func(error)) BlockReadWriterOptionFn

WithOnFatalHandler registers marshal error handler.

func (BlockReadWriterOptionFn) ApplyToBlockReaderOptions

func (o BlockReadWriterOptionFn) ApplyToBlockReaderOptions(opts *BlockReaderOptions) error

ApplyToBlockReaderOptions implements BlockReaderOption.

func (BlockReadWriterOptionFn) ApplyToBlockWriterOptions

func (o BlockReadWriterOptionFn) ApplyToBlockWriterOptions(opts *BlockWriterOptions) error

ApplyToBlockWriterOptions implements BlockWriterOption.

type BlockReadWriterOptions

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

BlockReadWriterOptions stores options for BlockWriter and BlockReader.

type BlockReader

type BlockReader interface {
	// Read a block from the connected Matroska reader.
	Read() (b []byte, keyframe bool, timestamp int64, err error)
}

BlockReader is a Matroska block reader interface.

type BlockReaderOption

type BlockReaderOption interface {
	ApplyToBlockReaderOptions(opts *BlockReaderOptions) error
}

BlockReaderOption configures a BlockReaderOptions.

type BlockReaderOptionFn

type BlockReaderOptionFn func(*BlockReaderOptions) error

BlockReaderOptionFn configures a BlockReaderOptions.

func WithUnmarshalOptions

func WithUnmarshalOptions(opts ...ebml.UnmarshalOption) BlockReaderOptionFn

WithUnmarshalOptions passes ebml.UnmarshalOption to ebml.Unmarshal.

func (BlockReaderOptionFn) ApplyToBlockReaderOptions

func (o BlockReaderOptionFn) ApplyToBlockReaderOptions(opts *BlockReaderOptions) error

ApplyToBlockReaderOptions implements BlockReaderOption.

type BlockReaderOptions

type BlockReaderOptions struct {
	BlockReadWriterOptions
	// contains filtered or unexported fields
}

BlockReaderOptions stores options for BlockReader.

type BlockSorterRule

type BlockSorterRule int

BlockSorterRule is a type of BlockSorter behaviour for outdated frame.

const (
	BlockSorterDropOutdated BlockSorterRule = iota
	BlockSorterWriteOutdated
)

List of BlockSorterRules.

type BlockWriteCloser

type BlockWriteCloser interface {
	BlockWriter
	BlockCloser
}

BlockWriteCloser groups Writer and Closer.

func NewSimpleBlockWriter

func NewSimpleBlockWriter(w0 io.WriteCloser, tracks []TrackDescription, opts ...BlockWriterOption) ([]BlockWriteCloser, error)

NewSimpleBlockWriter creates BlockWriteCloser for each track specified as tracks argument. Blocks will be written to the writer as EBML SimpleBlocks. Given io.WriteCloser will be closed automatically; don't close it by yourself. Frames written to each track must be sorted by their timestamp.

type BlockWriter

type BlockWriter interface {
	// Write a block to the connected Matroska writer.
	// timestamp is in millisecond.
	Write(keyframe bool, timestamp int64, b []byte) (int, error)
}

BlockWriter is a Matroska block writer interface.

type BlockWriterOption

type BlockWriterOption interface {
	ApplyToBlockWriterOptions(opts *BlockWriterOptions) error
}

BlockWriterOption configures a BlockWriterOptions.

type BlockWriterOptionFn

type BlockWriterOptionFn func(*BlockWriterOptions) error

BlockWriterOptionFn configures a BlockWriterOptions.

func WithBlockInterceptor

func WithBlockInterceptor(interceptor BlockInterceptor) BlockWriterOptionFn

WithBlockInterceptor registers BlockInterceptor.

func WithCues

func WithCues(enable bool) BlockWriterOptionFn

WithCues enables cues

func WithEBMLHeader

func WithEBMLHeader(h interface{}) BlockWriterOptionFn

WithEBMLHeader sets EBML header.

func WithMarshalOptions

func WithMarshalOptions(opts ...ebml.MarshalOption) BlockWriterOptionFn

WithMarshalOptions passes ebml.MarshalOption to ebml.Marshal.

func WithMaxKeyframeInterval

func WithMaxKeyframeInterval(mainTrackNumber uint64, interval int64) BlockWriterOptionFn

WithMaxKeyframeInterval sets maximum keyframe interval of the main (video) track. Using this option starts the cluster with a key frame if possible. interval must be given in the scale of timecode.

func WithSeekHead

func WithSeekHead(enable bool) BlockWriterOptionFn

WithSeekHead enables SeekHead calculation

func WithSegmentInfo

func WithSegmentInfo(i interface{}) BlockWriterOptionFn

WithSegmentInfo sets Segment.Info.

func WithSimpleTags

func WithSimpleTags(tags ...Tag) BlockWriterOptionFn

func (BlockWriterOptionFn) ApplyToBlockWriterOptions

func (o BlockWriterOptionFn) ApplyToBlockWriterOptions(opts *BlockWriterOptions) error

ApplyToBlockWriterOptions implements BlockWriterOption.

type BlockWriterOptions

type BlockWriterOptions struct {
	BlockReadWriterOptions
	// contains filtered or unexported fields
}

BlockWriterOptions stores options for BlockWriter.

type CuePoint

type CuePoint struct {
	CueTime           uint64             `ebml:"CueTime"`
	CueTrackPositions []CueTrackPosition `ebml:"CueTrackPositions"`
}

CuePoint represents CuePoint element struct.

type CueTrackPosition

type CueTrackPosition struct {
	CueTrack           uint64 `ebml:"CueTrack"`
	CueClusterPosition uint64 `ebml:"CueClusterPosition"`
	CueBlockNumber     uint64 `ebml:"CueBlockNumber,omitempty"`
}

CueTrackPosition represents CueTrackPosition element struct.

type Cues

type Cues struct {
	CuePoint []CuePoint `ebml:"CuePoint"`
}

Cues represents Cues element struct.

type MultiTrackBlockSorterOption

type MultiTrackBlockSorterOption func(*MultiTrackBlockSorterOptions) error

MultiTrackBlockSorterOption configures a MultiTrackBlockSorterOptions.

func WithMaxDelayedPackets

func WithMaxDelayedPackets(maxDelayedPackets int) MultiTrackBlockSorterOption

WithMaxDelayedPackets set the maximum number of packets that may be delayed within each track.

func WithMaxTimescaleDelay

func WithMaxTimescaleDelay(maxTimescaleDelay int64) MultiTrackBlockSorterOption

WithMaxTimescaleDelay set the maximum allowed delay between tracks for a given timescale.

func WithSortRule

WithSortRule set the sort rule to apply to how packet ordering should be treated within the webm container.

type MultiTrackBlockSorterOptions

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

MultiTrackBlockSorterOptions stores options for BlockWriter.

type SimpleTag

type SimpleTag struct {
	TagName     string `ebml:"TagName"`
	TagString   string `ebml:"TagString"`
	TagLanguage string `ebml:"TagLanguage,omitempty"` // und
	TagDefault  uint64 `ebml:"TagDefault,omitempty"`  // 1 (0-1)
}

type Tag

type Tag struct {
	Targets   Targets     `ebml:"Targets"`
	SimpleTag []SimpleTag `ebml:"SimpleTag"`
}

type Tags

type Tags struct {
	Tag []Tag `ebml:"Tag"`
}

type Targets

type Targets struct {
	TargetTypeValue uint64   `ebml:"TargetTypeValue,omitempty"` // 50
	TargetType      string   `ebml:"TargetType,omitempty"`
	TagTrackUID     []uint64 `ebml:"TagTrackUID,omitempty"`
}

type TrackDescription

type TrackDescription struct {
	TrackNumber uint64
	TrackEntry  core.TrackEntry
}

TrackDescription stores track number and its TrackEntry struct.

type TrackEntry

type TrackEntry struct {
	TrackNumber        uint64
	TrackUID           uint64
	TrackType          core.TrackType
	FlagEnabled        uint8
	FlagDefault        uint8
	FlagForced         uint8
	FlagLacing         uint8
	MinCache           uint64
	DefaultDuration    uint64
	MaxBlockAdditionID uint64
	Name               string
	Language           string
	LanguageIETF       string
	CodecID            string
	CodecDecodeAll     uint8
	SeekPreRoll        uint64
}

TrackEntry is a TrackEntry struct with all mandatory elements and commonly used elements.

func (*TrackEntry) SetAudioSamplingFrequency

func (c *TrackEntry) SetAudioSamplingFrequency(samplingFrequency float64)

type TrackEntryGetter

type TrackEntryGetter interface {
	TrackEntry() TrackEntry
}

TrackEntryGetter is a interface to get TrackEntry.

type Void

type Void struct {
	Void []byte `ebml:"Void,omitempty"`
}

Jump to

Keyboard shortcuts

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