Extract subtitles from a movie file and save it as an .srt file using Bash

A couple watching a movie with subtitles

The film industry in Germany is definitely not Hollywood, but every now and then, there’s a movie that’s worth watching, e.g., “Glauben” (English: “The Allegation”) or “Terror” (“The Verdict”), both by the writer and lawyer Ferdinand von Schirach—that my non-German wife doesn’t understand.

Luckily, the German media libraries of public broadcast channels come with subtitles—in German, but those can be translated easily online if you extract the .srt subtitle file from it. Here’s how.

tl;dr

Here’s the code snippet hosted on GitLab.

Install ffmpeg

Before you start, make sure you have installed ffmpeg. Check this by running ffmpeg -h. If something shows up, you’re good. If not, use brew install ffmpeg.

Extract Subtitles

Once you’ve downloaded the movie from the media library, for example, with the easy app Downie through the awesome app catalog that is Setapp, or by finding the direct link, all you need to do is run this simple Bash script in your console:

for file in *.mkv; do
  ffmpeg -i "$file" -map_metadata:s:0 "${file%.mkv}.srt"
done
Bash

Run this command in your console inside the directory where the movie file is located, and also make sure to adjust the file extension (in this case: .mkv):

# This is where the file `glauben-1080p.mkv` was downloaded in
cd ~/Downloads

# Find and loop through all files with the file extension `.mkv`...
for file in *.mkv; do
  # ...and extract the subtitle
  ffmpeg -i "$file" -map_metadata:s:0 "${file%.mkv}.srt"
done
Bash

Result

At the end, you should see a file named glauben-1080p.srt in the same directory.

Translate Subtitles

But, hey, what’s the point if it’s still in German? I’m not sure if this is the most user-friendly or fastest way, but the website subtitle-translator.com does this within a few clicks and free of charge. It uses Google’s translation service, so all languages are available.

Now, show some respect and donate a few bucks to its creator, Renata Barbieri Zimmermann!