Set Default Audio Track in MKV with FFmpeg
This guide provides a quick overview and step-by-step instructions on how to set a specific audio track as the default in a multi-track MKV file using FFmpeg on Linux. When a video contains multiple audio languages or commentary tracks, media players look for a specific metadata flag to determine which one to play automatically. By utilizing FFmpeg’s stream mapping and metadata disposition tools, you can easily change this default target without re-encoding the video, saving both time and quality.
Step 1: Identify the Audio Stream Index
Before changing the default track, you need to know the index number of the audio stream you want to target. Run the following command to inspect your MKV file:
ffmpeg -i input.mkvLook at the output lines that start with Stream #0:. You
will see video streams, audio streams, and subtitles. Note the index of
the audio track you want to make the default (for example,
Stream #0:2 means the index is 2).
Step 2: Set the Default Flag
To set your chosen audio track as the default, you will use the
-disposition flag. The following command copies all video,
audio, and subtitle streams without re-encoding them
(-c copy), turns off the default flag for all audio
streams, and then turns it on specifically for your chosen stream.
Assuming you want stream index 2 to be the default audio track, run:
ffmpeg -i input.mkv -map 0 -c copy -disposition:a 0 -disposition:a:2 default output.mkvCommand Breakdown
-i input.mkv: Specifies the input file.-map 0: Ensures that all streams (video, all audio tracks, and subtitles) from the input file are included in the output file.-c copy: Copies all streams directly without re-encoding them, making the process incredibly fast and preserving original quality.-disposition:a 0: Clears the default flag from all audio streams. This prevents conflicts where multiple audio tracks are marked as default.-disposition:a:2 default: Explicitly sets the “default” flag for the audio stream at index 2 (which corresponds to the 3rd stream overall if counting from 0).output.mkv: The name of your new file with the corrected default audio track.
Verifying the Changes
Once the command finishes running, you can verify that the metadata was applied correctly by inspecting the new file:
ffmpeg -i output.mkvIn the stream layout output, you should now see
(default) next to the specific audio stream you targeted,
ensuring that media players like VLC or MPV will automatically select it
upon playback.