Renaming the video or audio track inside an MKV container is possible using mkvmerge
. The --track-name
option allows you to set a custom name for any track (audio, video, or subtitle) in the container.
Here’s how you can rename a track within an MKV file:
Step 1: Identify Track Information
First, list the tracks to find the IDs and determine which track you want to rename:
mkvmerge -i input.mkv
Example output:
File 'input.mkv': container: Matroska
Track ID 0: video (V_MPEG4/ISO/AVC)
Track ID 1: audio (A_AC3) [English]
Track ID 2: audio (A_AAC) [French]
Track ID 3: subtitles (S_TEXT/UTF8) [French]
Step 2: Rename Tracks
Use the --track-name
option to rename a specific track by its ID. For example:
mkvmerge -o output.mkv \
--track-name 1:"English Audio" \
--track-name 2:"French Commentary" \
input.mkv
Explanation:
--track-name 1:"English Audio"
: Renames track ID1
(the English audio track) to “English Audio”.--track-name 2:"French Commentary"
: Renames track ID2
(the French audio track) to “French Commentary”.-o output.mkv
: Specifies the output file.
Automate Renaming Tracks Based on Language
If you want to automatically rename tracks based on their language, you can use a script.
Bash Script Example
#!/bin/bash
# Directory to scan (default: current directory)
SEARCH_DIR="${1:-.}"
# Function to rename tracks
rename_tracks() {
local file="$1"
# Temporary file for mkvmerge commands
local temp_file="temp.mkv"
# Create mkvmerge options dynamically
options=""
while IFS= read -r line; do
if [[ "$line" =~ Track\ ID\ ([0-9]+):.+language:\ ([a-z]{3}) ]]; then
track_id="${BASH_REMATCH[1]}"
lang="${BASH_REMATCH[2]}"
options+="--track-name $track_id:\"${lang^} Track\" "
fi
done < <(mkvmerge -i "$file")
# Apply the renaming
if [[ -n "$options" ]]; then
eval "mkvmerge -o \"$temp_file\" $options \"$file\""
mv "$temp_file" "$file"
echo "Renamed tracks in: $file"
fi
}
# Process files recursively
find "$SEARCH_DIR" -type f -name "*.mkv" | while read -r file; do
rename_tracks "$file"
done
How to Use:
- Save the script as
rename_tracks.sh
. - Make it executable:
chmod +x rename_tracks.sh
- Run it in the directory containing MKV files:
./rename_tracks.sh /path/to/directory
This script will:
- Scan each MKV file in the directory and subdirectories.
- Rename tracks based on their language (e.g., a track with
language: eng
becomes “Eng Track”).