Page 1 of 1

How to convert multiple subtitle files

Posted: Sun May 12, 2019 1:51 pm
by Pippin
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

Re: How to convert multiple subtitle files

Posted: Mon May 13, 2019 9:20 am
by donalduck
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

Re: How to convert multiple subtitle files

Posted: Wed May 15, 2019 3:07 am
by root
123.png
do not use quotes

Re: How to convert multiple subtitle files

Posted: Wed May 15, 2019 8:33 pm
by rene
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 *.

Re: How to convert multiple subtitle files

Posted: Thu May 16, 2019 4:49 am
by root
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".

Re: How to convert multiple subtitle files

Posted: Thu May 16, 2019 5:24 am
by gm10
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/"

Re: How to convert multiple subtitle files

Posted: Thu May 16, 2019 10:19 am
by Pippin
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.

Re: How to convert multiple subtitle files

Posted: Thu May 16, 2019 11:00 am
by gm10
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.

Re: How to convert multiple subtitle files

Posted: Thu May 16, 2019 1:36 pm
by Pippin
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.

Re: How to convert multiple subtitle files

Posted: Thu May 16, 2019 2:02 pm
by gm10
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 280 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.

Re: How to convert multiple subtitle files

Posted: Thu May 16, 2019 2:13 pm
by Pippin
Hi,

Your example showing 1/2 is showing -/0 for me.
mpvsubs.png
mpvsubs.png (17.97 KiB) Viewed 272 times

Re: How to convert multiple subtitle files

Posted: Thu May 16, 2019 2:25 pm
by gm10
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.