Created
April 7, 2015 05:40
-
-
Save samirfor/036b9e4d027e22b0f752 to your computer and use it in GitHub Desktop.
This script removes all subtitles 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/bash | |
################################################################ | |
# This script removes all subtitles from a mkv file. # | |
################################################################ | |
usage="[i] Usage: `basename $0` video.mkv" | |
# Checking parameter | |
if [ -z "$1" ]; then | |
echo ""; echo $usage; echo ""; exit | |
fi | |
# Setting up vars | |
mkvfile=$1 | |
# Adding suffix in new filename | |
newmkvfolder=$(dirname "${mkvfile}") | |
filename="${mkvfile##*/}" | |
filename="${filename%.*}" | |
if [ ${filename: -3} == ".br" ]; then | |
filename=${filename:0:${#filename}-3} # remove '.br' suffix | |
echo "INFO: '.br' suffix removed." | |
fi | |
suffix="nosub" # to distinguish the old mkv from the new | |
newmkvfilename="${filename}.${suffix}.mkv" # gets the filename without the path | |
newmkv=$newmkvfilename # do the work on current directory | |
# Checking if mkv file has at least one subtitle | |
mkvmerge -i "$mkvfile" | grep 'subtitle' | |
if [ $? != 0 ]; then | |
echo "INFO: There are no subtitles in this file already." | |
mv "$mkvfile" "$newmkv" | |
exit 0 | |
else | |
echo "INFO: Subtitles detected." | |
fi | |
# Building a new mkv container without subtitles and no video reencode (fast) | |
mkvmerge -S -o "$newmkv" "$mkvfile" # -S => --no-subtitles # remove all subtitles | |
success=$? | |
# Cleaning original files | |
if [ $success == 0 ]; then | |
echo "SUCCESS: Subtitle removed." | |
rm "$mkvfile" | |
echo "INFO: The original file was removed." | |
else | |
echo "ERROR: A error ocurred. Be aware." | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment