Skip to content

Instantly share code, notes, and snippets.

@AndreiDuma
Created January 13, 2014 20:30
Show Gist options
  • Save AndreiDuma/8407525 to your computer and use it in GitHub Desktop.
Save AndreiDuma/8407525 to your computer and use it in GitHub Desktop.
A little script to help with extracting subtitles from .mkv files.
#!/bin/sh
if ! command -v mkvmerge mkvextract >/dev/null 2>&1; then
echo >&2 "Tools mkvmerge & mkvextract are required. Install package mkvtoolnix."
exit 1
fi
filename=$1
if [ ! -f $filename ]; then
echo "File not found."
exit 1
fi
filename_no_ext=$(echo $1 | sed -r 's/.mkv//')
sed_exp='s/.*([0-9]+):.*language:([a-z]+).*/\1:'$filename_no_ext'.\2.\1.srt/'
mkvmerge -I $filename | grep subtitles | sed -r $sed_exp | xargs mkvextract tracks $filename
@Seegras
Copy link

Seegras commented Jun 8, 2016

And in order to make this work with filenames containing the path, you need to do this:

filename_no_ext=$(basename $1 .mkv)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment