Browse Source

* bin/ssa-retime : update

master
Alex 'AdUser' Z 9 years ago
parent
commit
e59febefae
  1. 36
      bin/ssa-retime

36
bin/ssa-retime

@ -2,12 +2,10 @@
use strict;
use warnings;
use feature qw(switch);
use lib 'lib';
use utf8;
use Getopt::Long;
use File::Slurp;
use Subtitle::SSA;
sub usage {
@ -80,14 +78,12 @@ GetOptions(
($opts{infile} and -f $opts{infile})
or usage("Input file not exists");
given ($mode) {
when ('framerate') {
if ($mode eq 'framerate') {
$opts{outrate}
or usage("You should set at least '-F' option in this mode");
($opts{inrate} != 0.0 and $opts{outrate} != 0.0)
or usage("Framerate can't be zero");
}
when ('shift') {
} elsif ($mode eq 'shift') {
$opts{shifttime}
or usage("You should set '-t' option in this mode");
(not $opts{shiftstart} or $opts{shiftstart} > 0.0)
@ -96,46 +92,42 @@ given ($mode) {
or usage("Shift end must be positive time");
(not $opts{shiftlen} or $opts{shiftlen} > 0.0)
or usage("Shift length must be positive time");
}
when ('points') {
} elsif ($mode eq 'points') {
scalar(@points)
or usage("You should specify at least one shift point");
foreach my $point (@points) {
...
}
}
default {
} else {
usage("Incorrect mode: $mode (see help below)");
}
}
my @lines = read_file($ARGV[0]);
my $ssa = Subtitle::SSA->new(debug => !!$opts{loglevel});
$ssa->parse(\@lines);
if ($ssa->from_file($opts{infile}) < 0) {
warn "Can't parse input file: $opts{infile}\n";
exit 1;
}
given ($mode) {
when ('framerate') {
if ($mode eq 'framerate') {
my $mod = $opts{inrate} / $opts{outrate};
foreach my $event ($ssa->events) {
foreach my $event (@{ $ssa->{events} }) {
$event->{start} *= $mod;
$event->{end} *= $mod;
}
}
when ('shift') {
} elsif ($mode eq 'shift') {
my $style = $opts{style};
my $start = $opts{shiftstart} // 0.0;
my $end = $opts{shiftend} // (($opts{shiftlen}) ? $start + $opts{shiftend} : undef);
my $mod = $opts{shifttime};
foreach my $event ($ssa->events) {
foreach my $event (@{ $ssa->{events} }) {
next if ($style and $event->{style} ne $style);
next if ($start and $event->{start} < $start);
next if ($end and $event->{end} > $end);
$event->{start} += $mod;
$event->{end} += $mod;
}
}
when ('points') {
}
} elsif ($mode eq 'points') {
...;
}
exit 0;

Loading…
Cancel
Save