全部博文(160)
分类: 其他平台
2015-05-29 00:35:15
有了上文我们经知道了MKV文件时长、音视频的类型、分辨率、采样率等基本信息,接下来就是音视频的数据了。
Clusters |
|
Element Name | L | EBML ID | Ma | Mu | Rng | Default | T | 1 | 2 | 3 | W | Description |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Cluster | ||||||||||||
Cluster | 1 | [1F][43][B6][75] | - | * | - | - | m | * | * | * | * | The lower level element containing the (monolithic) Block structure. |
Timecode | 2 | [E7] | * | - | - | - | u | * | * | * | * | Absolute timecode of the cluster (based on TimecodeScale). |
SilentTracks | 2 | [58][54] | - | - | - | - | m | * | * | * | The list of tracks that are not used in that part of the stream. It is useful when using overlay tracks on seeking. Then you should decide what track to use. | |
SilentTrackNumber | 3 | [58][D7] | - | * | - | - | u | * | * | * | One of the track number that are not used from now on in the stream. It could change later if not specified as silent in a further Cluster. | |
Position | 2 | [A7] | - | - | - | - | u | * | * | * | The of the Cluster in the segment (0 in live broadcast streams). It might help to resynchronise offset on damaged streams. | |
PrevSize | 2 | [AB] | - | - | - | - | u | * | * | * | * | Size of the previous Cluster, in octets. Can be useful for backward playing. |
SimpleBlock | 2 | [A3] | - | * | - | - | b | * | * | * | Similar to but without all the extra information, mostly used to reduced overhead when no extra feature is needed. (see ) | |
BlockGroup | 2 | [A0] | - | * | - | - | m | * | * | * | * | Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock. |
Block | 3 | [A1] | * | - | - | - | b | * | * | * | * | Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode. (see ) |
BlockVirtual | 3 | [A2] | - | - | - | - | b | A Block with no data. It must be stored in the stream at the place the real Block should be in display order. (see ) | ||||
BlockAdditions | 3 | [75][A1] | - | - | - | - | m | * | * | * | Contain additional blocks to complete the main one. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data. | |
BlockMore | 4 | [A6] | * | * | - | - | m | * | * | * | Contain the BlockAdditional and some parameters. | |
BlockAddID | 5 | [EE] | * | - | not 0 | 1 | u | * | * | * | An ID to identify the BlockAdditional level. | |
BlockAdditional | 5 | [A5] | * | - | - | - | b | * | * | * | Interpreted by the codec as it wishes (using the BlockAddID). | |
BlockDuration | 3 | [9B] | - | - | - | TrackDuration | u | * | * | * | * | The duration of the Block (based on TimecodeScale). This element is mandatory when DefaultDuration is set for the track (but can be omitted as other default values). When not written and with no DefaultDuration, the value is assumed to be the difference between the timecode of this Block and the timecode of the next Block in "display" order (not coding order). This element can be useful at the end of a Track (as there is not other Block available), or when there is a break in a track like for subtitle tracks. When set to 0 that means the frame is not a keyframe. |
ReferencePriority | 3 | [FA] | * | - | - | 0 | u | * | * | * | This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced. | |
ReferenceBlock | 3 | [FB] | - | * | - | - | i | * | * | * | * | Timecode of another frame used as a reference (ie: B or P frame). The timecode is relative to the block it's attached to. |
ReferenceVirtual | 3 | [FD] | - | - | - | - | i | Relative of the data that should be in position of the virtual block. | ||||
CodecState | 3 | [A4] | - | - | - | - | b | * | * | The new codec state to use. Data interpretation is private to the codec. This information should always be referenced by a seek entry. | ||
Slices | 3 | [8E] | - | - | - | - | m | * | * | * | * | Contains slices description. |
TimeSlice | 4 | [E8] | - | * | - | - | m | * | * | * | * | Contains extra time information about the data contained in the Block. While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback. |
LaceNumber | 5 | [CC] | - | - | - | 0 | u | * | * | * | * | The reverse number of the frame in the lace (0 is the last frame, 1 is the next to last, etc). While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback. |
FrameNumber | 5 | [CD] | - | - | - | 0 | u | The number of the frame to generate from this lace with this delay (allow you to generate many frames from the same Block/Frame). | ||||
BlockAdditionID | 5 | [CB] | - | - | - | 0 | u | The ID of the BlockAdditional element (0 is the main Block). | ||||
Delay | 5 | [CE] | - | - | - | 0 | u | The (scaled) delay to apply to the element. | ||||
SliceDuration | 5 | [CF] | - | - | - | 0 | u | The (scaled) duration to apply to the element. | ||||
ReferenceFrame | 3 | [C8] | - | - | - | - | m | DivX trick track extenstions | ||||
ReferenceOffset | 4 | [C9] | * | - | - | - | u | DivX trick track extenstions | ||||
ReferenceTimeCode | 4 | [CA] | * | - | - | - | u | DivX trick track extenstions | ||||
EncryptedBlock | 2 | [AF] | - | * | - | - | b | Similar to but the data inside the Block are Transformed (encrypt and/or signed). (see ) |
Cluster | ID = | [1F][43][B6][75] |
Block Header | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Offset | Player | Description | ||||||||||||||||||
0x00+ | must | Track Number (Track Entry). It is coded in EBML like form (1 octet if the value is < 0x80, 2 if < 0x4000, etc) (most significant bits set to increase the range). | ||||||||||||||||||
0x01+ | must | Timecode (relative to Cluster timecode, signed int16) | ||||||||||||||||||
0x03+ | - |
|
||||||||||||||||||
Lace (when lacing bit is set) | ||||||||||||||||||||
0x00 | must | Number of frames in the lace-1 (uint8) | ||||||||||||||||||
0x01 / 0xXX | must* | Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace). | ||||||||||||||||||
(possibly) Laced Data | ||||||||||||||||||||
0x00 | must | Consecutive laced frames |
将这个96034长度block 的数据转成NALU格式,然后加上从track部分中的CodecPrivate数据中解析出来的sps 和 pps 信息 保存到本地,应该就是1帧的264数据
用elecard 打开 果然是1帧I帧数据
按照这个套路,看看下一个
BlockGroup ID = A0 size = 0x2808
第一个block ID = A1 size = 0x2805(10245)
第1字节 表示Track Number =2 表示是track 2的数据,track是ac3 的音频。
第2-3字节表示Timecode = 0x0005;
In this case only the number of frames in the lace is saved, the size of each frame is deduced from the total size of the Block. For example, for 3 frames of 800 octets each :
Cueing Data 这部分内容其实是关键帧的index,如果没有关键帧的index的话,在做seek、快进快退的时候是十分困难的。你要逐个包去找。之前说过flv文件中官方没有做I帧index的规定。但是在民间已经做了补充。mkv官方有对index的规范。那就是Cueing Data
下面是结构图。
Cueing Data |
|
Cueing Data | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Cues | 1 | [1C][53][BB][6B] | - | - | - | - | m | * | * | * | * | A top-level element to speed seeking access. All entries are local to the segment. Should be mandatory for non . |
CuePoint | 2 | [BB] | * | * | - | - | m | * | * | * | * | Contains all information relative to a seek point in the segment. |
CueTime | 3 | [B3] | * | - | - | - | u | * | * | * | * | Absolute timecode according to the segment time base. |
CueTrackPositions | 3 | [B7] | * | * | - | - | m | * | * | * | * | Contain positions for different tracks corresponding to the timecode. |
CueTrack | 4 | [F7] | * | - | not 0 | - | u | * | * | * | * | The track for which a position is given. |
CueClusterPosition | 4 | [F1] | * | - | - | - | u | * | * | * | * | The of the Cluster containing the required Block. |
CueRelativePosition | 4 | [F0] | - | - | - | - | u | The relative position of the referenced block inside the cluster with 0 being the first possible position for an element inside that cluster. | ||||
CueDuration | 4 | [B2] | - | - | - | - | u | The duration of the block according to the segment time base. If missing the track's DefaultDuration does not apply and no duration information is available in terms of the cues. | ||||
CueBlockNumber | 4 | [53][78] | - | - | not 0 | 1 | u | * | * | * | * | Number of the Block in the specified Cluster. |
CueCodecState | 4 | [EA] | - | - | - | 0 | u | * | * | The of the Codec State corresponding to this Cue element. 0 means that the data is taken from the initial Track Entry. | ||
CueReference | 4 | [DB] | - | * | - | - | m | * | * | The Clusters containing the required referenced Blocks. | ||
CueRefTime | 5 | [96] | * | - | - | - | u | * | * | Timecode of the referenced Block. |
继续看上面的例子,我们找到了Cues 所在的位置。
ID = [1C][53][BB][6B] 表示Cues size = 0x7f
紧接着每个ID = 0xBB 就是一个CuePoint,图中的绿色框中的就是一个。 size = 0xC
CueTime ID = 0xB3 size = 1 data = 0;
CueTrackPositions ID=0xB7 size=7 data=0xf78101f18215ef
CueTrack ID=F7 size = 1 data = 1 表示这个位置的track num 值为1 针对这个流应该是video
CueClusterPosition ID = F1 size = 2 data = 15ef 位置是在0x15ef(5615) 相对于Segment
找到这个位置发现是第一个Clusters 上面章节分析了,这个族的video内容正好是关键帧。
按照这种方式 发现这个文件中共有8个cuepoint 信息
把这个文件中的264视频demux出来,用工具查看发现关键帧正好也是8个。
Level 0 |
|