srt2sub.pl

Download source codes: Media:srt2sub.pl. After downloading, convert the file name from srt2sub.pl.txt to srt2sub.pl

 #!/usr/bin/perl    while (<>) {    s/\r$//;    next if /^\d+$/;    if (/^(\d\d):(\d\d):(\d\d),(\d\d\d) --> (\d\d):(\d\d):(\d\d),(\d\d\d)/) {      $from=(($1*60)+$2)*60+$3+$4/1000.0;      $to=(($5*60)+$6)*60+$7+$8/1000.0;    } elsif (/^(.*\S)\s*$/) {      if ($text eq '') {        $text=$1;      } else {        $text .= "|" . $1;      }    } elsif (/^\s*$/) {      if ($from ne '' && $to ne '' && $text ne '') {        print "{", int(25*$from), "}{", int(25*$to), "}", $text, "\n";      }      $from='';      $to='';      $text ='';    }  }  if ($from ne '' && $to ne '' && $text ne '') {    print "{", int(25*$from), "}{", int(25*$to), "}", $text, "\n";  }

Usage: If the source frame rate is not 25 frames/sec, then you should change two lines in the code. For instance, if your source media has 30 frames/sec then Change two lines from

print “{”, int(25*$from), “}{”, int(25*$to), “}”, $text, “\n”

to

print “{”, int(30*$from), “}{”, int(30*$to), “}”, $text, “\n”

Command Sample:

cat source.srt | perl srt2sub.pl > target.sub

Typical SRT sample:

5 00:00:13,612 --> 00:00:14,647  X1:269 X2:447 Y1:482 Y2:524 What's up?

Output sample

{340}{366}What's up?