Set Default and Forced Subtitles in MKV using FFmpeg
Managing subtitle tracks in MKV containers is essential for a seamless media playback experience. This article provides a straightforward, step-by-step guide on how to use the powerful command-line tool FFmpeg to set the “default” and “forced” flags on subtitle tracks within an MKV file, ensuring your media player displays the correct subtitles automatically without manual configuration.
Understanding the Flags
- Default Flag (
default): Tells the media player to automatically play this subtitle track if the player’s language settings match or if no other preference is specified. - Forced Flag (
forced): Tells the media player to play this track regardless of user preferences. This is typically used for translating foreign language parts in an otherwise native-language film (e.g., when alien languages are spoken in a sci-fi movie).
Step 1: Identify the Subtitle Stream Index
Before modifying the file, you must identify which subtitle stream you want to target. Run the following command to view the streams in your MKV file:
ffmpeg -i input.mkvLook at the output for lines marked with Subtitle.
FFmpeg indexes streams starting from 0. Subtitle streams
are referred to as s:0 (first subtitle track),
s:1 (second subtitle track), and so on.
Step 2: Use the
-disposition Option
To change subtitle flags without re-encoding your video and audio,
use the -disposition option combined with
-c copy.
Set a Subtitle Track as Default
To make the first subtitle track (s:0) the default track
and copy all other streams untouched:
ffmpeg -i input.mkv -map 0 -c copy -disposition:s:0 default output.mkvSet a Subtitle Track as Forced
To make the first subtitle track (s:0) a forced
track:
ffmpeg -i input.mkv -map 0 -c copy -disposition:s:0 forced output.mkvSet a Subtitle Track as Both Default and Forced
To set both flags on the first subtitle track:
ffmpeg -i input.mkv -map 0 -c copy -disposition:s:0 default+forced output.mkvStep 3: Clearing Flags on Other Tracks
Media players can get confused if multiple tracks are marked as
default. To set the first track (s:0) as default while
explicitly stripping the default flag from the second track
(s:1), use:
ffmpeg -i input.mkv -map 0 -c copy -disposition:s:0 default -disposition:s:1 0 output.mkvSetting the disposition value to 0 disables all flags
for that specific stream.