Created
September 30, 2024 12:21
-
-
Save dmd/20e61de1610ff75471e0cc5a1c2894ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if a file is provided | |
if [ $# -eq 0 ]; then | |
echo "Please provide an MKV file as an argument." | |
exit 1 | |
fi | |
input_file="$1" | |
# Check if the file exists | |
if [ ! -f "$input_file" ]; then | |
echo "File not found: $input_file" | |
exit 1 | |
fi | |
# Get the audio tracks information | |
audio_tracks=$(mkvmerge -J "$input_file" | jq -r '.tracks[] | select(.type=="audio") | {id: .id, properties: .properties}') | |
# Find the English audio track | |
english_track=$(echo "$audio_tracks" | jq -r 'select(.properties.language=="eng") | .id') | |
if [ -z "$english_track" ]; then | |
echo "No English audio track found." | |
exit 1 | |
fi | |
# Prepare the mkvpropedit command | |
command="mkvpropedit \"$input_file\"" | |
# Set all audio tracks to not default | |
while read -r track_id; do | |
command+=" --edit track:a$track_id --set flag-default=0" | |
done < <(echo "$audio_tracks" | jq -r '.id') | |
# Set the English track to default | |
command+=" --edit track:a$english_track --set flag-default=1" | |
# Execute the command | |
echo "$command" | |
echo "Audio track defaults have been updated. English track (ID: $english_track) is now set as default." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment