Scroll to navigation

MKVEXTRACT(1) 使用者命令 MKVEXTRACT(1)

名称

mkvextract - 將 Matroska 軌道檔案擷取至其他檔案

概要

mkvextract {輸入檔名} {模式1} [選項] [擷取規格1] [模式2] [選項] [擷取規格2] [...]

摘要說明

此程式從 Matroska 檔中提取特定部分到其他有用的格式。第一個參數是原始檔案的名稱,該檔必須是 Matroska 檔。

所有其他引數可切換至特定擷取模式,變更目前使用模式的選項,或指定要擷取那些內容至哪個檔案中。可在 mkvextract 同一次啟動中使用多個模式,允許一次擷取多個內容。大多數選項只能在特定模式下使用,只有少數選項適用於所有模式。

目前支援軌道 tracks 軌道, tags 標籤, attachments 附件, chapters 章節, CUE sheets CUE 工作表, timestamps 時間戳記 與 cues的擷取。

一般選項

以下選項在所有模式下都可用,本節中僅介紹一次。

-f, --parse-fully

將剖析模式設為 '完整' 。預設模式不會剖析完整檔案,而是使用變換定位元件尋找原始檔案所需的元件。在 99% 情形足以夠用。但對於不包含變換定位元件或受損的檔案來說,使用者很可能需要使用此模式。完整檔案掃描會耗費較久的時間,而快速掃描只需要幾秒鐘。

--command-line-charset 字元集

設定在命令列顯示的字串字元集,以轉換為其他字元集。預設為目前系統所在位置指定的字元集。

--output-charset 字元集

設定要轉換為輸出字串的字元集。預設為目前系統所在位置指定的字元集。

-r, --redirect-output 檔名

將所有訊息寫入到檔案 檔名 而不是命令列。儘管使用輸出重新導向可以輕鬆完成此操作,但在某些情況下需要使用此選項: 當終端在將輸出寫入文件之前重新解釋(覆蓋)輸出時。 優先使用通過 --output-charset 設定字元集。

--flush-on-close

關閉已開啟寫入的檔案時,告訴程式清理所有在記憶體中的資料。這可以防止因斷電造成的資料遺失或避免作業系統或驅動程式造成的某些問題。缺點是執行合併工具會花費較久個時間,因為 mkvmerge 需要等待所有資料已寫入至儲存空間後,才會結束。請參閱 MKVToolNix 錯誤追蹤上的 #2469 和 #2480 問題,以便深入瞭解其優缺點。

--ui-language 語言碼

強制使用語言 編碼 對應的的翻譯(例如 'zh_TW' 為臺灣正體中文翻譯)。 在編碼欄位中輸入'list' 讓程式輸出時使用可用的對應翻譯清單。

--abort-on-warnings

發出第一個警告後,終止程式。程式的結束碼為 1 。

--debug 主題

針對特定功能開啟除錯。此選項適用於開發者。

--engage 功能

開啟實驗中功能。 透過mkvextract --engage list啟用可用的列表。這些功能不會在正常情況下使用。

--gui-mode

開啟 GUI 模式。在這種模式中,可能會輸出特殊格式的行數,可以呈現控制的 GUI 發生什麼事。這些訊息會以 '#GUI#訊息'呈現。訊息可能包含機碼/值,例如 '#GUI#訊息#機碼1=值1#機碼2=值2...'。 無論是訊息或是機碼都不會轉為譯文,而且永遠使用 *英語* 輸出。

-v, --verbose

輸出時盡量詳細,並在讀取時顯示所有 Matroska 重要的元件。

-h, --help

顯示使用方式並退出。

-V, --version

顯示版本資訊並離開。

@options-file.json

檔案選項檔讀取其他命令列引數。有關此類檔案支援格式的完整說明,請參閱 mkvmerge(1) 文件中的 "選項檔案" 章節。

軌道擷取模式

語法: mkvextract 原始檔名 tracks [選項] TID1:輸出檔名1 [TID2:輸出檔名2 ...]

以下命令列選項可用於 'tracks' 提取模式下的每個軌道。 這些命令須在應該所套用到的軌道指令(請見下文)前出現。

-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 input.mkv tracks 0:video.h264 2:output-two-vobsub-tracks.idx 3:output-two-vobsub-tracks.idx

附件擷取模式

語法: mkvextract 原始檔名 attachments [選項] AID1:輸出檔名1 [AID2:輸出檔名2 ...]

AID:輸出檔名

如果原始檔案中存在 ID 為 AID 的附件軌道,會將擷取為 輸出檔名 。假設 輸出檔名 保留空白,那麼將會使用原始 Matroska 檔案中的附件名稱。此選項可多次使用。此選項可多次使用。附件 ID 與 mkvmerge(1)--identify 選項輸出的相同。

章節擷取模式

語法: mkvextract 原始檔名 chapters [選項] 輸出檔名.xml

-s, --simple

用 OGM 工具的簡易格式來匯出章節資訊 (CHAPTER01=..., CHAPTER01NAME=...)。 在此模式中,將會丟棄部分資訊。預設是以 XML 格式輸出章節。

--simple-language 語言

如果啟用簡易模式, mkvextract(1) 即使單一章節單元包含一個以上的章節名稱,每個章節單元只會輸出單一項目。在預設情況下,無論任何語言, mkvextract(1) 都將會使用找到的第一個名稱。

使用此選項,當單元包含一個以上章節名稱時,允許使用者決定使用哪一個章節名稱作為輸出使用。 語言 參數必須為 ISO 639-1 或 ISO 639-2 編碼。

章節將寫入指定輸出檔案。預設情況下,會使用 mkvmerge(1) 可識別的 XML 格式。如果檔案中沒有找到任何章節,將不會建立輸出檔案。

標籤擷取模式

語法: mkvextract 原始檔名 tags [選項] 輸出檔名.xml

標籤將寫入指定輸出檔案。預設情況下,會使用 mkvmerge(1) 可識別的 XML 格式。如果檔案中沒有找到任何標籤,將不會建立輸出檔案。

Cue 工作表擷取模式

語法: mkvextract 原始檔名 cuesheet [選項] 輸出檔名.cue

CUE 表單將寫入指定輸出檔案。如果檔案中沒有找到任何章節或標籤,將不會建立輸出檔案。

時間戳記擷取模式

語法: mkvextract 原始檔名 timestamps_v2 [選項] TID1:輸出檔名1 [TID2:輸出檔名2 ...]

TID:輸出檔名

如果原始檔案中存在 ID 為 TID 的時間戳記軌道,會將擷取為 輸出檔名 。此選項可多次使用。此選項可多次使用。軌道 ID 與 mkvmerge(1)--identify 選項輸出的相同。

範例:

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

Cue 擷取模式

語法: mkvextract 原始檔名 cues [選項] TID1:輸出檔名1 [TID2:輸出檔名2 ...]

TID:輸出檔名

如果原始檔案中存在 ID 為 TID 的 CUE 軌道,會將擷取為 輸出檔名 。此選項可多次使用。此選項可多次使用。附件 ID 與 mkvmerge(1)--identify 選項輸出的相同,且不會包含 CueTrack 元件的數字。

輸出的格式為簡易文字格式: 每行對應一組 CuePoint 元件與 機碼=值。當選用的元素不存在於 CuePoint 時(例如 CueDuration) ,將會以短破折號(虛線)作為輸出值。

範例:

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

可使用的機碼如下:

timestamp

CUE 點的時間戳記( timestamp)具有奈秒的精準度。格式為 HH:MM:SS.nnnnnnnnn。 此元件為必要設定。

duration

CUE 點的時間長度(duration)具有奈秒的精準度。格式為 HH:MM:SS.nnnnnnnnn。

cluster_position

包含引用元件的叢集起始的 Matroska 檔案內位元組的絕對位置。


注意
Matroska 檔案中的 CueClusterPosition 相對於剪輯資訊資料的起始偏移。但由 mkvextract(1) CUE 擷取模式輸出的值已經包含該偏移,並且是與文件開頭的絕對偏移。

relative_position

CUE 點引用的 BlockGroup 或 SimpleBlock 元件在叢集起始內以位元組為單位的相對位置。


注意
Matroska 檔案中的 CueRelativePosition 是相對於叢集資料起始的偏移。但 mkvextract(1) 的 CUE 擷取模式所輸出的值,是相對於叢集的 ID 。可通過新增與新增檔案計算檔案內的 cluster_position 和 relative_position。

範例:

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

範例

同時擷取章節與標籤並依照各自的 XML 格式儲存:

$ mkvextract movie.mkv chapters movie-chapters.xml tags movie-tags.xml

同時擷取數個軌道與各自對應的時間戳記:

$ mkvextract "Another Movie.mkv" tracks 0:video.h265 "1:main audio.aac" "2:director's comments.aac" timestamps_v2 "0:timestamps video.txt" "1:timestamps main audio.txt" "2:timestamps director's comments.txt"

擷取 Ogg/OGM 格式的章節,然後將文字字幕軌道重新編碼到另一個字元集:

$ mkvextract "My Movie.mkv" chapters --simple "My Chapters.txt" tracks -c MS-ANSI "2:My Subtitles.srt"

文字檔案與字元集轉換

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.

檔案輸出格式

The decision about the output format is based on the track type, not on the extension used for the output file name. The following track types are supported at the moment:

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

All AAC files will be written into an AAC file with ADTS headers before each packet. The ADTS headers will not contain the deprecated emphasis field.

A_AC3, A_EAC3

這將會擷取為 raw AC-3 檔案。

A_ALAC

ALAC 軌道將寫入成 CAF 檔案。

A_DTS

這將會擷取為 raw DTS 檔案。

A_FLAC

FLAC 軌道將寫入成原始 FLAC 檔案。

A_MPEG/L2

MPEG-1 音層 II 串流將會擷取為原始的 MP2 檔案。

A_MPEG/L3

這將會擷取為 raw MP3 檔案。

A_OPUS

Opus 軌道將寫入成 OggOpus 檔案。

A_PCM/INT/LIT, A_PCM/INT/BIG

Raw PCM data will be written to a WAV file. Big-endian integer data will be converted to little-endian data in the process.

A_REAL/*

RealAudio 軌道將寫入成 RealMedia 檔案。

A_TRUEHD, A_MLP

這將會擷取為 raw TrueHD/MLP 檔案。

A_TTA1

TrueAudio tracks are written to TTA files. Please note that due to Matroska's limited timestamp precision the extracted file's header will be different regarding two fields: data_length (the total number of samples in the file) and the CRC.

A_VORBIS

Vorbis 音訊將會以 OggVorbis 寫入檔案。

A_WAVPACK4

WavPack 軌道將寫入成 WV 檔案。

S_HDMV/PGS

PGS 字幕將會以 SUP 寫入檔案。

S_HDMV/TEXTST

TextST subtitles will be written as a special file format invented for mkvmerge(1) and mkvextract(1).

S_KATE

Kate streams will be written within an Ogg container.

S_TEXT/SSA, S_TEXT/ASS, S_SSA, S_ASS

SSA 與 ASS 純文字字幕將會分別以 SSA/ASS 寫入檔案。

S_TEXT/UTF8, S_TEXT/ASCII

簡易純文字字幕將會以 SRT 寫入檔案。

S_VOBSUB

VobSub subtitles will be written as SUB files along with the respective index files, as IDX files.

S_TEXT/USF

USF 純文字字幕將會以 USF 寫入檔案。

S_TEXT/WEBVTT

WebVTT 純文字字幕將會以 WebVTT 寫入檔案。

V_MPEG1, V_MPEG2

MPEG-1 and MPEG-2 video tracks will be written as MPEG elementary streams.

V_MPEG4/ISO/AVC

H.264 / AVC video tracks are written to H.264 elementary streams which can be processed further with e.g. MP4Box from the GPAC package.

V_MPEG4/ISO/HEVC

H.265 / HEVC video tracks are written to H.265 elementary streams which can be processed further with e.g. MP4Box from the GPAC package.

V_MS/VFW/FOURCC

Fixed FPS video tracks with this CodecID are written to AVI files.

V_REAL/*

RealVideo 軌道將寫入成 RealMedia 檔案。

V_THEORA

Theora streams will be written within an Ogg container

V_VP8, V_VP9

VP8 / VP9 軌道將寫入成 IVF 檔案。

Tags

Tags are converted to a XML format. This format is the same that mkvmerge(1) supports for reading tags.

Attachments

Attachments are written to the output file as they are. No conversion whatsoever is done.

Chapters

Chapters are converted to a XML format. This format is the same that mkvmerge(1) supports for reading chapters. Alternatively a stripped-down version can be output in the simple OGM style format.

Timestamps

Timestamps are first sorted and then output as a timestamp v2 format compliant file ready to be fed to mkvmerge(1). The extraction to other formats (v1, v3 and v4) is not supported.

結束代碼

mkvextract(1) exits with one of three exit codes:

0 -- This exit code means that extraction has completed successfully.

1 -- In this case mkvextract(1) has output at least one warning, but extraction did continue. A warning is prefixed with the text 'Warning:'. Depending on the issues involved the resulting files might be ok or not. The user is urged to check both the warning and the resulting files.

2 -- This exit code is used after an error occurred. mkvextract(1) aborts right after outputting the error message. Error messages range from wrong command line arguments over read/write errors to broken files.

環境變數

mkvextract(1) uses the default variables that determine the system's locale (e.g. LANG and the LC_* family). Additional variables:

MKVEXTRACT_DEBUG, MKVTOOLNIX_DEBUG 與其縮寫 MTX_DEBUG

The content is treated as if it had been passed via the --debug option.

MKVEXTRACT_ENGAGE, MKVTOOLNIX_ENGAGE 與其縮寫 MTX_ENGAGE

The content is treated as if it had been passed via the --engage option.

參閱

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

網路

The latest version can always be found at the MKVToolNix homepage[1].

作者

Moritz Bunkus <moritz@bunkus.org>

開發人員

备注

1.
the MKVToolNix homepage
2021-01-04 MKVToolNix 52.0.0