前段时间一直没有时间,把自己的mkv总结写了下:
其他信息可以参看规范,我把精要的东西列了出来,为了编程方便。
MATROSKA files的基本结构由两部分组成:
EBML(可扩展二进制元语言)
Segment
segment中有tracks,track的 入口 trackentry有 audio,video。
EBML:一个文件应该只有一个EBML header,之后的都无效,被忽略。
Segment:包含了multimedia data,也包含了重放必须的header data.一个MATROSKA file可以包含多个segment数据,但不鼓励这样做。
EBML top level element包含了文件类型,文件版本等描述。
EBMLVERSION ID:42 86 def: 1
EBMLREADVERSION ID:42 F7 def: 1
EBMLMAXIDLENGTH ID:42 F2 def: 4
EBMLMAXSIZELENGTH ID:42 F3 def: 8
DOCTYPE ID:42 82 def: matroska
DOCTYPEVERSION ID:42 87 def: 1
DOCTYPEREADVERSION ID:42 85 def: 1
SEGMENT (top-level)
SEGMENTINFO(->3) ID:15 49 A9 66 def: (包含 UID,title等)
SEEKHEAD(->4) ID:11 4D 9B 74 def:
CLUSTER(->16) ID:1F 43 B6 75 def: (不包含multimedia data非强制性元素)
TRACKS(->6) ID:16 54 AE 6B def: ()
CUES(->18) ID:1C 53 BB 6B def:
ATTACHMENTS(->26) ID:19 41 A4 69
CHAPTERS(->21) ID:10 43 A7 70
TAGS(->28) ID:12 54 C3 67
SEGMENTINFO
SEGMENTUID ID:73 A4 char[16]
SEGMENTFILENAME ID:73 84 utf-8
PREVUID ID:3C B9 23 char[16]
PREVFILENAME ID:3C 83 AB utf-8
NEXTUID ID:3E B9 23 char[16]
NEXTFILENAME ID:3E 83 BB utf-8
TIMECODESCALE ID:2A D7 B1 uint
DURATION ID:44 89 float
TITLE ID:7B A9 utf-8
MUXINGAPP ID:4D 80 string
WRITINGAPP ID:57 41 utf-8
DATEUTC ID:44 61 int
SeekHead
SEEK(->5) ID:4D BB
SEEK
SEEKID ID:53 AB uint
SEEKPOSITION ID:53 AC uint 以0x4d bb为结束符
不是所有的level 1元素都会在同一个文件中出现。
Tracks
Tracks元素包含了在Segment中存储的audio,video,subtitles,used codec,resolution和采样率等。
TRACKENTRY(->7) ID:AE
TRACKENTRY
TRACKNUMBER ID:D7 uint
TRACKUID ID:73 C5 uint
TRACKTYPE ID:83 uint (ie:audio,video)
FLAGENABLED ID:B9 bool (=1 track is used)
FLAGDEFAULT ID:88 bool
FLAGFORCED ID:55 AA bool
FLAGLACING ID:9C bool
MINCACHE ID:6D E7 uint
MAXCACHE ID:6D F8 uint
DEFAULTDURATION ID:23 E3 83 uint
TRACKTIMECODESCALE ID:23 31 4F float
NAME ID:53 6E utf-8
LANGUAGE ID:22 B5 9C string
CODECID ID:86 string
CODECPRIVATE ID:63 A2 binary
CODECNAME ID:25 86 88 utf-8
ATTACHMENTLINK ID:74 46 uint
VIDEO(->8) ID:E0
AUDIO(->9) ID:E1
CONTENTENCODINGS(->10) ID:6D 80
VIDEO
PIXELWIDTH ID:B0 uint
PIXELHEIGHT ID:BA uint
PIXELCROPBOTTOM ID:54 AA uint
PIXELCROPTOP ID:54 BB uint
PIXELCROPLEFT ID:54 CC uint
PIXELCROPRIGHT ID:54 DD uint
DISPLAYWIDTH ID:54 B0 uint
DISPLAYHEIGHT ID:54 BA uint
DISPLAYUNIT ID:54 B2 uint
AUDIO
SAMPLINGFREQUENCY ID:B5 uint def:8kHz
OUTPUT-SAMPLINGFREQUENCY ID:78 B5 uint
CHANNELS ID:9F
BITDEPTH ID:62 64
CONTENTENCODINGS
CONTENTENCODING ID:62 40
CONTENTENCODING
CONTENTENCODING-ORDER ID:50 31
CONTENTENCODING-SCOPE(->14) ID:50 32
CONTENTENCODING-TYPE ID:50 33
CONTENTCOMPRESSION(->12) ID:50 34
CONTENTENCRYPTION(->??) ID:50 35
CONTENTCOMPRESSION
CONTENTCOMPALGO(->15) ID:42 54
CONTENTCOMPSETTINGS ID:42 55
The values of tracktype:
0x01 video
0x02 audio
0x03 complex track
0x10 logo track
0x11 subtitle track
0x12 button track
0x20 control track
Bits in CONTENTENCODINGSCOPE
1 all frames
2 codecprivate
4 the CONTENTCOMPRESSION in the next CONTENTENCODING
VALUES OF contentcompalgo
0 zlib
1 bzlib
2 lzo 1x
3 header striping
Cluster
TIMECODE ID:E7 uint
POSITION ID:A7 uint
PREVSIZE ID:AB uint
BLOCKGROUP(->17) ID:A0 uint
SIMPLEBLOCK ID:A3 binary
BLOCKGROUP
BLOCK ID:A1 binary
REFERENCEBLOCK ID:FB int
BLOCKDURATION ID:9B int
CUES
CUEPOINT(->19) ID:BB
CUEPOINT
CUETIME ID:B3 uint
CUETRACKPOSITIONS(->20) ID:B7
CUETRACKPOSITIONS
CUETRACK ID:F7
CUECLUSTERPOSITION ID:F1
CUEBLOCKNUMBER ID:53 78
CHAPTERS
EDITIONENTRY(->22) ID:45 B9
EDITionENTRY
EDITIONUID ID:45 BC
EDITIONFLAGHIDDEN ID:45 BD
EDITIONFLAGDEFAULT ID:45 DB
EDITIONFLAGORDERED ID:45 DD
CHAPTERATOPM(->23) ID:B6
CHAPTERATOM
CHAPTERUID ID:73 C4
CHAPTERTIMESTART ID:91
CHAPTERTIMEEND ID:92
CHAPTERFLAGHIDDEN ID:98
CHAPTERFLAGENABLED ID:45 98
CHAPTERSEGMENTUID ID:6E 67
CHAPTERSEGMENT-EDITIONUID ID:6E BC
CHAPTERTRACKS(->24) ID:8F
CHAPTERDISPLAY(->25) ID:80
CHAPTERTRACKS
CHAPTERTRACKNUMBER ID:89
CHAPTERDISPLAY
CHAPSTRING ID:85
CHAPLANGUAGE ID:43 7C
CHAPCOUNTRY ID:43 7E
ATTACHMENTS
ATTACHEDFILE ID:61 A7
ATTACHEDFILE
FILEDESCRIPTION ID:46 7E
FILENAME ID:46 6E
FILEMIMETYPE ID:46 60
FILEDATA ID:46 5C
FILEUID ID:46 AE
TAGS
TAG(->29) ID:73 73
TAG
TAGGETS(->30) ID:63 C0
SIMPLETAG(->31) ID:67 C8
TAGGETS
TARGETTYPEVALUE ID:68 CA
TARGETTYPE ID:63 CA
TRACKUID ID:63 C5
EDITIONUID ID:63 C9
CHAPTERUID ID:63 C4
ATTACHMENTUID ID:63 C6
SIMPLETAG
TAGNAME ID:45 A3
TAGLANGUAGE ID:44 7A
TAGORIGINAL ID:44 84
TAGSTRING ID:44 87
TAGBINARY ID:44 85
A few common tags
TITLE
BPS
FPS