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.
scripts/mux_replace_subtitles.sh

38 lines
1.2 KiB

#!/bin/bash
# Check if mkvmerge is installed
if ! command -v mkvmerge &> /dev/null; then
echo "Error: mkvmerge not found. Please install mkvtoolnix."
exit 1
fi
# Process each .mkv file in the current directory
for mkv in *.mkv; do
# Skip if no .mkv files exist
[[ -e "$mkv" ]] || continue
base_name="${mkv%.mkv}"
# Unset all subtitle tracks in the MKV file before adding new ones
echo "Executing command: mkvmerge -o temp.mkv --no-subtitles \"$mkv\""
if mkvmerge -o temp.mkv --no-subtitles "$mkv"; then
echo "Subtitle tracks unset successfully."
# Mux the new subtitle files with the language "eng"
echo "Executing command: mkvmerge -o out.mkv \"temp.mkv\" --language 0:eng \"${base_name}\"*.srt"
if mkvmerge -o out.mkv "temp.mkv" --language 0:eng "${base_name}"*.srt; then
echo "Muxing successful, replacing original file and deleting subtitles."
mv out.mkv "$mkv"
rm -f "${base_name}"*.srt
else
echo "Muxing failed, keeping original files."
fi
# Clean up temporary file
rm -f temp.mkv
else
echo "Failed to unset subtitles, keeping original files."
fi
done