How to Set Subtitle Language in FFmpeg
This guide explains how to set or change the language metadata code (such as ‘spa’ for Spanish or ‘jpn’ for Japanese) for a subtitle stream using FFmpeg. You will learn the precise command-line arguments needed to target specific subtitle streams and apply the correct ISO 639 language codes without re-encoding your video.
The Basic Syntax
To set the language of a subtitle stream, you use the
-metadata:s:s option. The syntax is broken down as
follows:
-metadata: Specifies that you want to change metadata.s:s:index: Targets a specific stream. The firstsstands for stream, the secondsstands for subtitle, andindexis the zero-based index of the subtitle stream (e.g.,0for the first subtitle stream,1for the second).language=code: Sets the language using the 3-letter ISO 639-2 code (e.g.,eng,spa,jpn,fra,deu).
Scenario 1: Changing Language on an Existing File
If you have a video file that already contains a subtitle stream, and
you want to change its language metadata to Spanish (spa)
without re-encoding the video or audio, use the following command:
ffmpeg -i input.mkv -map 0 -c copy -metadata:s:s:0 language=spa output.mkvCommand Breakdown:
-i input.mkv: Defines the input file.-map 0: Selects all streams (video, audio, and subtitles) from the input file to be included in the output.-c copy: Copies all streams directly without re-encoding, making the process extremely fast.-metadata:s:s:0 language=spa: Sets the language of the first subtitle stream (s:s:0) to Spanish (spa).
Scenario 2: Adding an External Subtitle and Setting its Language
If you are merging an external subtitle file (like an
.srt or .vtt file) into a video and want to
set its language to Japanese (jpn), use this command:
ffmpeg -i input.mp4 -i subtitle.srt -map 0 -map 1 -c copy -metadata:s:s:0 language=jpn output.mkvCommand Breakdown:
-i input.mp4 -i subtitle.srt: Imports both the video and the subtitle file.-map 0 -map 1: Maps all streams from the first input (video/audio) and the second input (subtitle).-metadata:s:s:0 language=jpn: Sets the language of the newly added subtitle stream to Japanese.
Handling Multiple Subtitle Streams
If your file has multiple subtitle streams and you want to label them differently, you can target each stream by its index:
ffmpeg -i input.mkv -map 0 -c copy -metadata:s:s:0 language=eng -metadata:s:s:1 language=fra output.mkvIn this example, the first subtitle stream (s:s:0) is
set to English (eng), and the second subtitle stream
(s:s:1) is set to French (fra).