mkvextract -- 将 Matroska(tm) 文件中的轨道提取为另外的文件

Table of contents

1. 概要

mkvextract {模式} {源文件名} 选项 提取指令

2. 说明

This program extracts specific parts from a Matroska(tm) file to other useful formats. The first argument, mode, tells mkvextract(1) what to extract. Currently supported is the extraction of tracks, tags, attachments, chapters, CUE sheets, timecodes and cues. The second argument is the name of the source file. It must be a Matroska(tm) file. All following arguments are options and extraction specifications; both of which depend on the selected mode.

2.1. 通用选项

以下选项在所有模式下可用,本段落只讲一遍,不赘述。

Option Description
-f, --parse-fully

设置解析模式为 'full(完整)'。默认的解析模式不解析整个文件,而是使用元定位元素确定源文件中所需元素的位置。99% 的情况下这已经足够。但如果碰到不含元定位元素或者元定位元素损坏的文件,用户可能得考虑使用此模式。完整扫描文件可能要花费几分钟,而快速扫描只需要几秒钟。

--command-line-charset 字符集

设定在命令行给出的字符串的字符集,用于转为其他字符集。默认为系统当前区域设置中所给定的字符集。

--output-charset 字符集

设置输出的字符串应被转换到何种字符集。默认为系统当前区域设置中所给定的字符集。

-r, --redirect-output 文件名

将所有信息输出至文件 文件名 而不是在命令行显示。尽管该操作可以用输出重定向轻松实现,但在某些情况下还需要靠它:如当终端在写入文件之前重新解释(覆盖输出)时。将优先使用通过 --output-charset 设定的字符集。

--ui-language 语言代码

强制使用语言代码为 语言代码 的翻译(如 'de_DE' 对应德文翻译)。使用 LANG, LC_MESSAGESLC_ALL 这些环境变量更好。如果在 语言代码 处输入 'list',mkvextract(1) 将输出可用翻译列表。

--debug 主题

为特定功能开启调试。该选项仅对开发者有用。

--engage 功能

开启实验性功能。可用功能列表可通过 mkvextract --engage list 得到。这些功能在正常情况下不应该使用。

--gui-mode

Turns on GUI mode. In this mode specially-formatted lines may be output that can tell a controlling GUI what's happening. These messages follow the format '#GUI#message'. The message may be followed by key/value pairs as in '#GUI#message#key1=value1#key2=value2…'. Neither the messages nor the keys are ever translated and always output in English.

-v, --verbose

使输出信息更详尽,且每当读取到重要的 Matroska(tm) 元素时就将其显示。

-h, --help

显示用法信息并退出。

-V, --version

显示版本信息并退出。

--check-for-updates

联机下载 URL http://mkvtoolnix-releases.bunkus.org/latest-release.xml 以检查新版本。将以 键=值 的样式输出四行: 检索信息的 URL(键 version_check_url),当前运行的版本(键 running_version),最新版本号(键 available_version)及其下载 URL(键 download_url)。

若无更新版本可用,程序将以退出码 0 退出,若有更新版本可用,退出码为 1,若出现错误(如无法检索更新信息),退出码则为 2。

此选项仅当程序附带 libcurl 支持编译时可用。

@选项文件

从文件 选项文件 中读取额外的命令行参数。首个非空白字符为井号 ('#') 的行将被当作注释对待,在处理过程中将被忽略。各行开头与结尾的空白将被除去。各行必须恰好仅含一个选项。

有些字符可以转义,如当您需要使用 '#' 作为一个不是评论的行的开头。规则在关于转义文本的段落有描述。

命令行 'mkvextract tracks 源.mkv --raw 1:目标.raw' 可以转换为下面所示选项文件:

# 从 源.mkv 提取轨道
tracks
源.mkv
# 将轨道以原始数据的形式输出。
--raw
1:目标.raw

2.2. 轨道提取模式

Syntax: mkvextract tracks source-filename [options] TID1:dest-filename1 [TID2:dest-filename2 ...]

以下命令行在 'tracks' 轨道提取模式下对各轨道可用。它们应当在所应用到的轨道指令(参阅下文)之前出现。

Option Description
-c 字符集

设定下一个字幕轨应被转换为哪一字符集。仅当后面的轨道 ID 对应文本字幕轨时有效。默认为 UTF-8。

--blockadd 层级

只保留低于或等于此层级的 BlockAdditions 附加块。默认保留所有层级。 本选项仅影响特定类别的编解码器,如 WAVPACK4。

--cuesheet

mkvextract(1) 根据下一轨道的标签数据与章节信息提取出 CUE 表单,输出文件名为轨道的输出名后接 '.cue' 扩展名。

--raw

将原始数据提取为文件,输出文件的周围没有任何容器数据。 与 --fullraw 标记不同的是,此标记不会将 CodecPrivate 元素的内容写入输出文件。 此模式对所有 CodecIDs 有效,即使是 mkvextract(1) 不支持处理的,然而生成的文件可能无法使用。

--fullraw

提取原始数据,输出文件的周围没有任何容器数据。 如果轨道包含 CodecPrivate 编解码器私有元素,它的内容将先被写入文件。 此模式对所有 CodecIDs 有效,即使是 mkvextract(1) 不支持的那些,但是生成的文件可能无法使用。

TID:输出文件名

如果源文件中存在 ID 为 TID 的轨道,则将其提取为文件 输出文件名。本选项可多次给出。轨道 ID 与 mkvmerge(1)--identify 选项所输出的相同。

每个输出文件名只能用一次。但 RealAudio 与 RealVideo 轨道例外。如果您为不同轨道使用了同样的输出文件名,这些轨道将被存入同一个文件中。示例:

$ mkvextract tracks 输入.mkv 1:输出两条轨道.rm 2:输出两条轨道.rm

2.3. 标签提取模式

Syntax: mkvextract tags source-filename [options]

提取出的标签将被输出到命令行,除非输出被重定向(详情参见关于 输出重定向 的章节)。

2.4. 附件提取模式

Syntax: mkvextract attachments source-filename [options] AID1:outname1 [AID2:outname2 ...]

Option Description
AID:输出文件名

如果源文件中存在 ID 为 AID 的附件,则将其提取为文件 输出文件名。如果 输出文件名 处留空,将使用所用 Matroska(tm) 文件中的附件名称。本选项可多次给出。附件 ID 与 mkvmerge(1)--identify 选项所输出的相同。

2.5. 章节提取模式

Syntax: mkvextract chapters source-filename [options]

Option Description
-s, --simple

将章节信息以 OGM tools 所用的简单格式 (CHAPTER01=..., CHAPTER01NAME=...) 导出。此模式下部分信息将被废弃。默认以 XML 格式输出章节。

提取出的章节将被输出到命令行,除非输出被重定向(详情参见关于 输出重定向 的章节)。

2.6. Cue 表单提取模式

Syntax: mkvextract cuesheet source-filename [options]

提取出的 cue 表单将被输出到命令行,除非输出被重定向(详情参见关于 输出重定向 的章节)。

2.7. 时间码提取模式

Syntax: mkvextract timecodes_v2 source-filename [options] TID1:dest-filename1 [TID2:dest-filename2 ...]

提取出的时间码将被输出到命令行,除非输出被重定向(详情参见关于 输出重定向 的章节)。

Option Description
TID:输出文件名

如果源文件中存在 ID 为 TID 的轨道,则将其时间码提取为文件 输出文件名。本选项可多次给出。轨道 ID 与 mkvmerge(1)--identify 选项所输出的相同。

示例:

$ mkvextract timecodes_v2 输入.mkv 1:轨道1的时间码.txt 2:轨道2的时间码.txt

2.8. Cues extraction mode

Syntax: mkvextract cues source-filename [options] TID1:dest-filename1 [TID2:dest-filename2 ...]

Option Description
TID:dest-filename

Causes extraction of the cues for the track with the ID TID into the file outname if such a track exists in the source file. This option can be given multiple times. The track IDs are the same as the ones output by mkvmerge(1)'s --identify option and not the numbers contained in the CueTrack element.

The format output is a simple text format: one line per CuePoint element with key=value pairs. If an optional element is not present in a CuePoint (e.g. CueDuration) then a dash will be output as the value.

示例:

timecode=00:00:13.305000000 duration=- cluster_position=757741 relative_position=11

The possible keys are:

Option Description
timecode

The cue point's timecode with nanosecond precision. The format is HH:MM:SS.nnnnnnnnn. This element is always set.

duration

The cue point's duration with nanosecond precision. The format is HH:MM:SS.nnnnnnnnn.

cluster_position

The absolute position in bytes inside the Matroska(tm) file where the cluster containing the referenced element starts.

Note:

Inside the Matroska(tm) file the CueClusterPosition is relative to the segment's data start offset. The value output by mkvextract(1)'s cue extraction mode, however, contains that offset already and is an absolute offset from the beginning of the file.

relative_position

The relative position in bytes inside the cluster where the BlockGroup or SimpleBlock element the cue point refers to starts.

Note:

Inside the Matroska(tm) file the CueRelativePosition is relative to the cluster's data start offset. The value output by mkvextract(1)'s cue extraction mode, however, is relative to the cluster's ID. The absolute position inside the file can be calculated by adding cluster_position and relative_position.

示例:

$ mkvextract cues input.mkv 1:cues-track1.txt 2:cues-track2.txt

3. 输出重定向

有些提取模式会使 mkvextract(1) 将提取出的数据输出到命令行。通常有两种方法将数据写入文件:一种由 shell 提供,另一种由 mkvextract(1) 自身提供。

shell 的报告重定向功能可以通过在命令行后追加 '> 输出文件名.扩展名' 命令实现。示例:

$ mkvextract tags 源.mkv > 标签.xml

mkvextract(1) 自身的重定向功能可通过 --redirect-output 选项唤出。示例:

$ mkvextract tags 源.mkv --redirect-output 标签.xml

Note:

在 Windows 平台上您应当使用 --redirect-output 选项,因为 cmd.exe 有时会在写入文件之前对特殊字符进行转义,导致输出文件损坏。

4. 文本文件与字符集转换

For an in-depth discussion about how all tools in the MKVToolNix suite handle character set conversions, input/output encoding, command line encoding and console encoding please see the identically-named section in the mkvmerge(1) man page.

5. 输出文件格式

输出文件的格式取决于轨道的类型,而不是输出文件名的扩展名。目前支持以下轨道类型:

Option Description
V_MPEG4/ISO/AVC

H.264 / AVC 视频轨将被输出为 H.264 基本流,可以使用如 GPAC(tm) 工具包中的 MP4Box(tm) 作进一步处理。

V_MS/VFW/FOURCC

使用此 CodecIDFPS 恒定的视频轨将被输出为 AVI 文件。

V_REAL/*

RealVideo(tm) 轨道将被输出为 RealMedia(tm) 文件。

V_THEORA

Theora(tm) 流将以 Ogg(tm) 为容器输出

V_VP8, V_VP9

VP8 / VP9 tracks are written to IVF files.

A_MPEG/L2

MPEG-1 Audio Layer II 流将提取为原始的 MP2 文件。

A_MPEG/L3, A_AC3

这些将被输出为原始的 MP3AC3 文件。

A_PCM/INT/LIT

原始 PCM 数据将被输出为 WAV 文件。

A_AAC/MPEG2/*, A_AAC/MPEG4/*, A_AAC

所有 AAC 文件将被输出为 AAC 文件,其中数据包前有 ADTS 头。ADTS 头将不含反增强字段(deprecated emphasis field)。

A_VORBIS

Vorbis 音频将被输出为 OggVorbis(tm) 文件。

A_REAL/*

RealAudio(tm) 轨道将被输出为 RealMedia(tm) 文件。

A_TTA1

TrueAudio(tm) 轨道将被输出为 TTA 文件。请注意,由于 Matroska(tm) 时间码的精度限制,解开来的文件的头部有两个字段不同:data_length (文件的总采样数) 与 CRC

A_ALAC

ALAC 轨道将输出为 CAF 文件。

A_FLAC

FLAC 轨道将输出为原始的 FLAC 文件。

A_WAVPACK4

WavPack(tm) 轨道将输出为 WV 文件。

A_OPUS

Opus(tm) tracks are written to OggOpus(tm) files.

S_TEXT/UTF8

简单的文本字幕将被输出为 SRT 文件。

S_TEXT/SSA, S_TEXT/ASS

SSAASS 文本字幕将分别被输出为 SSA/ASS 文件。

S_KATE

Kate(tm) 流将以 Ogg(tm) 为容器输出。

S_VOBSUB

VobSub(tm) 字幕将输出为 SUB 文件及相应的索引文件(后缀为 IDX)。

S_TEXT/USF

USF 文本字幕将输出为 USF 文件。

S_HDMV/PGS

PGS 字幕将输出为 SUP 文件。

标签

标签将被转换为 XML 格式。此格式与 mkvmerge(1) 所支持读取的标签格式相同。

附件

附件将被以原样输出。不会进行任何转换。

章节

章节将被转换为 XML 格式。此格式与 mkvmerge(1) 所支持读取的章节格式相同。您也可以选择输出精简的简单 OGM 格式。

时间码

时间码会先被排序,然后以 timecode v2 格式文件输出,该文件适用于 mkvmerge(1)。不支持提取为其他格式 (v1, v3 或 v4)。

6. 退出代码

mkvextract(1) 退出时会返回以下三个退出代码中的一个:

7. 文本中特殊字符的转义

有时文本中的特殊字符必须或应该转义。转义规则很简单: 用反斜杠后接一字符替换需要转义的各字符。

规则为: ' ' (空格) 变为 '\s'、'"' (双引号) 变为 '\2'、':' 变为 '\c'、'#' 变为 '\h',而 '\' (单个反斜杠) 自己则变为 '\\'。

8. 环境变量

mkvextract(1) 使用决定系统区域设置的默认变量 (如 LANGLC_* 族)。其他变量包括:

Option Description
MKVEXTRACT_DEBUG, MKVTOOLNIX_DEBUG and its short form MTX_DEBUG

内容将被当作通过 --debug 选项传递的参数对待。

MKVEXTRACT_ENGAGE, MKVTOOLNIX_ENGAGE and its short form MTX_ENGAGE

内容将被当作通过 --engage 选项传递的参数对待。

MKVEXTRACT_OPTIONS, MKVTOOLNIX_OPTIONS and its short form MTX_OPTIONS

内容将在空白处切割。最终得到的字符串部分将按命令行选项的格式处理。如果您需要传递特殊字符 (如空白) 则需要转义 (参见关于转义文本中特殊字符的段落)。

9. 参阅

mkvmerge(1), mkvinfo(1), mkvpropedit(1), mkvtoolnix-gui(1)

10. 网络

最新版本总可以在 MKVToolNix 主页 找到。