Documentation
¶
Overview ¶
Package mkv writes Matroska files: the muxer behind bdtools' default output, taking an encoder's raw H.264 or HEVC stream and the audio and subtitle tracks a Blu-ray demux produces.
Index ¶
- func ADTSHeader(asc []byte, n int) []byte
- func FourCC(s string) uint32
- func HasCore(r io.Reader, format AudioFormat) bool
- func Mux(w io.WriteSeeker, sources []Source, opts Options) error
- type AudioFormat
- type AudioSource
- func (a *AudioSource) Delay() time.Duration
- func (a *AudioSource) Gaps() []time.Duration
- func (a *AudioSource) Next() (Frame, error)
- func (a *AudioSource) SampleStart() int64
- func (a *AudioSource) SetDefault(d bool)
- func (a *AudioSource) SetName(n string)
- func (a *AudioSource) SetSyncPoints(sp []SyncPoint)
- func (a *AudioSource) Track() Track
- type BlockAddition
- type Chapter
- type Codec
- type Colour
- type Frame
- type HEVCOrder
- type Options
- type PGSSource
- type Packet
- type ReadTrack
- type Reader
- type Source
- type Span
- type SyncPoint
- type Track
- type TrackType
- type VideoSource
- func (v *VideoSource) Next() (Frame, error)
- func (v *VideoSource) SetBlockAdditions(a []BlockAddition)
- func (v *VideoSource) SetColour(c *Colour)
- func (v *VideoSource) SetDelay(d time.Duration)
- func (v *VideoSource) SetDisplaySize(w, h int)
- func (v *VideoSource) SetExtras(extras func(display int64, key bool) [][]byte)
- func (v *VideoSource) SetTrailer(trailer func(display int64) ([][]byte, error))
- func (v *VideoSource) Track() Track
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ADTSHeader ¶ added in v0.14.0
ADTSHeader makes an ADTS header for a raw AAC frame of n bytes with the AudioSpecificConfig asc (object type, rate index, channels from its first 13 bits).
Types ¶
type AudioFormat ¶
type AudioFormat int
AudioFormat is the content of a demuxed audio file.
const ( AC3 AudioFormat = iota // AC-3, or E-AC-3: whichever the frames are TrueHD // TrueHD access units, possibly with an AC-3 core interleaved DTS // DTS, or DTS-HD: a core frame then its extension substream WAV // PCM in a WAV file AAC // AAC in ADTS frames (given raw, the configuration in the codec private data) )
type AudioSource ¶
type AudioSource struct {
// contains filtered or unexported fields
}
AudioSource reads a demuxed audio file frame by frame. A Blu-ray stream can carry a lossy core next to (or inside) its main coding — the AC-3 frames between TrueHD's access units, the AC-3 independent substream of a 7.1 E-AC-3 track, the DTS core of DTS-HD — and Core selects which of the two this source produces.
func NewAudioSource ¶
func NewAudioSource(r io.Reader, format AudioFormat, core bool, lang string) (*AudioSource, error)
NewAudioSource probes the file. lang is the track's ISO 639-2 language.
func (*AudioSource) Delay ¶
func (a *AudioSource) Delay() time.Duration
Delay is when the track starts, if the source starts it after the picture; Gaps is how far each later move to the source's timestamps shifted it.
func (*AudioSource) Gaps ¶
func (a *AudioSource) Gaps() []time.Duration
Gaps reports the gaps in the source the track was moved across.
func (*AudioSource) SampleStart ¶ added in v0.12.0
func (a *AudioSource) SampleStart() int64
SampleStart is how many samples came before the frame Next last gave, counted over the whole file (across any gap): where a decoder of the file, which knows nothing of the gaps, has it.
func (*AudioSource) SetDefault ¶
func (a *AudioSource) SetDefault(d bool)
SetDefault marks the track as the one a player picks by default.
func (*AudioSource) SetSyncPoints ¶
func (a *AudioSource) SetSyncPoints(sp []SyncPoint)
SetSyncPoints gives the source's timestamps, in file order. Without them the track starts at zero and runs by its sample count.
type BlockAddition ¶ added in v0.7.0
BlockAddition is a track's BlockAdditionMapping: what a kind of data alongside its frames is. Dolby Vision's names its configuration record: Type is the record's four-character code (dvcC or dvvC) and ExtraData the record.
type Colour ¶ added in v0.7.0
Colour is a video track's colour signalling (H.273 code points: 2 is unspecified) and its HDR10 metadata.
type Frame ¶
type Frame struct {
// PTS is the presentation time.
PTS time.Duration
// Order is when the frame goes into the file, relative to the other
// tracks: its decode time. Equal to PTS for anything without frame
// reordering.
Order time.Duration
Keyframe bool
Data []byte
// Duration, when set, is the frame's time on screen: a subtitle's,
// written as its block's BlockDuration.
Duration time.Duration
}
Frame is one block of a track.
type HEVCOrder ¶ added in v0.8.6
type HEVCOrder struct {
// contains filtered or unexported fields
}
HEVCOrder puts an HEVC stream's access units, met in decoding order, in display order: Key gives each one a number that sorts it there, its picture order count past every earlier coded video sequence's. Decoders that give pictures back in the order of the timestamps they were given (VideoToolbox) need such timestamps.
type Options ¶
type Options struct {
Chapters []Chapter
WritingApp string
// Progress, when set, is called now and then with the time muxed so far.
Progress func(time.Duration)
// Spans, when set, receives each track's first and last presentation
// time (the last frame's start), in source order, once the mux is done.
Spans *[]Span
}
Options for Mux.
type PGSSource ¶
type PGSSource struct {
// contains filtered or unexported fields
}
PGSSource reads a .sup file — each presentation graphics segment behind "PG" and its PTS and DTS — and gives one frame per display set: the segments from a presentation composition to its end segment, at the composition's time.
func NewPGSSource ¶
NewPGSSource reads a .sup file.
func (*PGSSource) SetDefault ¶
SetDefault marks the track the one a player picks among the subtitles.
type Packet ¶
type Packet struct {
Track uint64
Time time.Duration // the block's timestamp: the presentation time
// Duration is the block's, when it states one (a subtitle's time on
// screen); 0 when it does not.
Duration time.Duration
Keyframe bool
Data []byte
}
Packet is one frame of a track.
type ReadTrack ¶
type ReadTrack struct {
Number uint64
Type TrackType
CodecID string
CodecPrivate []byte
// Language is the ISO 639-2 code; Matroska's default, when the file
// says nothing, is English.
Language string
// LanguageBCP47 is the IETF tag, when the file has one.
LanguageBCP47 string
Name string
Default bool
Forced bool
Commentary bool // FlagCommentary
// Video.
Width, Height int
StereoMode int
// DisplayWidth and DisplayHeight are zero when the file does not say.
DisplayWidth, DisplayHeight int
// DefaultDuration is a frame's duration, zero when the file does not
// say.
DefaultDuration time.Duration
// BitsPerChannel is the Colour element's bit depth, zero when the file
// does not say.
BitsPerChannel int
// Transfer is the Colour element's transfer characteristics (H.273: 16
// is PQ, 18 HLG), zero when the file does not say.
Transfer int
// BlockAdditions are the track's BlockAdditionMappings (Dolby Vision's
// configuration).
BlockAdditions []BlockAddition
// Audio.
SampleRate float64
Channels int
BitDepth int
// contains filtered or unexported fields
}
ReadTrack is a track of a Matroska file being read.
type Reader ¶
type Reader struct {
Tracks []ReadTrack
Chapters []time.Duration
Duration time.Duration
// contains filtered or unexported fields
}
Reader reads a Matroska file's blocks in order.
func NewReader ¶
NewReader reads the file's headers: the EBML header, then the segment's info, tracks and chapters, up to the first cluster.
func (*Reader) Resync ¶ added in v0.14.0
func (m *Reader) Resync(r io.ReadSeeker, off int64) error
Resync goes on reading at the first cluster that starts at or after byte off of r, the file NewReader read: frames come from there on, in file order. It is for reading parts of a file, looking at its pictures here and there, without reading what lies between.
type SyncPoint ¶
SyncPoint says when the byte at Offset of a demuxed audio file is presented, on the output's timeline.
type Track ¶
type Track struct {
Type TrackType
CodecID string // "V_MPEG4/ISO/AVC", "A_TRUEHD", "S_HDMV/PGS"
CodecPrivate []byte
Language string // ISO 639-2; empty writes "und"
Name string
Default bool
Forced bool
// DefaultDuration is the duration of a frame, for constant-rate tracks.
DefaultDuration time.Duration
// Video.
Width, Height int
// StereoMode is the Matroska stereo layout: 1 is side by side, left
// eye first.
StereoMode int
// Colour, when set, is the video's colour signalling and HDR metadata,
// written as Matroska's Colour element.
Colour *Colour
// DisplayWidth and DisplayHeight, when set, are the shape a frame is
// shown at (zero leaves Matroska's default, the pixel size). For a
// stereo frame, players built on ffmpeg (Kodi, mpv) and mkvmerge take
// them as one eye's shape: see SetDisplaySize.
DisplayWidth, DisplayHeight int
// BlockAdditions describe data the track's frames carry for a purpose
// of their own: Dolby Vision's configuration.
BlockAdditions []BlockAddition
// Audio.
SampleRate int
Channels int
BitDepth int
}
Track describes a track's header.
type VideoSource ¶
type VideoSource struct {
// contains filtered or unexported fields
}
VideoSource reads an encoder's raw Annex B output — in decode order, with no timestamps — and gives each frame its presentation time from its picture order count: within a coded video sequence, display order is POC order. The frames are passed through in decode order, NAL units length-prefixed as Matroska stores them, access unit delimiters dropped and the parameter sets kept in-band as well as in the codec private data.
func NewVideoSource ¶
func NewVideoSource(r io.Reader, codec Codec, fpsNum, fpsDen int, stereoMode int) (*VideoSource, error)
NewVideoSource reads the first frames to learn the stream's parameters. fps is the frame rate as a fraction.
func (*VideoSource) Next ¶
func (v *VideoSource) Next() (Frame, error)
Next returns the next frame in decode order.
func (*VideoSource) SetBlockAdditions ¶ added in v0.7.0
func (v *VideoSource) SetBlockAdditions(a []BlockAddition)
SetBlockAdditions sets the track's BlockAdditionMappings.
func (*VideoSource) SetColour ¶ added in v0.7.0
func (v *VideoSource) SetColour(c *Colour)
SetColour sets the track's colour signalling and HDR metadata.
func (*VideoSource) SetDelay ¶
func (v *VideoSource) SetDelay(d time.Duration)
SetDelay starts the picture later: for a source whose first picture comes after the start of what plays (the audio's), as some discs do.
func (*VideoSource) SetDisplaySize ¶
func (v *VideoSource) SetDisplaySize(w, h int)
SetDisplaySize sets the shape a frame is shown at. For a side-by-side frame the convention mkvmerge writes and ffmpeg's demuxer reads is one eye's shape: a full-width pair of 1920x1080 eyes (3840x1080) is 3840x2160, square pixels; a half-width pair squeezed into 1920x1080 is 1920x1080, each eye stretched back to 16:9. Left at the pixel size, ffmpeg takes a full-width pair for 7680x1080, which players then show and size their output for as if it were twice as wide.
func (*VideoSource) SetExtras ¶ added in v0.7.0
func (v *VideoSource) SetExtras(extras func(display int64, key bool) [][]byte)
SetExtras has extras give, for each frame by its display index, units to add to it: NAL units (without start codes) ahead of an H.264 or HEVC picture's, or OBUs after an AV1 temporal unit's sequence header. HDR metadata goes in this way, on the frame it belongs to whatever order the encoder put the frames in.
func (*VideoSource) SetTrailer ¶ added in v0.7.0
func (v *VideoSource) SetTrailer(trailer func(display int64) ([][]byte, error))
SetTrailer has trailer give, for each frame by its display index (asked in decoding order), NAL units to end it with: Dolby Vision's enhancement layer and RPU go last in its access unit. An error ends the source.