mkvparse

package module
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 9 Imported by: 4

README

mkvparse: Matroska parser in Go

Go Reference

Fast Matroska (.mkv, .mka, .webm) parser, written in Go.

Features:

  • Supports all Matroska elements
  • Supports short-circuiting the parser, making it possible to read specific data (e.g. title, author) without reading the entire file (see the mkvtags example)
  • Also works with WebM (.webm) files
  • Supports streaming
  • Event-based push API
  • No dependencies

API

See the API Reference.

Examples

Besides the examples in the API Reference, there are some larger examples in the examples/ dir:

  • examples/mkvinfo: Example using basic parser API to print all elements
  • examples/mkvtags: Example using the optimized 'sections' API to print all tags without parsing the entire file.

Documentation

Overview

Package mkvparse provides push-style parser functions for parsing Matroska (`.mkv`, `.mka`, `.webm`) files.

Example
package main

import (
	"fmt"
	"log"
)

func main() {
	handler := MyHandler{}
	if err := ParsePath("testdata/example.mkv", &handler); err != nil {
		log.Fatalf("%v", err)
	}
}

type MyHandler struct {
	DefaultHandler
}

func (p *MyHandler) HandleString(id ElementID, value string, info ElementInfo) error {
	switch id {
	case TitleElement:
		fmt.Printf("%s: %v\n", NameForElementID(id), value)
	}
	return nil
}
Output:

Title: Awesome Movie

Index

Examples

Constants

View Source
const (
	AspectRatioType_FreeResizing    int64 = 0 // free resizing
	AspectRatioType_KeepAspectRatio int64 = 1 // keep aspect ratio
	AspectRatioType_Fixed           int64 = 2 // fixed
)

Possible AspectRatioTypeElement values

View Source
const (
	ChapProcessTime_DuringWholeChapter     int64 = 0 // during the whole chapter
	ChapProcessTime_BeforeStartingPlayback int64 = 1 // before starting playback
	ChapProcessTime_AfterPlaybackOfChapter int64 = 2 // after playback of the chapter
)

Possible ChapProcessTimeElement values

View Source
const (
	ChapterTranslateCodec_MatroskaScript int64 = 0 // Matroska Script
	ChapterTranslateCodec_DVDMenu        int64 = 1 // DVD-menu
)

Possible ChapterTranslateCodecElement values

View Source
const (
	ChromaSitingHorz_Unspecified    int64 = 0 // unspecified
	ChromaSitingHorz_LeftCollocated int64 = 1 // left collocated
	ChromaSitingHorz_Half           int64 = 2 // half
)

Possible ChromaSitingHorzElement values

View Source
const (
	ChromaSitingVert_Unspecified   int64 = 0 // unspecified
	ChromaSitingVert_TopCollocated int64 = 1 // top collocated
	ChromaSitingVert_Half          int64 = 2 // half
)

Possible ChromaSitingVertElement values

View Source
const (
	DisplayUnit_Pixels             int64 = 0 // pixels
	DisplayUnit_Centimeters        int64 = 1 // centimeters
	DisplayUnit_Inches             int64 = 2 // inches
	DisplayUnit_DisplayAspectRatio int64 = 3 // display aspect ratio
	DisplayUnit_Unknown            int64 = 4 // unknown
)

Possible DisplayUnitElement values

View Source
const (
	FieldOrder_Progressive  int64 = 0  // progressive
	FieldOrder_TFF          int64 = 1  // tff
	FieldOrder_Undetermined int64 = 2  // undetermined
	FieldOrder_BFF          int64 = 6  // bff
	FieldOrder_BFF_Swapped  int64 = 9  // bff(swapped)
	FieldOrder_TFF_Swapped  int64 = 14 // tff(swapped)
)

Possible FieldOrderElement values

View Source
const (
	FlagInterlaced_Undetermined int64 = 0 // undetermined
	FlagInterlaced_Interlaced   int64 = 1 // interlaced
	FlagInterlaced_Progressive  int64 = 2 // progressive
)

Possible FlagInterlacedElement values

View Source
const (
	MatrixCoefficients_GBR                        int64 = 0  // GBR
	MatrixCoefficients_BT709                      int64 = 1  // BT709
	MatrixCoefficients_Unspecified                int64 = 2  // unspecified
	MatrixCoefficients_Reserved3                  int64 = 3  // reserved
	MatrixCoefficients_FCC                        int64 = 4  // FCC
	MatrixCoefficients_BT470BG                    int64 = 5  // BT470BG
	MatrixCoefficients_SMPTE170M                  int64 = 6  // SMPTE 170M
	MatrixCoefficients_SMPTE240M                  int64 = 7  // SMPTE 240M
	MatrixCoefficients_YCoCg                      int64 = 8  // YCoCg
	MatrixCoefficients_BT2020NonConstantLuminance int64 = 9  // BT2020 Non-constant Luminance
	MatrixCoefficients_BT2020ConstantLuminance    int64 = 10 // BT2020 Constant Luminance
)

Possible MatrixCoefficientsElement values

View Source
const (
	OldStereoMode_Mono     int64 = 0 // mono
	OldStereoMode_RightEye int64 = 1 // right eye
	OldStereoMode_LeftEye  int64 = 2 // left eye
	OldStereoMode_BothEyes int64 = 3 // both eyes
)

Possible OldStereoModeElement values

View Source
const (
	Primaries_Reserved0         int64 = 0  // reserved
	Primaries_ITURBT709         int64 = 1  // ITU-R BT.709
	Primaries_Unspecified       int64 = 2  // unspecified
	Primaries_Reserved3         int64 = 3  // reserved
	Primaries_ITURBT470M        int64 = 4  // ITU-R BT.470M
	Primaries_ITURBT470BG       int64 = 5  // ITU-R BT.470BG
	Primaries_SMPTE170M         int64 = 6  // SMPTE 170M
	Primaries_SMPTE240M         int64 = 7  // SMPTE 240M
	Primaries_FILM              int64 = 8  // FILM
	Primaries_ITURBT2020        int64 = 9  // ITU-R BT.2020
	Primaries_SMPTEST4281       int64 = 10 // SMPTE ST 428-1
	Primaries_JEDECP22Phosphors int64 = 22 // JEDEC P22 phosphors
)

Possible PrimariesElement values

View Source
const (
	ProjectionType_Rectangular     int64 = 0 // rectangular
	ProjectionType_Equirectangular int64 = 1 // equirectangular
	ProjectionType_Cubemap         int64 = 2 // cubemap
	ProjectionType_Mesh            int64 = 3 // mesh
)

Possible ProjectionTypeElement values

View Source
const (
	Range_Unspecified                                         int64 = 0 // unspecified
	Range_BroadcastRange                                      int64 = 1 // broadcast range
	Range_FullRange_NoClipping                                int64 = 2 // full range (no clipping)
	Range_DefinedByMatrixCoefficients_TransferCharacteristics int64 = 3 // defined by MatrixCoefficients/TransferCharacteristics
)

Possible RangeElement values

View Source
const (
	StereoMode_Mono                                  int64 = 0  // mono
	StereoMode_SideBySide_LeftEyeFirst               int64 = 1  // side by side (left eye first)
	StereoMode_TopBottom_RightEyeFirst               int64 = 2  // top - bottom (right eye is first)
	StereoMode_TopBottom_LeftEyeFirst                int64 = 3  // top - bottom (left eye is first)
	StereoMode_Checkboard_RightEyeFirst              int64 = 4  // checkboard (right eye is first)
	StereoMode_Checkboard_LeftEyeFirst               int64 = 5  // checkboard (left eye is first)
	StereoMode_RowInterleaved_RightEyeFirst          int64 = 6  // row interleaved (right eye is first)
	StereoMode_RowInterleaved_LeftEyeFirst           int64 = 7  // row interleaved (left eye is first)
	StereoMode_ColumnInterleaved_RightEyeFirst       int64 = 8  // column interleaved (right eye is first)
	StereoMode_ColumnInterleaved_LeftEyeFirst        int64 = 9  // column interleaved (left eye is first)
	StereoMode_Anaglyph_Cyan_Red                     int64 = 10 // anaglyph (cyan/red)
	StereoMode_SideBySide_RightEyeFirst              int64 = 11 // side by side (right eye first)
	StereoMode_Anaglyph_Green_Magenta                int64 = 12 // anaglyph (green/magenta)
	StereoMode_BothEyesLacedInOneBlock_LeftEyeFirst  int64 = 13 // both eyes laced in one Block (left eye is first)
	StereoMode_BothEyesLacedInOneBlock_RightEyeFirst int64 = 14 // both eyes laced in one Block (right eye is first)
)

Possible StereoModeElement values

View Source
const (
	TargetType_COLLECTION string = "COLLECTION" // COLLECTION
	TargetType_EDITION    string = "EDITION"    // EDITION
	TargetType_ISSUE      string = "ISSUE"      // ISSUE
	TargetType_VOLUME     string = "VOLUME"     // VOLUME
	TargetType_OPUS       string = "OPUS"       // OPUS
	TargetType_SEASON     string = "SEASON"     // SEASON
	TargetType_SEQUEL     string = "SEQUEL"     // SEQUEL
	TargetType_ALBUM      string = "ALBUM"      // ALBUM
	TargetType_OPERA      string = "OPERA"      // OPERA
	TargetType_CONCERT    string = "CONCERT"    // CONCERT
	TargetType_MOVIE      string = "MOVIE"      // MOVIE
	TargetType_EPISODE    string = "EPISODE"    // EPISODE
	TargetType_PART       string = "PART"       // PART
	TargetType_SESSION    string = "SESSION"    // SESSION
	TargetType_TRACK      string = "TRACK"      // TRACK
	TargetType_SONG       string = "SONG"       // SONG
	TargetType_CHAPTER    string = "CHAPTER"    // CHAPTER
	TargetType_SUBTRACK   string = "SUBTRACK"   // SUBTRACK
	TargetType_MOVEMENT   string = "MOVEMENT"   // MOVEMENT
	TargetType_SCENE      string = "SCENE"      // SCENE
	TargetType_SHOT       string = "SHOT"       // SHOT
)

Possible TargetTypeElement values

View Source
const (
	TargetTypeValue_COLLECTION                                int64 = 70 // COLLECTION
	TargetTypeValue_EDITION_ISSUE_VOLUME_OPUS_SEASON_SEQUEL   int64 = 60 // EDITION / ISSUE / VOLUME / OPUS / SEASON / SEQUEL
	TargetTypeValue_ALBUM_OPERA_CONCERT_MOVIE_EPISODE_CONCERT int64 = 50 // ALBUM / OPERA / CONCERT / MOVIE / EPISODE / CONCERT
	TargetTypeValue_PART_SESSION                              int64 = 40 // PART / SESSION
	TargetTypeValue_TRACK_SONG_CHAPTER                        int64 = 30 // TRACK / SONG / CHAPTER
	TargetTypeValue_SUBTRACK_PART_MOVEMENT_SCENE              int64 = 20 // SUBTRACK / PART / MOVEMENT / SCENE
	TargetTypeValue_SHOT                                      int64 = 10 // SHOT
)

Possible TargetTypeValueElement values

View Source
const (
	TrackPlaneType_LeftEye    int64 = 0 // left eye
	TrackPlaneType_RightEye   int64 = 1 // right eye
	TrackPlaneType_Background int64 = 2 // background
)

Possible TrackPlaneTypeElement values

View Source
const (
	TrackTranslateCodec_MatroskaScript int64 = 0 // Matroska Script
	TrackTranslateCodec_DVDMenu        int64 = 1 // DVD-menu
)

Possible TrackTranslateCodecElement values

View Source
const (
	TrackType_Video    int64 = 1  // video
	TrackType_Audio    int64 = 2  // audio
	TrackType_Complex  int64 = 3  // complex
	TrackType_Subtitle int64 = 17 // subtitle
	TrackType_Buttons  int64 = 18 // buttons
	TrackType_Control  int64 = 32 // control
)

Possible TrackTypeElement values

View Source
const (
	TransferCharacteristics_Reserved0                     int64 = 0  // reserved
	TransferCharacteristics_ITURBT709                     int64 = 1  // ITU-R BT.709
	TransferCharacteristics_Unspecified                   int64 = 2  // unspecified
	TransferCharacteristics_Reserved3                     int64 = 3  // reserved
	TransferCharacteristics_Gamma22Curve                  int64 = 4  // Gamma 2.2 curve
	TransferCharacteristics_Gamma28Curve                  int64 = 5  // Gamma 2.8 curve
	TransferCharacteristics_SMPTE170M                     int64 = 6  // SMPTE 170M
	TransferCharacteristics_SMPTE240M                     int64 = 7  // SMPTE 240M
	TransferCharacteristics_Linear                        int64 = 8  // Linear
	TransferCharacteristics_Log                           int64 = 9  // Log
	TransferCharacteristics_LogSqrt                       int64 = 10 // Log Sqrt
	TransferCharacteristics_IEC6196624                    int64 = 11 // IEC 61966-2-4
	TransferCharacteristics_ITURBT1361ExtendedColourGamut int64 = 12 // ITU-R BT.1361 Extended Colour Gamut
	TransferCharacteristics_IEC6196621                    int64 = 13 // IEC 61966-2-1
	TransferCharacteristics_ITURBT202010Bit               int64 = 14 // ITU-R BT.2020 10 bit
	TransferCharacteristics_ITURBT202012Bit               int64 = 15 // ITU-R BT.2020 12 bit
	TransferCharacteristics_SMPTEST2084                   int64 = 16 // SMPTE ST 2084
	TransferCharacteristics_SMPTEST4281                   int64 = 17 // SMPTE ST 428-1
	TransferCharacteristics_ARIBSTDB67_HLG                int64 = 18 // ARIB STD-B67 (HLG)
)

Possible TransferCharacteristicsElement values

View Source
const (
	Tag_Accompaniment         string = "ACCOMPANIMENT"
	Tag_Actor                 string = "ACTOR"
	Tag_Address               string = "ADDRESS"
	Tag_Arranger              string = "ARRANGER"
	Tag_ArtDirector           string = "ART_DIRECTOR"
	Tag_Artist                string = "ARTIST"
	Tag_AssistantDirector     string = "ASSISTANT_DIRECTOR"
	Tag_BPM                   string = "BPM"
	Tag_BPS                   string = "BPS"
	Tag_Barcode               string = "BARCODE"
	Tag_CatalogNumber         string = "CATALOG_NUMBER"
	Tag_Character             string = "CHARACTER"
	Tag_Choregrapher          string = "CHOREGRAPHER"
	Tag_Comment               string = "COMMENT"
	Tag_Composer              string = "COMPOSER"
	Tag_ComposerNationality   string = "COMPOSER_NATIONALITY"
	Tag_CompositionLocation   string = "COMPOSITION_LOCATION"
	Tag_Conductor             string = "CONDUCTOR"
	Tag_ContentType           string = "CONTENT_TYPE"
	Tag_Coproducer            string = "COPRODUCER"
	Tag_Copyright             string = "COPYRIGHT"
	Tag_CostumeDesigner       string = "COSTUME_DESIGNER"
	Tag_Country               string = "COUNTRY"
	Tag_DateDigitized         string = "DATE_DIGITIZED"
	Tag_DateEncoded           string = "DATE_ENCODED"
	Tag_DatePurchased         string = "DATE_PURCHASED"
	Tag_DateRecorded          string = "DATE_RECORDED"
	Tag_DateReleased          string = "DATE_RELEASED"
	Tag_DateTagged            string = "DATE_TAGGED"
	Tag_DateWritten           string = "DATE_WRITTEN"
	Tag_Description           string = "DESCRIPTION"
	Tag_Director              string = "DIRECTOR"
	Tag_DirectorOfPhotography string = "DIRECTOR_OF_PHOTOGRAPHY"
	Tag_DistributedBy         string = "DISTRIBUTED_BY"
	Tag_EditedBy              string = "EDITED_BY"
	Tag_Email                 string = "EMAIL"
	Tag_EncodedBy             string = "ENCODED_BY"
	Tag_Encoder               string = "ENCODER"
	Tag_EncoderSettings       string = "ENCODER_SETTINGS"
	Tag_ExecutiveProducer     string = "EXECUTIVE_PRODUCER"
	Tag_FPS                   string = "FPS"
	Tag_Fax                   string = "FAX"
	Tag_Genre                 string = "GENRE"
	Tag_IMDB                  string = "IMDB"
	Tag_ISBN                  string = "ISBN"
	Tag_ISRC                  string = "ISRC"
	Tag_InitialKey            string = "INITIAL_KEY"
	Tag_Instruments           string = "INSTRUMENTS"
	Tag_Keywords              string = "KEYWORDS"
	Tag_LCCN                  string = "LCCN"
	Tag_Label                 string = "LABEL"
	Tag_LabelCode             string = "LABEL_CODE"
	Tag_LawRating             string = "LAW_RATING"
	Tag_LeadPerformer         string = "LEAD_PERFORMER"
	Tag_License               string = "LICENSE"
	Tag_Lyricist              string = "LYRICIST"
	Tag_Lyrics                string = "LYRICS"
	Tag_MCDI                  string = "MCDI"
	Tag_MasteredBy            string = "MASTERED_BY"
	Tag_Measure               string = "MEASURE"
	Tag_MixedBy               string = "MIXED_BY"
	Tag_Mood                  string = "MOOD"
	Tag_Original              string = "ORIGINAL"
	Tag_OriginalMediaType     string = "ORIGINAL_MEDIA_TYPE"
	Tag_PartNumber            string = "PART_NUMBER"
	Tag_PartOffset            string = "PART_OFFSET"
	Tag_Period                string = "PERIOD"
	Tag_Phone                 string = "PHONE"
	Tag_PlayCounter           string = "PLAY_COUNTER"
	Tag_Producer              string = "PRODUCER"
	Tag_ProductionCopyright   string = "PRODUCTION_COPYRIGHT"
	Tag_ProductionDesigner    string = "PRODUCTION_DESIGNER"
	Tag_ProductionStudio      string = "PRODUCTION_STUDIO"
	Tag_Publisher             string = "PUBLISHER"
	Tag_PurchaseCurrency      string = "PURCHASE_CURRENCY"
	Tag_PurchaseInfo          string = "PURCHASE_INFO"
	Tag_PurchaseItem          string = "PURCHASE_ITEM"
	Tag_PurchaseOwner         string = "PURCHASE_OWNER"
	Tag_PurchasePrice         string = "PURCHASE_PRICE"
	Tag_Rating                string = "RATING"
	Tag_RecordingLocation     string = "RECORDING_LOCATION"
	Tag_RemixedBy             string = "REMIXED_BY"
	Tag_ReplayGainGain        string = "REPLAYGAIN_GAIN"
	Tag_ReplayGainPeak        string = "REPLAYGAIN_PEAK"
	Tag_Sample                string = "SAMPLE"
	Tag_ScreenplayBy          string = "SCREENPLAY_BY"
	Tag_SortWith              string = "SORT_WITH"
	Tag_SoundEngineer         string = "SOUND_ENGINEER"
	Tag_Subject               string = "SUBJECT"
	Tag_Subtitle              string = "SUBTITLE"
	Tag_Summary               string = "SUMMARY"
	Tag_Synopsis              string = "SYNOPSIS"
	Tag_TMDB                  string = "TMDB"
	Tag_TVDB                  string = "TVDB"
	Tag_TermsOfUse            string = "TERMS_OF_USE"
	Tag_ThanksTo              string = "THANKS_TO"
	Tag_Title                 string = "TITLE"
	Tag_TotalParts            string = "TOTAL_PARTS"
	Tag_Tuning                string = "TUNING"
	Tag_URL                   string = "URL"
	Tag_WrittenBy             string = "WRITTEN_BY"
)

Official tags. See https://www.matroska.org/technical/tagging.html

Variables

This section is empty.

Functions

func NameForElementID

func NameForElementID(id ElementID) string

Gives the human-readable name for the given element ID.

Example
fmt.Println(NameForElementID(InfoElement))
Output:

Info

func Parse

func Parse(reader io.Reader, handler Handler) error

Parse the contents of `reader`

func ParseCover added in v0.9.0

func ParseCover(path string) ([]byte, string, error)
Example
data, typ, err := ParseCover("testdata/example-cover.mkv")
if err != nil {
	panic(err)
}

fmt.Printf("parsed cover: %s (%d bytes)\n", typ, len(data))
Output:

parsed cover: image/jpeg (41363 bytes)
Example (Image)
data, typ, err := ParseCover("testdata/example-cover.mkv")
if err != nil {
	log.Panic(err)
}
if data == nil {
	log.Panic("no cover")
	return
}
var img image.Image
switch typ {
case "image/jpeg":
	img, err = jpeg.Decode(bytes.NewReader(data))
case "image/png":
	img, err = png.Decode(bytes.NewReader(data))
default:
	log.Panicf("unknown MIME type: %s", typ)
}
if err != nil {
	log.Panic(err)
}

fmt.Printf("parsed cover image: %dx%d\n", img.Bounds().Dx(), img.Bounds().Dy())
Output:

parsed cover image: 265x377

func ParsePath

func ParsePath(path string, handler Handler) error

Parse the file pointed to by `path`

func ParseSections

func ParseSections(file io.ReadSeeker, handler Handler, sections ...ElementID) error

Parses only the given sections of `file`.

When present, uses the seek index to avoid having to parse the entire file

Example
package main

import (
	"fmt"
	"log"
	"os"
)

func main() {
	handler := myTitleHandler{}
	file, err := os.Open("testdata/example.mkv")
	if err != nil {
		log.Fatalf("%v", err)
	}
	defer file.Close()
	if err = ParseSections(file, &handler, InfoElement); err != nil {
		log.Fatalf("%v", err)
	}
}

type myTitleHandler struct {
	DefaultHandler
}

func (p *myTitleHandler) HandleString(id ElementID, value string, info ElementInfo) error {
	switch id {
	case TitleElement:
		fmt.Printf("%s: %v\n", NameForElementID(id), value)
	}
	return nil
}
Output:

Title: Awesome Movie

Types

type CoverHandler added in v0.9.0

type CoverHandler struct {
	DefaultHandler

	Data     []byte
	MIMEType string
	// contains filtered or unexported fields
}

Handler to extract cover image data

Needs the section parser to handle `AttachmentsElement`

Example
file, err := os.Open("testdata/example-cover.mkv")
if err != nil {
	panic(err)
}
defer file.Close()

handler := CoverHandler{}
if err := ParseSections(file, &handler, AttachmentsElement); err != nil {
	panic(err)
}

fmt.Printf("parsed cover: %s (%d bytes)\n", handler.MIMEType, len(handler.Data))
Output:

parsed cover: image/jpeg (41363 bytes)

func (*CoverHandler) HandleBinary added in v0.9.0

func (p *CoverHandler) HandleBinary(id ElementID, value []byte, info ElementInfo) error

func (*CoverHandler) HandleMasterEnd added in v0.9.0

func (p *CoverHandler) HandleMasterEnd(id ElementID, info ElementInfo) error

func (*CoverHandler) HandleString added in v0.9.0

func (p *CoverHandler) HandleString(id ElementID, value string, info ElementInfo) error

type DefaultHandler added in v0.5.0

type DefaultHandler struct{}

A handler that does nothing (but recurses into master elements). Can be embedded into other handler struct to avoid implementing all callbacks.

func (DefaultHandler) HandleBinary added in v0.5.0

func (h DefaultHandler) HandleBinary(id ElementID, value []byte, info ElementInfo) error

func (DefaultHandler) HandleDate added in v0.5.0

func (h DefaultHandler) HandleDate(id ElementID, value time.Time, info ElementInfo) error

func (DefaultHandler) HandleFloat added in v0.5.0

func (h DefaultHandler) HandleFloat(id ElementID, value float64, info ElementInfo) error

func (DefaultHandler) HandleInteger added in v0.5.0

func (h DefaultHandler) HandleInteger(id ElementID, value int64, info ElementInfo) error

func (DefaultHandler) HandleMasterBegin added in v0.5.0

func (h DefaultHandler) HandleMasterBegin(id ElementID, info ElementInfo) (bool, error)

Returns `true` (recurses into the master element)

func (DefaultHandler) HandleMasterEnd added in v0.5.0

func (h DefaultHandler) HandleMasterEnd(id ElementID, info ElementInfo) error

func (DefaultHandler) HandleString added in v0.5.0

func (h DefaultHandler) HandleString(id ElementID, value string, info ElementInfo) error

type ElementID

type ElementID int64

ElementID represents the EBML ID of an element. The supported EBML IDs are documented in the Matroska specification: https://www.matroska.org/technical/specs/index.html

const (
	AlphaModeElement                   ElementID = 0x53C0
	AspectRatioTypeElement             ElementID = 0x54B3
	AttachedFileElement                ElementID = 0x61A7
	AttachmentLinkElement              ElementID = 0x7446
	AttachmentsElement                 ElementID = 0x1941A469
	AudioElement                       ElementID = 0xE1
	BitDepthElement                    ElementID = 0x6264
	BitsPerChannelElement              ElementID = 0x55B2
	BlockAddIDElement                  ElementID = 0xEE
	BlockAdditionIDElement             ElementID = 0xCB
	BlockAdditionalElement             ElementID = 0xA5
	BlockAdditionsElement              ElementID = 0x75A1
	BlockDurationElement               ElementID = 0x9B
	BlockElement                       ElementID = 0xA1
	BlockGroupElement                  ElementID = 0xA0
	BlockMoreElement                   ElementID = 0xA6
	BlockVirtualElement                ElementID = 0xA2
	CRC32Element                       ElementID = 0xBF
	CbSubsamplingHorzElement           ElementID = 0x55B5
	CbSubsamplingVertElement           ElementID = 0x55B6
	ChannelPositionsElement            ElementID = 0x7D7B
	ChannelsElement                    ElementID = 0x9F
	ChapCountryElement                 ElementID = 0x437E
	ChapLanguageElement                ElementID = 0x437C
	ChapLanguageIETFElement            ElementID = 0x437D
	ChapProcessCodecIDElement          ElementID = 0x6955
	ChapProcessCommandElement          ElementID = 0x6911
	ChapProcessDataElement             ElementID = 0x6933
	ChapProcessElement                 ElementID = 0x6944
	ChapProcessPrivateElement          ElementID = 0x450D
	ChapProcessTimeElement             ElementID = 0x6922
	ChapStringElement                  ElementID = 0x85
	ChapterAtomElement                 ElementID = 0xB6
	ChapterDisplayElement              ElementID = 0x80
	ChapterFlagEnabledElement          ElementID = 0x4598
	ChapterFlagHiddenElement           ElementID = 0x98
	ChapterPhysicalEquivElement        ElementID = 0x63C3
	ChapterSegmentEditionUIDElement    ElementID = 0x6EBC
	ChapterSegmentUIDElement           ElementID = 0x6E67
	ChapterStringUIDElement            ElementID = 0x5654
	ChapterTimeEndElement              ElementID = 0x92
	ChapterTimeStartElement            ElementID = 0x91
	ChapterTrackElement                ElementID = 0x8F
	ChapterTrackNumberElement          ElementID = 0x89
	ChapterTranslateCodecElement       ElementID = 0x69BF
	ChapterTranslateEditionUIDElement  ElementID = 0x69FC
	ChapterTranslateElement            ElementID = 0x6924
	ChapterTranslateIDElement          ElementID = 0x69A5
	ChapterUIDElement                  ElementID = 0x73C4
	ChaptersElement                    ElementID = 0x1043A770
	ChromaSitingHorzElement            ElementID = 0x55B7
	ChromaSitingVertElement            ElementID = 0x55B8
	ChromaSubsamplingHorzElement       ElementID = 0x55B3
	ChromaSubsamplingVertElement       ElementID = 0x55B4
	ClusterElement                     ElementID = 0x1F43B675
	CodecDecodeAllElement              ElementID = 0xAA
	CodecDelayElement                  ElementID = 0x56AA
	CodecDownloadURLElement            ElementID = 0x26B240
	CodecIDElement                     ElementID = 0x86
	CodecInfoURLElement                ElementID = 0x3B4040
	CodecNameElement                   ElementID = 0x258688
	CodecPrivateElement                ElementID = 0x63A2
	CodecSettingsElement               ElementID = 0x3A9697
	CodecStateElement                  ElementID = 0xA4
	ColourElement                      ElementID = 0x55B0
	ColourSpaceElement                 ElementID = 0x2EB524
	ContentCompAlgoElement             ElementID = 0x4254
	ContentCompSettingsElement         ElementID = 0x4255
	ContentCompressionElement          ElementID = 0x5034
	ContentEncAlgoElement              ElementID = 0x47E1
	ContentEncKeyIDElement             ElementID = 0x47E2
	ContentEncodingElement             ElementID = 0x6240
	ContentEncodingOrderElement        ElementID = 0x5031
	ContentEncodingScopeElement        ElementID = 0x5032
	ContentEncodingTypeElement         ElementID = 0x5033
	ContentEncodingsElement            ElementID = 0x6D80
	ContentEncryptionElement           ElementID = 0x5035
	ContentSigAlgoElement              ElementID = 0x47E5
	ContentSigHashAlgoElement          ElementID = 0x47E6
	ContentSigKeyIDElement             ElementID = 0x47E4
	ContentSignatureElement            ElementID = 0x47E3
	CueBlockNumberElement              ElementID = 0x5378
	CueClusterPositionElement          ElementID = 0xF1
	CueCodecStateElement               ElementID = 0xEA
	CueDurationElement                 ElementID = 0xB2
	CuePointElement                    ElementID = 0xBB
	CueRefClusterElement               ElementID = 0x97
	CueRefCodecStateElement            ElementID = 0xEB
	CueRefNumberElement                ElementID = 0x535F
	CueRefTimeElement                  ElementID = 0x96
	CueReferenceElement                ElementID = 0xDB
	CueRelativePositionElement         ElementID = 0xF0
	CueTimeElement                     ElementID = 0xB3
	CueTrackElement                    ElementID = 0xF7
	CueTrackPositionsElement           ElementID = 0xB7
	CuesElement                        ElementID = 0x1C53BB6B
	DateUTCElement                     ElementID = 0x4461
	DefaultDecodedFieldDurationElement ElementID = 0x234E7A
	DefaultDurationElement             ElementID = 0x23E383
	DelayElement                       ElementID = 0xCE
	DiscardPaddingElement              ElementID = 0x75A2
	DisplayHeightElement               ElementID = 0x54BA
	DisplayUnitElement                 ElementID = 0x54B2
	DisplayWidthElement                ElementID = 0x54B0
	DocTypeElement                     ElementID = 0x4282
	DocTypeExtensionElement            ElementID = 0x4281
	DocTypeExtensionNameElement        ElementID = 0x4283
	DocTypeExtensionVersionElement     ElementID = 0x4284
	DocTypeReadVersionElement          ElementID = 0x4285
	DocTypeVersionElement              ElementID = 0x4287
	DurationElement                    ElementID = 0x4489
	EBMLElement                        ElementID = 0x1A45DFA3
	EBMLMaxIDLengthElement             ElementID = 0x42F2
	EBMLMaxSizeLengthElement           ElementID = 0x42F3
	EBMLReadVersionElement             ElementID = 0x42F7
	EBMLVersionElement                 ElementID = 0x4286
	EditionEntryElement                ElementID = 0x45B9
	EditionFlagDefaultElement          ElementID = 0x45DB
	EditionFlagHiddenElement           ElementID = 0x45BD
	EditionFlagOrderedElement          ElementID = 0x45DD
	EditionUIDElement                  ElementID = 0x45BC
	EncryptedBlockElement              ElementID = 0xAF
	FieldOrderElement                  ElementID = 0x9D
	FileDataElement                    ElementID = 0x465C
	FileDescriptionElement             ElementID = 0x467E
	FileMimeTypeElement                ElementID = 0x4660
	FileNameElement                    ElementID = 0x466E
	FileReferralElement                ElementID = 0x4675
	FileUIDElement                     ElementID = 0x46AE
	FileUsedEndTimeElement             ElementID = 0x4662
	FileUsedStartTimeElement           ElementID = 0x4661
	FlagDefaultElement                 ElementID = 0x88
	FlagEnabledElement                 ElementID = 0xB9
	FlagForcedElement                  ElementID = 0x55AA
	FlagInterlacedElement              ElementID = 0x9A
	FlagLacingElement                  ElementID = 0x9C
	FrameNumberElement                 ElementID = 0xCD
	FrameRateElement                   ElementID = 0x2383E3
	GammaValueElement                  ElementID = 0x2FB523
	InfoElement                        ElementID = 0x1549A966
	LaceNumberElement                  ElementID = 0xCC
	LanguageElement                    ElementID = 0x22B59C
	LanguageIETFElement                ElementID = 0x22B59D
	LuminanceMaxElement                ElementID = 0x55D9
	LuminanceMinElement                ElementID = 0x55DA
	MasteringMetadataElement           ElementID = 0x55D0
	MatrixCoefficientsElement          ElementID = 0x55B1
	MaxBlockAdditionIDElement          ElementID = 0x55EE
	MaxCLLElement                      ElementID = 0x55BC
	MaxCacheElement                    ElementID = 0x6DF8
	MaxFALLElement                     ElementID = 0x55BD
	MinCacheElement                    ElementID = 0x6DE7
	MuxingAppElement                   ElementID = 0x4D80
	NameElement                        ElementID = 0x536E
	NextFilenameElement                ElementID = 0x3E83BB
	NextUIDElement                     ElementID = 0x3EB923
	OldStereoModeElement               ElementID = 0x53B9
	OutputSamplingFrequencyElement     ElementID = 0x78B5
	PixelCropBottomElement             ElementID = 0x54AA
	PixelCropLeftElement               ElementID = 0x54CC
	PixelCropRightElement              ElementID = 0x54DD
	PixelCropTopElement                ElementID = 0x54BB
	PixelHeightElement                 ElementID = 0xBA
	PixelWidthElement                  ElementID = 0xB0
	PositionElement                    ElementID = 0xA7
	PrevFilenameElement                ElementID = 0x3C83AB
	PrevSizeElement                    ElementID = 0xAB
	PrevUIDElement                     ElementID = 0x3CB923
	PrimariesElement                   ElementID = 0x55BB
	PrimaryBChromaticityXElement       ElementID = 0x55D5
	PrimaryBChromaticityYElement       ElementID = 0x55D6
	PrimaryGChromaticityXElement       ElementID = 0x55D3
	PrimaryGChromaticityYElement       ElementID = 0x55D4
	PrimaryRChromaticityXElement       ElementID = 0x55D1
	PrimaryRChromaticityYElement       ElementID = 0x55D2
	ProjectionElement                  ElementID = 0x7670
	ProjectionPosePitchElement         ElementID = 0x7674
	ProjectionPoseRollElement          ElementID = 0x7675
	ProjectionPoseYawElement           ElementID = 0x7673
	ProjectionPrivateElement           ElementID = 0x7672
	ProjectionTypeElement              ElementID = 0x7671
	RangeElement                       ElementID = 0x55B9
	ReferenceBlockElement              ElementID = 0xFB
	ReferenceFrameElement              ElementID = 0xC8
	ReferenceOffsetElement             ElementID = 0xC9
	ReferencePriorityElement           ElementID = 0xFA
	ReferenceTimeCodeElement           ElementID = 0xCA
	ReferenceVirtualElement            ElementID = 0xFD
	SamplingFrequencyElement           ElementID = 0xB5
	SeekElement                        ElementID = 0x4DBB
	SeekHeadElement                    ElementID = 0x114D9B74
	SeekIDElement                      ElementID = 0x53AB
	SeekPositionElement                ElementID = 0x53AC
	SeekPreRollElement                 ElementID = 0x56BB
	SegmentElement                     ElementID = 0x18538067
	SegmentFamilyElement               ElementID = 0x4444
	SegmentFilenameElement             ElementID = 0x7384
	SegmentUIDElement                  ElementID = 0x73A4
	SilentTrackNumberElement           ElementID = 0x58D7
	SilentTracksElement                ElementID = 0x5854
	SimpleBlockElement                 ElementID = 0xA3
	SimpleTagElement                   ElementID = 0x67C8
	SliceDurationElement               ElementID = 0xCF
	SlicesElement                      ElementID = 0x8E
	StereoModeElement                  ElementID = 0x53B8
	TagAttachmentUIDElement            ElementID = 0x63C6
	TagBinaryElement                   ElementID = 0x4485
	TagChapterUIDElement               ElementID = 0x63C4
	TagDefaultElement                  ElementID = 0x4484
	TagEditionUIDElement               ElementID = 0x63C9
	TagElement                         ElementID = 0x7373
	TagLanguageElement                 ElementID = 0x447A
	TagLanguageIETFElement             ElementID = 0x447B
	TagNameElement                     ElementID = 0x45A3
	TagStringElement                   ElementID = 0x4487
	TagTrackUIDElement                 ElementID = 0x63C5
	TagsElement                        ElementID = 0x1254C367
	TargetTypeElement                  ElementID = 0x63CA
	TargetTypeValueElement             ElementID = 0x68CA
	TargetsElement                     ElementID = 0x63C0
	TimeSliceElement                   ElementID = 0xE8
	TimecodeElement                    ElementID = 0xE7
	TimecodeScaleElement               ElementID = 0x2AD7B1
	TitleElement                       ElementID = 0x7BA9
	TrackCombinePlanesElement          ElementID = 0xE3
	TrackEntryElement                  ElementID = 0xAE
	TrackJoinBlocksElement             ElementID = 0xE9
	TrackJoinUIDElement                ElementID = 0xED
	TrackNumberElement                 ElementID = 0xD7
	TrackOffsetElement                 ElementID = 0x537F
	TrackOperationElement              ElementID = 0xE2
	TrackOverlayElement                ElementID = 0x6FAB
	TrackPlaneElement                  ElementID = 0xE4
	TrackPlaneTypeElement              ElementID = 0xE6
	TrackPlaneUIDElement               ElementID = 0xE5
	TrackTimecodeScaleElement          ElementID = 0x23314F
	TrackTranslateCodecElement         ElementID = 0x66BF
	TrackTranslateEditionUIDElement    ElementID = 0x66FC
	TrackTranslateElement              ElementID = 0x6624
	TrackTranslateTrackIDElement       ElementID = 0x66A5
	TrackTypeElement                   ElementID = 0x83
	TrackUIDElement                    ElementID = 0x73C5
	TracksElement                      ElementID = 0x1654AE6B
	TransferCharacteristicsElement     ElementID = 0x55BA
	TrickMasterTrackSegmentUIDElement  ElementID = 0xC4
	TrickMasterTrackUIDElement         ElementID = 0xC7
	TrickTrackFlagElement              ElementID = 0xC6
	TrickTrackSegmentUIDElement        ElementID = 0xC1
	TrickTrackUIDElement               ElementID = 0xC0
	VideoElement                       ElementID = 0xE0
	VoidElement                        ElementID = 0xEC
	WhitePointChromaticityXElement     ElementID = 0x55D7
	WhitePointChromaticityYElement     ElementID = 0x55D8
	WritingAppElement                  ElementID = 0x5741
)

Supported ElementIDs

type ElementInfo

type ElementInfo struct {
	Offset int64
	Size   int64
	Level  int
}

ElementInfo contains information about an element encountered in the stream, and is passed to the handler by the parser on parse events.

type Handler

type Handler interface {
	// Return `true` to descend into the element, `false` to skip this element's children.
	HandleMasterBegin(ElementID, ElementInfo) (bool, error)
	HandleMasterEnd(ElementID, ElementInfo) error
	HandleString(ElementID, string, ElementInfo) error
	HandleInteger(ElementID, int64, ElementInfo) error
	HandleFloat(ElementID, float64, ElementInfo) error
	HandleDate(ElementID, time.Time, ElementInfo) error
	HandleBinary(ElementID, []byte, ElementInfo) error
}

Handler declares an interface for handling parse events

type HandlerChain added in v0.10.0

type HandlerChain struct {
	Handlers []Handler
}

Handler that chains multiple handlers.

All handlers are called in sequence. If one of the handers requests to descend, the parser will descend.

Example
package main

import (
	"fmt"
	"os"
)

func main() {
	file, err := os.Open("testdata/example-cover.mkv")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	coverh := CoverHandler{}
	titleh := TitleHandler{}
	if err := ParseSections(file, NewHandlerChain(&coverh, &titleh), InfoElement, AttachmentsElement); err != nil {
		panic(err)
	}
	fmt.Printf("parsed cover: %s (%d bytes)\n", coverh.MIMEType, len(coverh.Data))

}

type TitleHandler struct {
	DefaultHandler
}

func (p *TitleHandler) HandleString(id ElementID, value string, info ElementInfo) error {
	switch id {
	case TitleElement:
		fmt.Printf("%s: %v\n", NameForElementID(id), value)
	}
	return nil
}
Output:

Title: Awesome Movie
parsed cover: image/jpeg (41363 bytes)

func NewHandlerChain added in v0.10.0

func NewHandlerChain(handlers ...Handler) *HandlerChain

Creates a new handler that chains `handlers`

func (*HandlerChain) HandleBinary added in v0.10.0

func (c *HandlerChain) HandleBinary(id ElementID, value []byte, info ElementInfo) error

func (*HandlerChain) HandleDate added in v0.10.0

func (c *HandlerChain) HandleDate(id ElementID, value time.Time, info ElementInfo) error

func (*HandlerChain) HandleFloat added in v0.10.0

func (c *HandlerChain) HandleFloat(id ElementID, value float64, info ElementInfo) error

func (*HandlerChain) HandleInteger added in v0.10.0

func (c *HandlerChain) HandleInteger(id ElementID, value int64, info ElementInfo) error

func (*HandlerChain) HandleMasterBegin added in v0.10.0

func (c *HandlerChain) HandleMasterBegin(id ElementID, info ElementInfo) (bool, error)

func (*HandlerChain) HandleMasterEnd added in v0.10.0

func (c *HandlerChain) HandleMasterEnd(id ElementID, info ElementInfo) error

func (*HandlerChain) HandleString added in v0.10.0

func (c *HandlerChain) HandleString(id ElementID, value string, info ElementInfo) error

type TagsHandler added in v0.11.0

type TagsHandler struct {
	DefaultHandler
	// contains filtered or unexported fields
}

Handler that collects tags.

Needs the section parser to handle `TagsElement`.

Example
file, err := os.Open("testdata/example.mkv")
if err != nil {
	panic(err)
}
defer file.Close()

handler := NewTagsHandler()
if err := ParseSections(file, handler, TagsElement); err != nil {
	panic(err)
}

fmt.Printf("Artist: %s\n", handler.Tags()[Tag_Artist])
Output:

Artist: John Doe

func NewTagsHandler added in v0.11.0

func NewTagsHandler() *TagsHandler

func (*TagsHandler) AttachmentTags added in v0.11.0

func (h *TagsHandler) AttachmentTags(uid int64) map[string]string

Retrieves tags for attachment with UID `uid`.

Returns nil if no tags were encountered for this attachment.

func (*TagsHandler) ChapterTags added in v0.11.0

func (h *TagsHandler) ChapterTags(uid int64) map[string]string

Retrieves tags for chapter with UID `uid`.

Returns nil if no tags were encountered for this chapter.

func (*TagsHandler) EditionTags added in v0.11.0

func (h *TagsHandler) EditionTags(uid int64) map[string]string

Retrieves tags for edition with UID `uid`.

Returns nil if no tags were encountered for this edition.

func (*TagsHandler) HandleInteger added in v0.11.0

func (p *TagsHandler) HandleInteger(id ElementID, value int64, info ElementInfo) error

func (*TagsHandler) HandleMasterBegin added in v0.11.0

func (p *TagsHandler) HandleMasterBegin(id ElementID, info ElementInfo) (bool, error)

func (*TagsHandler) HandleMasterEnd added in v0.11.0

func (p *TagsHandler) HandleMasterEnd(id ElementID, info ElementInfo) error

func (*TagsHandler) HandleString added in v0.11.0

func (p *TagsHandler) HandleString(id ElementID, value string, info ElementInfo) error

func (*TagsHandler) Tags added in v0.11.0

func (h *TagsHandler) Tags() map[string]string

Retrieves all global tags

func (*TagsHandler) TrackTags added in v0.11.0

func (h *TagsHandler) TrackTags(uid int64) map[string]string

Retrieves tags for track with UID `uid`.

Returns nil if no tags were encountered for this track.

Directories

Path Synopsis
examples
mkvdir2mrss
mkvdir2mrss parses all MKV files in a dir, and generates a (Media) RSS feed for them.
mkvdir2mrss parses all MKV files in a dir, and generates a (Media) RSS feed for them.
mkvinfo
Prints all information of an MKV file
Prints all information of an MKV file
mkvtags
Prints tags of an MKV file
Prints tags of an MKV file
internal

Jump to

Keyboard shortcuts

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