Ben Bullock > Video-Subtitle-SRT > Video::Subtitle::SRT

Download:
Video-Subtitle-SRT-0.05.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.05   Source  

NAME ^

Video::Subtitle::SRT - manipulate SRT subtitle files

SYNOPSIS ^

  use Video::Subtitle::SRT;

  my $subtitle = Video::Subtitle::SRT->new (\&callback);
  $subtitle->parse ($fh);

  sub callback {
      my $data = shift;
      # $data->{number}
      # $data->{start_time}
      # $data->{end_time}
      # $data->{text}
  }

DESCRIPTION ^

Video::Subtitle::SRT is a callback based parser to parse SubRip subtitle files (.SRT). See the script adjust-srt in the distribution for how to use this module to create subtitle delay adjusting tools.

METHODS ^

new

    my $srt_wranger = Video::Subtitle::SRT->new (\& function);

The argument is the function to call back when parsing.

The callback function takes one argument, a hash reference. The hash has the following fields:

start_time

The start time of the subtitle, as a text string, in the SRT time format. This may be converted into a time in milliseconds from the start of the video using "srt_time_to_milliseconds".

end_time

The end time of the subtitle, as a text string, in the SRT time format. This may be converted into a time in milliseconds from the start of the video using "srt_time_to_milliseconds".

text

The text of the subtitle.

number

The number of the subtitle.

It does not need to return any value. It can die on error to halt parsing.

parse

Parse a file handle,

    open my $fh, "<", 'movie.srt' or die $!;
    $srt_wrangler->parse ($fh);    
    close $fh or die $!;

or a file

    $srt_wrangler->parse ('movie.srt');

Parse the subtitle file and call the callback specified in "new".

FUNCTIONS ^

srt_time_to_milliseconds

Convert an SRT time into a time in milliseconds.

milliseconds_to_srt_time

Convert a time in milliseconds into an SRT time.

make_subtitle

    my $srt = make_subtitle (\%data);

Given a subtitle containing the fields {number => 1, text => 'Words', start_time => srt_time, end_time => srt_time}, make it into an SRT subtitle. The return value is the subtitle. If any of the fields is missing, this emits a fatal error.

add

    $srt->add ($data);

Add the line to the subtitles.

write_file

    $srt->write_file ();

Write the file of subtitles to STDOUT.

EXPORTS ^

Video::Subtitle::SRT exports the following functions on request: "srt_time_to_milliseconds", "milliseconds_to_srt_time", and "make_subtitle". All the functions can be exported using the tag <code>:all</code>:

    use Video::Subtitle::SRT ':all';

SEE ALSO ^

http://en.wikipedia.org/wiki/SubRip

This explains the format.

http://www.opensubtitles.org/

AUTHOR ^

The module's creator is Tatsuhiko Miyagawa <miyagawa@bulknews.net>. The module is currently maintained by Ben Bullock <bkb@cpan.org>.

LICENSE ^

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: