MKV 文件格式学习

本贴最后更新于 1199 天前,其中的信息可能已经时异事殊

简介

MKV 是开源的多媒体封装格式,是 Matroska 媒体系统中的一种文件格式。

优势

Matroska 媒体格式最大的优势是,通过 EBML 框架,可以支持所有已知的音视频格式,同时支持未来新出现的音视频格式。

EBML Extensible Binary Meta Language 框架,允许在向后兼容性的基础上,增加容器格式的新特征。

常见的扩展名

常见扩展名有:

播放器和解码器

常见的播放器,只要安装了 Matroska 解码器,即可以播放 mkv 文件。

特点

EBML

Document 由 EBML Element 组成,EBML Element 定义为:

typedef struct {
    vint ID;            // EBML-ID
    vint size;          // size of element
    char data[size];    // data
} EBML_ELEMENT;

其中 vint (Unsigned Integer Values of Variable Length) 是可变长度类型。

MKV 结构

Meta Seek Information

Segment Information

Track

Chapters

Clusters

Cueing Data

Attachment

Tagging

使用工具查看 MKV 结构

安装 mkvtoolnix,执行

mkvinfo file.mkv

使用测试文件 https://www.sample-videos.com/video/mkv/240/big_buck_bunny_240p_1mb.mkv

结果为

+ EBML head
|+ EBML version: 1
|+ EBML read version: 1
|+ EBML maximum ID length: 4
|+ EBML maximum size length: 8
|+ Doc type: matroska
|+ Doc type version: 2
|+ Doc type read version: 2
+ Segment, size 1055662
|+ Seek head (subentries will be skipped)
|+ EbmlVoid (size: 148)
|+ Segment information
| + Timestamp scale: 1000000
| + Multiplexing application: Lavf53.24.2
| + Writing application: Lavf53.24.2
| + Segment UID: 0xd0 0x73 0xe6 0xe9 0x83 0x1c 0x2b 0x98 0x86 0xa0 0x51 0xfd 0x4d 0x28 0x24 0xe6
| + Duration: 9.818s (00:00:09.818)
|+ Segment tracks
| + A track
|  + Track number: 1 (track ID for mkvmerge & mkvextract: 0)
|  + Track UID: 1
|  + Lacing flag: 0
|  + Language: und
|  + Default flag: 1
|  + Codec ID: V_MPEG4/ISO/AVC
|  + Track type: video
|  + Default duration: 40.000ms (25.000 frames/fields per second for a video track)
|  + Video track
|   + Pixel width: 320
|   + Pixel height: 240
|   + Display width: 320
|   + Display height: 240
|   + Display unit: 3 (aspect ratio)
|  + CodecPrivate, length 37 (h.264 profile: Main @L2.0)
| + A track
|  + Track number: 2 (track ID for mkvmerge & mkvextract: 1)
|  + Track UID: 2
|  + Lacing flag: 0
|  + Language: und
|  + Default flag: 1
|  + Codec ID: A_AAC
|  + Track type: audio
|  + Audio track
|   + Channels: 6
|   + Sampling frequency: 48000
|  + CodecPrivate, length 2
|+ Tags
| + Tag
|  + Targets
|  + Simple
|   + Name: ENCODER
|   + String: Lavf53.24.2
|+ Cluster

使用 Java 查看 MKV 结构

依赖

		<dependency>
			<groupId>com.github.kokorin</groupId>
			<artifactId>jebml</artifactId>
			<version>2.3.1</version>
		</dependency>

调用

		fileStr = "big_buck_bunny_240p_1mb.mkv";
		DataSource source = new FileDataSource(fileStr);
		MatroskaFile file = new MatroskaFile(source);
		file.readFile();
		System.out.println(file.getReport());

结果

MatroskaFile report
Infomation Segment 
	Segment Title: null
	Segment Date: null
	Muxing App : Lavf53.24.2
	Writing App : Lavf53.24.2
	Duration : 9.818sec 
	TimecodeScale : 1000000
Track Count: 2
	Track 0
		TrackNo: 1
		TrackUID: 1
		TrackType: VIDEO
		DefaultDuration: 40000000
		Name: unnamed
		Language: und
		CodecID: V_MPEG4/ISO/AVC
		CodecPrivate: 37 byte(s)
		PixelWidth: 320
		PixelHeight: 240
		DisplayWidth: 320
		DisplayHeight: 240
	Track 1
		TrackNo: 2
		TrackUID: 2
		TrackType: AUDIO
		DefaultDuration: 0
		Name: unnamed
		Language: und
		CodecID: A_AAC
		CodecPrivate: 2 byte(s)
		SamplingFrequency: 48000.0
		Channels: 6
Tag Count: 1
	Tag Entry 
		SimpleTag
			Name: ENCODER
			Value: Lavf53.24.2
End report

参考

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...