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

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
Post Reply
JChris
Posts: 1
Joined: 24 Nov 2019, 16:39

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

Post by JChris » 24 Nov 2019, 16:52

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?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest