You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

#!/bin/bash
# Check if mkvpropedit is installed
if ! command -v mkvpropedit &> /dev/null; then
echo "Error: mkvpropedit not found. Please install mkvtoolnix."
exit 1
fi
# Ensure correct number of arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <mkv-file> <track-number>"
exit 1
fi
mkv_file="$1"
default_track="$2"
# Ensure the file exists
if [[ ! -f "$mkv_file" ]]; then
echo "Error: File '$mkv_file' not found."
exit 1
fi
# Get subtitle track IDs
subtitle_tracks=$(mkvmerge -i "$mkv_file" | grep 'subtitles' | awk -F ': ' '{print $1}' | awk '{print $3}')
if [[ -z "$subtitle_tracks" ]]; then
echo "No subtitle tracks found in '$mkv_file'."
exit 1
fi
# Remove default and forced flags from all subtitle tracks
for track_id in $subtitle_tracks; do
echo "Running: mkvpropedit \"$mkv_file\" --edit track:$track_id --set flag-default=0 --set flag-forced=0"
mkvpropedit "$mkv_file" --edit track:$track_id --set flag-default=0 --set flag-forced=0
done
# Set the specified track as default
echo "Running: mkvpropedit \"$mkv_file\" --edit track:$default_track --set flag-default=1"
mkvpropedit "$mkv_file" --edit track:$default_track --set flag-default=1
echo "Subtitle track $default_track set as default in '$mkv_file'."