Created
January 13, 2014 20:30
-
-
Save AndreiDuma/8407525 to your computer and use it in GitHub Desktop.
A little script to help with extracting subtitles from .mkv files.
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 | |
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 |
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
Fails when there are more than 10 tracks, fails if the subtitles are vobsub (because mkvextract will then ditch anything beyond the first dot, and make two files named .idx and .sub respectively -- probably a bug in mkvextract, it should split off at the last dot, not the first).
Here's a sed-line that fixes the first and works around the second.
sed_exp='s/Track\sID\s([0-9]{1,3}):.language:([a-z]+)./\1:'$filename_no_ext'-\1-\2/'