Browse Source

* bin/ssa-retime : update

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

96
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,62 +78,56 @@ GetOptions(
($opts{infile} and -f $opts{infile})
or usage("Input file not exists");
given ($mode) {
when ('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') {
$opts{shifttime}
or usage("You should set '-t' option in this mode");
(not $opts{shiftstart} or $opts{shiftstart} > 0.0)
or usage("Shift start must be positive time");
(not $opts{shiftend} or $opts{shiftend} > 0.0)
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') {
scalar(@points)
or usage("You should specify at least one shift point");
foreach my $point (@points) {
...
}
}
default {
usage("Incorrect mode: $mode (see help below)");
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");
} elsif ($mode eq 'shift') {
$opts{shifttime}
or usage("You should set '-t' option in this mode");
(not $opts{shiftstart} or $opts{shiftstart} > 0.0)
or usage("Shift start must be positive time");
(not $opts{shiftend} or $opts{shiftend} > 0.0)
or usage("Shift end must be positive time");
(not $opts{shiftlen} or $opts{shiftlen} > 0.0)
or usage("Shift length must be positive time");
} elsif ($mode eq 'points') {
scalar(@points)
or usage("You should specify at least one shift point");
foreach my $point (@points) {
...
}
} 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);
given ($mode) {
when ('framerate') {
my $mod = $opts{inrate} / $opts{outrate};
foreach my $event ($ssa->events) {
$event->{start} *= $mod;
$event->{end} *= $mod;
}
}
when ('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) {
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;
}
if ($ssa->from_file($opts{infile}) < 0) {
warn "Can't parse input file: $opts{infile}\n";
exit 1;
}
if ($mode eq 'framerate') {
my $mod = $opts{inrate} / $opts{outrate};
foreach my $event (@{ $ssa->{events} }) {
$event->{start} *= $mod;
$event->{end} *= $mod;
}
when ('points') {
} 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} }) {
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;
}
} elsif ($mode eq 'points') {
...;
}
exit 0;

Loading…
Cancel
Save