Extract WebVTT Subtitles from WebM with FFmpeg

This guide provides a straightforward, step-by-step tutorial on how to extract WebVTT subtitle streams from a WebM video container using the FFmpeg command-line tool. You will learn how to identify the subtitle stream within your WebM file and run the precise commands needed to export it as an independent .vtt file.

Step 1: Identify the Subtitle Stream

Before extracting the subtitles, you must identify which stream inside the WebM container contains the WebVTT data. Run the following command in your terminal:

ffmpeg -i input.webm

Look at the console output for the “Stream” entries. You are looking for a line that resembles this:

Stream #0:2: Subtitle: webvtt

In this example, the subtitle stream is indexed as 0:2 (the third stream of the first input file) or represented generally as the first subtitle stream 0:s:0.

Step 2: Extract the WebVTT Stream

Once you know the stream index, use the -map flag to target the subtitle track and save it to a .vtt file.

Run this command to extract the first subtitle track:

ffmpeg -i input.webm -map 0:s:0 output.vtt

Command breakdown: * -i input.webm: Specifies the input WebM video file. * -map 0:s:0: Selects the first subtitle stream (s:0) from the first input file (0). * output.vtt: Specifies the name of your extracted WebVTT subtitle file.

Extracting Specific Streams (Multiple Subtitles)

If your WebM file contains multiple subtitle tracks (such as different languages), change the index number at the end of the -map argument.

Alternative Shortcut Method

If the WebM file only contains a single subtitle track, FFmpeg can automatically detect and extract it simply by matching the output file extension:

ffmpeg -i input.webm output.vtt