Page 1 of 1

[PP-Script] Automatically convert subtitles to SRT using ffmpeg

Posted: 24 Nov 2019, 16:52
by JChris
Many of my media downloads comes with subtitles formats other than SRT, but my TV only supports SRT. I have to convert them before playing as my NAS isn't powerful to do the conversion during playback.

To help me with that, I created the workaround script below:

Code: Select all

#!/bin/bash 

input_file=$(realpath "$1")

mv -f "$input_file" "${input_file}.temp"
ffmpeg -i "${input_file}.temp" -map 0 -c:v copy -c:a copy -c:s srt "$input_file"
rm -f "${input_file}.temp"
And I run it inside the Season folder as:

Code: Select all

find . -iname '*.mkv' -exec bash subtitle-converter.sh {} \;
It's very simple, it doesn't check if the subtitle is already in SRT or not, it also doesn't check if the file doesn't have any subtitle to skip it. But it works.

I would like to execute something similar after each NZBGet download, but the script would need to be smarter and take into consideration stuff like:

- Download is a single file or a folder with multiple files
- Media file doesn't have subtitle stream so skip this file
- Media file already has SRT subtitle stream so skip this file

Can someone help?