sub2csv.pl

Download source codes: Media:sub2csv.pl

After downloading, convert the file name from sub2csv.pl.txt to sub2csv.pl

 #!/usr/bin/perl    while (<>) {    s/\r$//;    if (/^{([0-9]+)}{([0-9]+)}(.*)/) {      $from=$1/25;      $from_hour = int($from/3600);      $from_minute = int(($from - $from_hour*3600)/60);      $from_second = int($from - $from_hour*3600 - $from_minute*60);      $from_fraction = int(($from - $from_hour*3600 - $from_minute*60                                      - $from_second)*1000);      $to=$2/25;      $to_hour = int($to/3600);      $to_minute = int(($to - $to_hour*3600)/60);      $to_second = int($to - $to_hour*3600 - $to_minute*60);      $to_fraction = int(($to - $to_hour*3600 - $to_minute*60 -                                 $to_second)*1000);        $text=$3;      printf("%02d:%02d:%02d.%04d\t%02d:%02d:%02d.%04d\t%s\n",          $from_hour, $from_minute, $from_second, $from_fraction,          $to_hour, $to_minute, $to_second, $to_fraction,          $text);        $from='';      $to='';      $text ='';    }  }

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

$from=$1/30; .. $to=$2/30;

Command Sample:

cat source.sub | perl sub2csv.pl > target.csv

Additional information: Typical SUB sample:

{478}{563}- Hey, guys.|- Hey. {592}{690}Don't say that loud.|He is gonna want to hug me. {719}{769}Good news, everyone.|We finally found him.

“|” represent the carriage return. Output sample

00:00:19.0120   00:00:22.0519   - Hey, guys.|- Hey. 00:00:23.0679   00:00:27.0600   Don't say that loud.|He is gonna want to hug me. 00:00:28.0760   00:00:30.0760   Good news, everyone.|We fina