Skip to content

Instantly share code, notes, and snippets.

@belgareth
Forked from kampfgnu/mkvextractTracks.sh
Last active January 8, 2023 10:06
Show Gist options
  • Save belgareth/a9a2df50de7692cf821d6abf4fe2c13f to your computer and use it in GitHub Desktop.
Save belgareth/a9a2df50de7692cf821d6abf4fe2c13f to your computer and use it in GitHub Desktop.
batch extract subtitles from mkv files
#!/bin/bash -e
# a script that extracts the subtitle file of every mkv movie file and saves it with the same name
# copy to the folder where the mkv files live and run "./mkvextractTracks.sh" in terminal
# options: [trackID]
# example: ./mkvextractTracks.sh 1
#
# info:
# mkvextract is used to extract the subtitles, so mkvtoolnix app (which contains the mkvextract binary) is used:
# https://mkvtoolnix.download/downloads.html
# please adjust below path to point to mkvextract or this script won't work
extractorPath='/usr/bin/mkvextract'
# Ensure we're running in the location of the script.
cd "`dirname $0`"
for f in *; do
if [[ $f == *.mkv ]]; then
# Extract all subtitles from the file
$extractorPath tracks "$f" --no-video --no-audio "${f//mkv/srt}"
fi
done
echo "Complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment