54

Are there any open source, command line, subtitle converters - preferably for Linux?

Gareth
  • 19,080
Johnas
  • 787

10 Answers10

67

You can try FFmpeg (great tool !) :

$ ffmpeg -i file.srt file.vtt
SebMa
  • 2,035
22

very simple and effective oneliner i use to convert subtitles:

for i in *.ass ; do ffmpeg -i "$i" "$i.srt" ; done

just change ass and srt according to your needs.

yodog
  • 852
  • 1
  • 9
  • 14
8

Subtitles perl swiss army knife (scroll to the end of the page).

Here you can find more options.

Also, mplayer/mencoder has some dumpXXXsub options, which might work. I never tried this, but reading the man, it should work. Example:

-dumpmpsub (MPlayer only)
              Convert the given subtitle (specified with the -sub option) to MPlayer's subtitle format, MPsub.  Creates a dump.mpsub file in the current directory.
Sunny
  • 951
6

The open source program Subtitle Edit has a command line converter and is available for both Windows and Linux.

Syntax: SubtitleEdit /convert "pattern" "name-of-format-without-spaces"

Example 1: SubtitleEdit /convert sub1.srt sami
Result: Will convert sub1.srt to sub1.sub to SAMI format

Example 2: SubtitleEdit /convert *.srt adobeencore
Result: Will convert all .srt files to Adobe Encore format

For Linux the command line needs to be slightly longer…

Syntax: mono SubtitleEdit.exe /convert "pattern" "name-of-format-without-spaces"

…but could easily be wrapped in a script.

Moilleadóir
  • 186
  • 8
Johanz
  • 114
5

I found that some players (e.g., Google Drive video player) do not like the .srt generated from:

ffmpeg -i subtitles.ass <blah>.srt

or:

SubtitleEdit /convert subtitles.ass subrip

but:

ffmpeg -i subtitles.ass -codec:s text subtitles.srt

...did the trick for me.

Hashim Aziz
  • 13,835
1

What is it you want to convert exactly? If it is between subtitle formats then it depends on which formats you are talking about. Those which are bitmap based will require OCR to convert to text format and generally always require user input for confirming the accuracy of the OCR

If it is all text formats then Jubler or Aegisub may be of use

Shevek
  • 16,738
0

rename the file name using sed

for i in ./*.ass ; do ffmpeg -i "$i" "$( echo "$i"|sed 's/\.ass//g' ).srt" ; done

if you want to delete the .srt file after converting, just add a rm command afterwards.

for i in ./*.ass ; do ffmpeg -i "$i" "$( echo "$i"|sed 's/\.ass//g' ).srt"  &&  rm -f "$i"  ; done
0
#!/bin/bash

file="*.srt"                     # Find file
ffmpeg -i "$file" "${file%.*}.vtt"   # Convert file  
rm "$file"                         # Remove file .srt from your dir

if you want to convert more file using this program in for loop.

0

With Windows batch file, you could use this to convert all text-subtitle files in folder to SRT

for %%i in (*.vtt .ass .ssa) do ffmpeg -i "%%i" "%%~ni.srt"
0

For converting the whole directory and also changing the extension of every file. You can use find command and combined it with ${%.*} to remove the .srt and use the new extension .vtt with this one-line command.

find . -name "*.srt" -exec bash -c 'ffmpeg -i {} "${0%.*}$1" ' {} ".vtt" \;

The reason to call bash is to use the ${0%.*} to find basename.

The {} after ffmpeg -i {} "${0%.*}$1" is the argument $0 that send into the ffmpeg command.

The ".vtt" is the argument $1.

So ${0%.*}$1 became basename.vtt