Last active
December 16, 2022 17:25
-
-
Save dkorunic/51d0a2b93d7fcd46d19a86e2b6697d98 to your computer and use it in GitHub Desktop.
Simple tool to strip all languages except the desired one from a mkv file
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/sh | |
# Copyright (C) 2022 Dinko Korunic | |
# Simple tool to strip all languages except the desired one from a bunch of mkv files in a current folder | |
# Depends: mkvtoolnix | |
LANG_CODE="hr" | |
LANG_TRACK_COUNT=$(mkvinfo -s "$1" | head -50 | grep -c '^Track .*: audio') | |
if [ "${LANG_TRACK_COUNT}" -eq 0 ]; then | |
echo "Unable to find any language track" | |
exit 1 | |
fi | |
if [ "${LANG_TRACK_COUNT}" -eq 1 ]; then | |
echo "There is only a single language, no need to convert" | |
exit 1 | |
fi | |
LANG_TRACK=$(mkvinfo -s "$1" | head -10 | grep "^Track .*: audio.*language: ${LANG_CODE}" | grep -oP '(?<=track ID: )\d+') | |
if [ -z "${LANG_TRACK}" ]; then | |
echo "Unable to find ${LANG_CODE} language" | |
exit 1 | |
fi | |
mkvmerge -o tmp.mkv --audio-tracks "${LANG_TRACK}" "$1" && mv tmp.mkv "$1" | |
rm -f tmp.mkv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment