Documentation
¶
Overview ¶
Provides push-style parser functions for parsing Matroska (`.mkv`, `.mka`) files.
Example ¶
package main
import (
"fmt"
"log"
"time"
)
type MyParser struct {
DefaultHandler
}
func (p *MyParser) HandleMasterBegin(id ElementID, info ElementInfo) (bool, error) {
return true, nil
}
func (p *MyParser) HandleMasterEnd(id ElementID, info ElementInfo) error {
return nil
}
func (p *MyParser) HandleString(id ElementID, value string, info ElementInfo) error {
if id == TitleElement {
fmt.Printf("%s: %v\n", NameForElementID(id), value)
}
return nil
}
func (p *MyParser) HandleInteger(id ElementID, value int64, info ElementInfo) error {
return nil
}
func (p *MyParser) HandleFloat(id ElementID, value float64, info ElementInfo) error {
return nil
}
func (p *MyParser) HandleDate(id ElementID, value time.Time, info ElementInfo) error {
return nil
}
func (p *MyParser) HandleBinary(id ElementID, value []byte, info ElementInfo) error {
return nil
}
func main() {
handler := MyParser{}
if err := ParsePath("example.mkv", &handler); err != nil {
log.Fatalf("%v", err)
}
}
Output: Title: Awesome Movie
Index ¶
- Constants
- func NameForElementID(id ElementID) string
- func Parse(reader io.Reader, handler Handler) error
- func ParsePath(path string, handler Handler) error
- func ParseSections(file *os.File, sections []ElementID, handler Handler) error
- type DefaultHandler
- func (dh *DefaultHandler) HandleBinary(ElementID, []byte, ElementInfo) error
- func (dh *DefaultHandler) HandleDate(ElementID, time.Time, ElementInfo) error
- func (dh *DefaultHandler) HandleFloat(ElementID, float64, ElementInfo) error
- func (dh *DefaultHandler) HandleInteger(ElementID, int64, ElementInfo) error
- func (dh *DefaultHandler) HandleMasterBegin(ElementID, ElementInfo) (bool, error)
- func (dh *DefaultHandler) HandleMasterEnd(ElementID, ElementInfo) error
- func (dh *DefaultHandler) HandleParseError(reader io.Reader, err *ParseError) *ParseError
- func (dh *DefaultHandler) HandleString(ElementID, string, ElementInfo) error
- type Element
- type ElementID
- type ElementInfo
- type ElementStack
- type ElementType
- type Handler
- type InvalidElementError
- type InvalidFloatSizeError
- type ParseError
- type TruncatedInputError
Examples ¶
Constants ¶
const ( EBMLElement = 0x1A45DFA3 EBMLVersionElement = 0x4286 EBMLReadVersionElement = 0x42F7 EBMLMaxIDLengthElement = 0x42F2 EBMLMaxSizeLengthElement = 0x42F3 DocTypeElement = 0x4282 DocTypeVersionElement = 0x4287 DocTypeReadVersionElement = 0x4285 VoidElement = 0xEC CRC32Element = 0xBF SignatureSlotElement = 0x1B538667 SignatureAlgoElement = 0x7E8A SignatureHashElement = 0x7E9A SignaturePublicKeyElement = 0x7EA5 SignatureElement = 0x7EB5 SignatureElementsElement = 0x7E5B SignatureElementListElement = 0x7E7B SignedElementElement = 0x6532 SegmentElement = 0x18538067 SeekHeadElement = 0x114D9B74 SeekElement = 0x4DBB SeekIDElement = 0x53AB SeekPositionElement = 0x53AC InfoElement = 0x1549A966 SegmentUIDElement = 0x73A4 SegmentFilenameElement = 0x7384 PrevUIDElement = 0x3CB923 PrevFilenameElement = 0x3C83AB NextUIDElement = 0x3EB923 NextFilenameElement = 0x3E83BB SegmentFamilyElement = 0x4444 ChapterTranslateElement = 0x6924 ChapterTranslateEditionUIDElement = 0x69FC ChapterTranslateCodecElement = 0x69BF ChapterTranslateIDElement = 0x69A5 TimecodeScaleElement = 0x2AD7B1 DurationElement = 0x4489 DateUTCElement = 0x4461 TitleElement = 0x7BA9 MuxingAppElement = 0x4D80 WritingAppElement = 0x5741 ClusterElement = 0x1F43B675 TimecodeElement = 0xE7 SilentTracksElement = 0x5854 SilentTrackNumberElement = 0x58D7 PositionElement = 0xA7 PrevSizeElement = 0xAB SimpleBlockElement = 0xA3 BlockGroupElement = 0xA0 BlockElement = 0xA1 BlockVirtualElement = 0xA2 BlockAdditionsElement = 0x75A1 BlockMoreElement = 0xA6 BlockAddIDElement = 0xEE BlockAdditionalElement = 0xA5 BlockDurationElement = 0x9B ReferencePriorityElement = 0xFA ReferenceBlockElement = 0xFB ReferenceVirtualElement = 0xFD CodecStateElement = 0xA4 DiscardPaddingElement = 0x75A2 SlicesElement = 0x8E TimeSliceElement = 0xE8 LaceNumberElement = 0xCC FrameNumberElement = 0xCD BlockAdditionIDElement = 0xCB DelayElement = 0xCE SliceDurationElement = 0xCF ReferenceFrameElement = 0xC8 ReferenceOffsetElement = 0xC9 ReferenceTimeCodeElement = 0xCA EncryptedBlockElement = 0xAF TracksElement = 0x1654AE6B TrackEntryElement = 0xAE TrackNumberElement = 0xD7 TrackUIDElement = 0x73C5 TrackTypeElement = 0x83 FlagEnabledElement = 0xB9 FlagDefaultElement = 0x88 FlagForcedElement = 0x55AA FlagLacingElement = 0x9C MinCacheElement = 0x6DE7 MaxCacheElement = 0x6DF8 DefaultDurationElement = 0x23E383 DefaultDecodedFieldDurationElement = 0x234E7A TrackTimecodeScaleElement = 0x23314F TrackOffsetElement = 0x537F MaxBlockAdditionIDElement = 0x55EE NameElement = 0x536E LanguageElement = 0x22B59C LanguageIETFElement = 0x22B59D CodecIDElement = 0x86 CodecPrivateElement = 0x63A2 CodecNameElement = 0x258688 AttachmentLinkElement = 0x7446 CodecSettingsElement = 0x3A9697 CodecInfoURLElement = 0x3B4040 CodecDownloadURLElement = 0x26B240 CodecDecodeAllElement = 0xAA TrackOverlayElement = 0x6FAB CodecDelayElement = 0x56AA SeekPreRollElement = 0x56BB TrackTranslateElement = 0x6624 TrackTranslateEditionUIDElement = 0x66FC TrackTranslateCodecElement = 0x66BF TrackTranslateTrackIDElement = 0x66A5 VideoElement = 0xE0 FlagInterlacedElement = 0x9A FieldOrderElement = 0x9D StereoModeElement = 0x53B8 AlphaModeElement = 0x53C0 OldStereoModeElement = 0x53B9 PixelWidthElement = 0xB0 PixelHeightElement = 0xBA PixelCropBottomElement = 0x54AA PixelCropTopElement = 0x54BB PixelCropLeftElement = 0x54CC PixelCropRightElement = 0x54DD DisplayWidthElement = 0x54B0 DisplayHeightElement = 0x54BA DisplayUnitElement = 0x54B2 AspectRatioTypeElement = 0x54B3 ColourSpaceElement = 0x2EB524 GammaValueElement = 0x2FB523 FrameRateElement = 0x2383E3 ColourElement = 0x55B0 MatrixCoefficientsElement = 0x55B1 BitsPerChannelElement = 0x55B2 ChromaSubsamplingHorzElement = 0x55B3 ChromaSubsamplingVertElement = 0x55B4 CbSubsamplingHorzElement = 0x55B5 CbSubsamplingVertElement = 0x55B6 ChromaSitingHorzElement = 0x55B7 ChromaSitingVertElement = 0x55B8 RangeElement = 0x55B9 TransferCharacteristicsElement = 0x55BA PrimariesElement = 0x55BB MaxCLLElement = 0x55BC MaxFALLElement = 0x55BD MasteringMetadataElement = 0x55D0 PrimaryRChromaticityXElement = 0x55D1 PrimaryRChromaticityYElement = 0x55D2 PrimaryGChromaticityXElement = 0x55D3 PrimaryGChromaticityYElement = 0x55D4 PrimaryBChromaticityXElement = 0x55D5 PrimaryBChromaticityYElement = 0x55D6 WhitePointChromaticityXElement = 0x55D7 WhitePointChromaticityYElement = 0x55D8 LuminanceMaxElement = 0x55D9 LuminanceMinElement = 0x55DA ProjectionElement = 0x7670 ProjectionTypeElement = 0x7671 ProjectionPrivateElement = 0x7672 ProjectionPoseYawElement = 0x7673 ProjectionPosePitchElement = 0x7674 ProjectionPoseRollElement = 0x7675 AudioElement = 0xE1 SamplingFrequencyElement = 0xB5 OutputSamplingFrequencyElement = 0x78B5 ChannelsElement = 0x9F ChannelPositionsElement = 0x7D7B BitDepthElement = 0x6264 TrackOperationElement = 0xE2 TrackCombinePlanesElement = 0xE3 TrackPlaneElement = 0xE4 TrackPlaneUIDElement = 0xE5 TrackPlaneTypeElement = 0xE6 TrackJoinBlocksElement = 0xE9 TrackJoinUIDElement = 0xED TrickTrackUIDElement = 0xC0 TrickTrackSegmentUIDElement = 0xC1 TrickTrackFlagElement = 0xC6 TrickMasterTrackUIDElement = 0xC7 TrickMasterTrackSegmentUIDElement = 0xC4 ContentEncodingsElement = 0x6D80 ContentEncodingElement = 0x6240 ContentEncodingOrderElement = 0x5031 ContentEncodingScopeElement = 0x5032 ContentEncodingTypeElement = 0x5033 ContentCompressionElement = 0x5034 ContentCompAlgoElement = 0x4254 ContentCompSettingsElement = 0x4255 ContentEncryptionElement = 0x5035 ContentEncAlgoElement = 0x47E1 ContentEncKeyIDElement = 0x47E2 ContentEncAESSettingsElement = 0x47E7 AESSettingsCipherModeElement = 0x47E8 ContentSignatureElement = 0x47E3 ContentSigKeyIDElement = 0x47E4 ContentSigAlgoElement = 0x47E5 ContentSigHashAlgoElement = 0x47E6 CuesElement = 0x1C53BB6B CuePointElement = 0xBB CueTimeElement = 0xB3 CueTrackPositionsElement = 0xB7 CueTrackElement = 0xF7 CueClusterPositionElement = 0xF1 CueRelativePositionElement = 0xF0 CueDurationElement = 0xB2 CueBlockNumberElement = 0x5378 CueCodecStateElement = 0xEA CueReferenceElement = 0xDB CueRefTimeElement = 0x96 CueRefClusterElement = 0x97 CueRefNumberElement = 0x535F CueRefCodecStateElement = 0xEB AttachmentsElement = 0x1941A469 AttachedFileElement = 0x61A7 FileDescriptionElement = 0x467E FileNameElement = 0x466E FileMimeTypeElement = 0x4660 FileDataElement = 0x465C FileUIDElement = 0x46AE FileReferralElement = 0x4675 FileUsedStartTimeElement = 0x4661 FileUsedEndTimeElement = 0x4662 ChaptersElement = 0x1043A770 EditionEntryElement = 0x45B9 EditionUIDElement = 0x45BC EditionFlagHiddenElement = 0x45BD EditionFlagDefaultElement = 0x45DB EditionFlagOrderedElement = 0x45DD ChapterAtomElement = 0xB6 ChapterUIDElement = 0x73C4 ChapterStringUIDElement = 0x5654 ChapterTimeStartElement = 0x91 ChapterTimeEndElement = 0x92 ChapterFlagHiddenElement = 0x98 ChapterFlagEnabledElement = 0x4598 ChapterSegmentUIDElement = 0x6E67 ChapterSegmentEditionUIDElement = 0x6EBC ChapterPhysicalEquivElement = 0x63C3 ChapterTrackElement = 0x8F ChapterTrackNumberElement = 0x89 ChapterDisplayElement = 0x80 ChapStringElement = 0x85 ChapLanguageElement = 0x437C ChapLanguageIETFElement = 0x437D ChapCountryElement = 0x437E ChapProcessElement = 0x6944 ChapProcessCodecIDElement = 0x6955 ChapProcessPrivateElement = 0x450D ChapProcessCommandElement = 0x6911 ChapProcessTimeElement = 0x6922 ChapProcessDataElement = 0x6933 TagsElement = 0x1254C367 TagElement = 0x7373 TargetsElement = 0x63C0 TargetTypeValueElement = 0x68CA TargetTypeElement = 0x63CA TagTrackUIDElement = 0x63C5 TagEditionUIDElement = 0x63C9 TagChapterUIDElement = 0x63C4 TagAttachmentUIDElement = 0x63C6 SimpleTagElement = 0x67C8 TagNameElement = 0x45A3 TagLanguageElement = 0x447A TagLanguageIETFElement = 0x447B TagDefaultElement = 0x4484 TagStringElement = 0x4487 TagBinaryElement = 0x4485 )
Supported ElementIDs
const UnknownSize = -1
https://github.com/cellar-wg/ebml-specification/blob/master/specification.markdown#element-data-size
An Element Data Size with all VINT_DATA bits set to one is reserved as an indicator that the size of the EBML Element is unknown.
Variables ¶
This section is empty.
Functions ¶
func NameForElementID ¶
Gives the human-readable name for the given element ID.
Example ¶
fmt.Println(NameForElementID(InfoElement))
Output: Info
func ParseSections ¶
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"
"time"
)
type myTitleParser struct {
DefaultHandler
}
func (p *myTitleParser) HandleMasterBegin(id ElementID, info ElementInfo) (bool, error) {
return true, nil
}
func (p *myTitleParser) HandleMasterEnd(id ElementID, info ElementInfo) error {
return nil
}
func (p *myTitleParser) HandleString(id ElementID, value string, info ElementInfo) error {
if id == TitleElement {
fmt.Printf("%s: %v\n", NameForElementID(id), value)
}
return nil
}
func (p *myTitleParser) HandleInteger(id ElementID, value int64, info ElementInfo) error {
return nil
}
func (p *myTitleParser) HandleFloat(id ElementID, value float64, info ElementInfo) error {
return nil
}
func (p *myTitleParser) HandleDate(id ElementID, value time.Time, info ElementInfo) error {
return nil
}
func (p *myTitleParser) HandleBinary(id ElementID, value []byte, info ElementInfo) error {
return nil
}
func main() {
file, err := os.Open("example.mkv")
if err != nil {
log.Fatalf("%v", err)
}
defer file.Close()
handler := myTitleParser{}
if err = ParseSections(file, []ElementID{InfoElement}, &handler); err != nil {
log.Fatalf("%v", err)
}
}
Output: Title: Awesome Movie
Types ¶
type DefaultHandler ¶
type DefaultHandler struct{}
DefaultHandler has basic handlers that do nothing and descend into all elements. This can be used as the basis of a handler if you only want to implement a subset of the handlers.
func (*DefaultHandler) HandleBinary ¶
func (dh *DefaultHandler) HandleBinary(ElementID, []byte, ElementInfo) error
func (*DefaultHandler) HandleDate ¶
func (dh *DefaultHandler) HandleDate(ElementID, time.Time, ElementInfo) error
func (*DefaultHandler) HandleFloat ¶
func (dh *DefaultHandler) HandleFloat(ElementID, float64, ElementInfo) error
func (*DefaultHandler) HandleInteger ¶
func (dh *DefaultHandler) HandleInteger(ElementID, int64, ElementInfo) error
func (*DefaultHandler) HandleMasterBegin ¶
func (dh *DefaultHandler) HandleMasterBegin(ElementID, ElementInfo) (bool, error)
func (*DefaultHandler) HandleMasterEnd ¶
func (dh *DefaultHandler) HandleMasterEnd(ElementID, ElementInfo) error
func (*DefaultHandler) HandleParseError ¶
func (dh *DefaultHandler) HandleParseError(reader io.Reader, err *ParseError) *ParseError
func (*DefaultHandler) HandleString ¶
func (dh *DefaultHandler) HandleString(ElementID, string, ElementInfo) error
type Element ¶
type Element struct {
ID ElementID
Info ElementInfo
}
Combined element id and information.
type ElementInfo ¶
type ElementStack ¶
type ElementStack []Element
A stack of elements.
func NewElementStack ¶
func NewElementStack() *ElementStack
func (*ElementStack) Peek ¶
func (es *ElementStack) Peek() (id ElementID, info ElementInfo)
Return the top element on the stack.
func (*ElementStack) Pop ¶
func (es *ElementStack) Pop() (id ElementID, info ElementInfo)
Remove the top element on the stack and return it.
func (*ElementStack) Push ¶
func (es *ElementStack) Push(id ElementID, info ElementInfo)
Push the id and info onto the element stack.
func (*ElementStack) String ¶
func (es *ElementStack) String() string
Render a human readable list of stack id names.
func (*ElementStack) UnknownSize ¶
func (es *ElementStack) UnknownSize() (index int, ok bool)
Return the index of the last element with an unknown size. If no element of unknown size exists, then index will be 0 and ok will be false.
type ElementType ¶
type ElementType int
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
HandleParseError(reader io.Reader, err *ParseError) *ParseError
}
Interface for handling parse events
type InvalidElementError ¶
func (*InvalidElementError) Error ¶
func (iee *InvalidElementError) Error() string
type InvalidFloatSizeError ¶
func (*InvalidFloatSizeError) Error ¶
func (ifse *InvalidFloatSizeError) Error() string
type ParseError ¶
type ParseError struct {
Offset int64
Stack *ElementStack
Err error
}
func NewParseError ¶
func NewParseError(offset int64, stack *ElementStack, e error) *ParseError
func (*ParseError) Error ¶
func (pe *ParseError) Error() string
type TruncatedInputError ¶
func (*TruncatedInputError) Error ¶
func (tie *TruncatedInputError) Error() string