Extract VTT Subtitles from MKV with FFmpeg

This article provides a straightforward guide on how to extract a WebVTT (.vtt) subtitle track from an MKV video file using FFmpeg in a Linux environment. You will learn how to identify the correct subtitle stream, run the extraction command, and efficiently process multiple files at once using a simple bash loop.

Identify the Subtitle Stream

Before extracting the subtitles, you need to find out which stream index contains the subtitle track you want. MKV files often contain multiple audio, video, and subtitle tracks. You can inspect the file’s metadata by running the following command in your terminal:

ffmpeg -i input.mkv

Look through the output for lines labeled Stream #0:x, where x is a number. You are looking for a stream that specifies Subtitle. For example, you might see something like this:

Stream #0:2(eng): Subtitle: subrip (default)

In this case, the subtitle track is at index 2.

Extract the VTT Subtitle Track

Once you know the stream number, you can use FFmpeg to extract it and convert it to the VTT format. Use the -map flag to select the specific stream.

Assuming your subtitle stream is 0:2, run the following command:

ffmpeg -i input.mkv -map 0:2 output.vtt

Here is what each part of that command does:

Batch Extract Subtitles from Multiple MKV Files

If you have a directory full of MKV files and want to extract the first subtitle track (typically stream 0:s:0) from all of them, you can automate the process using a bash for loop:

for file in *.mkv; do
    ffmpeg -i "$file" -map 0:s:0 "${file%.mkv}.vtt"
done

This script loops through every MKV file in the current folder, selects the very first subtitle track available (0:s:0), and saves it as a VTT file matching the original video’s filename.