-
-
Save kampfgnu/bb7be04b624ed5ddf65d6e7c54f9ce2e to your computer and use it in GitHub Desktop.
| #!/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='/Applications/MKVToolNix-9.0.1.app/Contents/MacOS/mkvextract' | |
| defaultTrackID=2 | |
| # Ensure we're running in location of script. | |
| cd "`dirname $0`" | |
| if [ $# -gt 0 ] | |
| then | |
| defaultTrackID=$1 | |
| fi | |
| for f in *; do | |
| if [[ $f == *.mkv ]]; | |
| then | |
| echo $f | |
| $extractorPath tracks "$f" $defaultTrackID:"${f//mkv/srt}" | |
| fi | |
| done | |
| echo "Complete" |
@Bananaman is it possible to directly shell script on Linux without Python, please?
Came here for a potential one-liner but was sadly disappointed that this was just a way to extract subtitles from a single file.
Bananaman's script was borked for some reason, so no love there too.
In the end, the solution using pure Bash was not that hard.
Here's a one-liner:
for F in *.mkv; do MKV=$(echo $F | sed -e "s/\.mkv$//"); SUBS=$(mkvmerge -i "$MKV.mkv" | grep "SubRip/SRT" | cut -d ' ' -f3 | tr -d ':'); for SUB in $SUBS; do mkvextract tracks "$F" $SUB:"${MKV}_$SUB.srt"; done; done
Or if you prefer a more elegant solution in the form of a script you just execute in a folder:
https://gist.github.com/fevangelou/48da813ac1d5d0d207ff0acab1c09df2
Enjoy :)
Very usefull. Thank you @fevangelou ;)
Try https://github.com/caoccao/BatchMkvExtract which provides much better user experience.
Try https://github.com/caoccao/BatchMkvExtract which provides much better user experience.
I would try, but your AppImage doesn't launch. I opened an issue.
@Bananaman Oh thanks. your script is very usefull.
@anhthoai install python 3.5 and mkvtoolnix then windows command: python mkvextract-allsubs file.mkv