How to convert multiple subtitle files

Forum rules
Before you post please read how to get help
Post Reply
Pippin
Level 4
Level 4
Posts: 233
Joined: Wed Dec 13, 2017 11:14 am
Location: NL/DE/TH

How to convert multiple subtitle files

Post by Pippin » Sun May 12, 2019 1:51 pm

Hi,

Trying to convert multiple *.vtt to *.srt subtitle files using ffmpeg.
A single file works fine:

Code: Select all

/usr/bin/ffmpeg -i vttfile.vtt srtfile.srt
For multiple files i have the following:

Code: Select all

#!/bin/sh

LOC="$HOME/Videos/"

for x in "$LOC/*.vtt"
    do /usr/bin/ffmpeg -i "$LOC/$x" "$LOC/$x.srt"
done
Execution:

Code: Select all

sh -v subconv.sh
Results in:

Code: Select all

*.vtt: No such file or directory
Executing as user or root makes no difference.
Example of subtitle file:
Name. Serie. Episode. English.en.vtt
Wanted result:
Name. Serie. Episode. English.en.srt
Thanks.

Edit: Typo
Last edited by Pippin on Thu May 16, 2019 10:21 am, edited 1 time in total.
"I'm not in this world to live up your expectations, neither are you here to live up to mine.”
F.P. & P.T.

donalduck
Level 3
Level 3
Posts: 134
Joined: Mon Oct 07, 2013 1:43 pm
Location: there

Re: How to convert multiple subtitle files

Post by donalduck » Mon May 13, 2019 9:20 am

Hello,
several mistakes in your script I think :)

try this

Code: Select all

#!/bin/sh
LOC="$HOME/Videos"
for x in $LOC/*.vtt
  do /usr/bin/ffmpeg -i "$x" "${x%vtt}srt"
done
also you can use -x option to debug a shell script.

more explanation: man sh

User avatar
root
Level 1
Level 1
Posts: 8
Joined: Wed Mar 13, 2019 11:57 am
Location: Russia

Re: How to convert multiple subtitle files

Post by root » Wed May 15, 2019 3:07 am

123.png
do not use quotes

rene
Level 10
Level 10
Posts: 3307
Joined: Sun Mar 27, 2016 6:58 pm

Re: How to convert multiple subtitle files

Post by rene » Wed May 15, 2019 8:33 pm

Very slight adjustment to above answers; don't use quotes around wildcards. That's to say, if indeed you want to guard against $LOC containing whitespace you'd write it as e.g. for x in "$LOC"/*.vtt. In this case it's clearly not important, $LOC being defined without whitespace just above, but this additional reply so as to say that quotes by design "take away special meaning" in shell, and specifically, take away the special meaning of *.

User avatar
root
Level 1
Level 1
Posts: 8
Joined: Wed Mar 13, 2019 11:57 am
Location: Russia

Re: How to convert multiple subtitle files

Post by root » Thu May 16, 2019 4:49 am

rene wrote:
Wed May 15, 2019 8:33 pm
Very slight adjustment to above answers; don't use quotes around wildcards. That's to say, if indeed you want to guard against $LOC containing whitespace you'd write it as e.g. for x in "$LOC"/*.vtt.
Adjustment? Can the home folder contain spaces in the name?! No! You say rational things, but the word "adjustment" is inappropriate here. It is rather an "addition".

gm10
Level 17
Level 17
Posts: 7446
Joined: Thu Jun 21, 2018 5:11 pm

Re: How to convert multiple subtitle files

Post by gm10 » Thu May 16, 2019 5:24 am

root wrote:
Thu May 16, 2019 4:49 am
Can the home folder contain spaces in the name?! No!
Why would you think that? Of course it can. Try it:

Code: Select all

sudo adduser spaces --home="/home/Home Directory With Spaces/"

Pippin
Level 4
Level 4
Posts: 233
Joined: Wed Dec 13, 2017 11:14 am
Location: NL/DE/TH

Re: How to convert multiple subtitle files

Post by Pippin » Thu May 16, 2019 10:19 am

Hi,

Thanks all, little late reaction from me but donalduck's way works here.
In the meantime I found VLC will handle vtt files so problem solved.

Thanks.
"I'm not in this world to live up your expectations, neither are you here to live up to mine.”
F.P. & P.T.

gm10
Level 17
Level 17
Posts: 7446
Joined: Thu Jun 21, 2018 5:11 pm

Re: How to convert multiple subtitle files

Post by gm10 » Thu May 16, 2019 11:00 am

Pippin wrote:
Thu May 16, 2019 10:19 am
In the meantime I found VLC will handle vtt files so problem solved.
Don't all media players? At least mpv does as well.

Pippin
Level 4
Level 4
Posts: 233
Joined: Wed Dec 13, 2017 11:14 am
Location: NL/DE/TH

Re: How to convert multiple subtitle files

Post by Pippin » Thu May 16, 2019 1:36 pm

Hi,

VLC finds the subs automatically if the file name is the same.

Both Media Player and mpv Media Player not working.
Cannot find any menu in mpv.

Thanks.
"I'm not in this world to live up your expectations, neither are you here to live up to mine.”
F.P. & P.T.

gm10
Level 17
Level 17
Posts: 7446
Joined: Thu Jun 21, 2018 5:11 pm

Re: How to convert multiple subtitle files

Post by gm10 » Thu May 16, 2019 2:02 pm

Pippin wrote:
Thu May 16, 2019 1:36 pm
VLC finds the subs automatically if the file name is the same.

Both Media Player and mpv Media Player not working.
Cannot find any menu in mpv.
Weird. I don't have Media Player but mpv behaves just like the VLC functionality you describe (actually it also picks them up as filename.languagecode, that's the preferred naming because then it can display the subtitle language in the UI).

mpv has a minimalist interface so there is no menu, the subtitle selection is at the bottom of the OSD, to the left of the volume control:
mpv-subtitles.png
mpv-subtitles.png (6.77 KiB) Viewed 208 times
And further to the left is the audio track selection.

But there's nothing wrong with using VLC, not trying to talk you out of it.

Pippin
Level 4
Level 4
Posts: 233
Joined: Wed Dec 13, 2017 11:14 am
Location: NL/DE/TH

Re: How to convert multiple subtitle files

Post by Pippin » Thu May 16, 2019 2:13 pm

Hi,

Your example showing 1/2 is showing -/0 for me.
mpvsubs.png
mpvsubs.png (17.97 KiB) Viewed 200 times
"I'm not in this world to live up your expectations, neither are you here to live up to mine.”
F.P. & P.T.

gm10
Level 17
Level 17
Posts: 7446
Joined: Thu Jun 21, 2018 5:11 pm

Re: How to convert multiple subtitle files

Post by gm10 » Thu May 16, 2019 2:25 pm

Yep, if the filename of the subs is the same but it doesn't show I have no answer for you. You could force it to load via the command line option I suppose, but that's inconvenient.

Note that I'm running the latest release version (0.29.1) rather than the older 0.27.2 in the LM 19 repos, so maybe that's the reason, although I saw nothing in the changelog about subtitles.

Post Reply

Return to “Scripts & Bash”