| Subtitles(3pm) | User Contributed Perl Documentation | Subtitles(3pm) |
Subtitles - handle video subtitles in various text formats
Video files (avi mpeg etc) are sometimes accompanied with subtitles, which are currently very popular as text files. "Subtitles" provides means for simple loading, re-timing, and storing these subtitle files. A command-line tool subs for the same purpose and using "Subtitles" interface is included in the distribution.
The module supports "srt", "sub", "smi", and "mdvd" subtitle formats.
Time values are floats, in seconds with millisecond precision.
use Subtitles;
my $sub = Subtitles->new();
open F, 'Ichi The Killer.sub' or die "Cannot read:$!";
die "Cannot load:$@\n" unless $sub-> load(\*F);
close F;
# back two minutes
$sub-> shift( $sub-> parse_time('-02:00'));
# re-frame from 25 fps
$sub-> scale( 23.976 / 25 );
# or both
$sub-> transform( -120, 0.96);
$sub-> transform( -120, 0.96, 0, $sub-> length - 60);
# split in 2
my ( $part1, $part2) = $sub-> split( $self-> length / 2);
# join back with 5-second gap
$part1-> join( $part2, 5);
# save
open F, "> out.sub" or die "Cannot write:$!\n";
$part1-> save( \*F);
close F;
# report
print "sub is ", time2str( $sub-> length);
By default, tries to deduce which codec to use; to point the selection explicitly CODEC string is to be used.
This is alpha code, more a proof-of-concept rather that anything else, so most surely bugs are lurking.
Anyway: not all subtitle types are recognized. The modules doesn't handle multi-language subtitles.
subs - command-line wrapper for this module
<http://dvd.box.sk/>, <http://subs.2ya.com>.
Dmitry Karasik, <dmitry@karasik.eu.org>.
| 2022-06-17 | perl v5.34.0 |