Embed WebVTT Subtitles in WebM Using FFmpeg

This guide demonstrates how to embed WebVTT (.vtt) subtitle tracks directly into a WebM video container using FFmpeg. You will learn the precise command-line syntax required to merge your video, audio, and subtitle streams into a single, highly compatible WebM file without re-encoding your video and audio tracks.

The Basic Command

To mux a WebVTT file into an existing WebM video, use the following FFmpeg command:

ffmpeg -i input.webm -i subtitles.vtt -map 0 -map 1 -c:v copy -c:a copy -c:s webvtt output.webm

Parameter Breakdown

  • -i input.webm: Specifies the input video file.
  • -i subtitles.vtt: Specifies the input WebVTT subtitle file.
  • -map 0: Maps all streams (video and audio) from the first input file (input.webm).
  • -map 1: Maps the subtitle stream from the second input file (subtitles.vtt).
  • -c:v copy and -c:a copy: Copies the video and audio streams directly without re-encoding, preserving the original quality and completing the process almost instantly.
  • -c:s webvtt: Specifies the WebVTT encoder to format the subtitles correctly inside the WebM container.

Embedding Multiple Subtitle Languages

You can embed multiple WebVTT files for different languages into a single WebM container. Use the metadata flags to label each language track so media players can identify them properly:

ffmpeg -i input.webm -i english.vtt -i spanish.vtt \
-map 0 -map 1 -map 2 \
-c:v copy -c:a copy \
-c:s webvtt \
-metadata:s:s:0 language=eng -metadata:s:s:0 title="English" \
-metadata:s:s:1 language=spa -metadata:s:s:1 title="Spanish" \
output.webm

How the Metadata Mapping Works:

  • -map 0 -map 1 -map 2: Tells FFmpeg to include the video/audio (0), the English subtitles (1), and the Spanish subtitles (2).
  • -metadata:s:s:0 language=eng: Targets the first subtitle stream (index 0) and sets its language metadata to English.
  • -metadata:s:s:1 title="Spanish": Targets the second subtitle stream (index 1) and sets its user-facing menu title to "Spanish".