Skip to content

Instantly share code, notes, and snippets.

@iSplasher
Created June 5, 2016 06:49
Show Gist options
  • Save iSplasher/301c3ace3a022922e8504e179541752d to your computer and use it in GitHub Desktop.
Save iSplasher/301c3ace3a022922e8504e179541752d to your computer and use it in GitHub Desktop.
RipSubsFromMKV
#!/usr/local/bin/python
#
# Script to rip srt/ssa subtitles out of .mkv files
# Usage: scriptname.py [filename.mkv]
# If the filename isn't specified all .mkv files in the current directory will be processed
# Developed with ffmpeg 2.1.1, you probably want that or higher if this doesn't work
#
import glob, re, argparse
from subprocess import call
ffmpeg = '/usr/local/bin/ffmpeg'
parser = argparse.ArgumentParser(description='Extract subtitles from mkv files.')
parser.add_argument('-f', '--file', help="source filename (mkv) to extract subtitle from")
args = parser.parse_args()
def process(i):
return [ffmpeg, '-i', i, re.sub(r".mkv", ".srt", i)]
if args.file is None:
mkvs = glob.glob("*.mkv")
if (len(mkvs) == 0):
print "No .mkv files in current directory"
for i in mkvs:
call(process(i))
else:
call(process(args.file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment