|
|
@ -55,6 +55,7 @@ sub add_point { |
|
|
|
my $err = $p->parse($val); |
|
|
|
my $err = $p->parse($val); |
|
|
|
die "$err\n" if $err; |
|
|
|
die "$err\n" if $err; |
|
|
|
push @points, $p; |
|
|
|
push @points, $p; |
|
|
|
|
|
|
|
@points = sort { $a->time <=> $b->time } @points; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
########### init ################### |
|
|
|
########### init ################### |
|
|
@ -100,7 +101,7 @@ if ($mode eq 'framerate') { |
|
|
|
$opts{infile} |
|
|
|
$opts{infile} |
|
|
|
or die "No input file\n"; |
|
|
|
or die "No input file\n"; |
|
|
|
|
|
|
|
|
|
|
|
my $ssa = Subtitle::Format::SSA->new(debug => !!$opts{loglevel}); |
|
|
|
my $ssa = Subtitle::Format::SSA->new(debug => ($opts{loglevel} >= 2 ? 1 : 0)); |
|
|
|
unless ($ssa->from_file($opts{infile})) { |
|
|
|
unless ($ssa->from_file($opts{infile})) { |
|
|
|
foreach my $line (@{ $ssa->{log} }) { |
|
|
|
foreach my $line (@{ $ssa->{log} }) { |
|
|
|
print $line, "\n"; |
|
|
|
print $line, "\n"; |
|
|
@ -108,10 +109,6 @@ unless ($ssa->from_file($opts{infile})) { |
|
|
|
exit 1; |
|
|
|
exit 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (@points) { |
|
|
|
|
|
|
|
@points = sort { $a->time <=> $b->time } @points; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($mode eq 'framerate') { |
|
|
|
if ($mode eq 'framerate') { |
|
|
|
my $mod = $opts{inrate} / $opts{outrate}; |
|
|
|
my $mod = $opts{inrate} / $opts{outrate}; |
|
|
|
foreach my $e (@{ $ssa->events }) { |
|
|
|
foreach my $e (@{ $ssa->events }) { |
|
|
@ -125,8 +122,8 @@ if ($mode eq 'framerate') { |
|
|
|
next if $p->time > $e->t_start; |
|
|
|
next if $p->time > $e->t_start; |
|
|
|
$e->t_start($e->t_start + $p->shift); |
|
|
|
$e->t_start($e->t_start + $p->shift); |
|
|
|
$e->t_end ($e->t_end + $p->shift); |
|
|
|
$e->t_end ($e->t_end + $p->shift); |
|
|
|
} # foreach |
|
|
|
} # foreach @events |
|
|
|
} # while |
|
|
|
} # while @points |
|
|
|
} elsif ($opts{amode} eq 'rst') { |
|
|
|
} elsif ($opts{amode} eq 'rst') { |
|
|
|
while (my $p = shift @points) { |
|
|
|
while (my $p = shift @points) { |
|
|
|
# use time of next point as upper limit for current |
|
|
|
# use time of next point as upper limit for current |
|
|
@ -136,8 +133,8 @@ if ($mode eq 'framerate') { |
|
|
|
next if $end and $end <= $e->t_start; # too late |
|
|
|
next if $end and $end <= $e->t_start; # too late |
|
|
|
$e->t_start($e->t_start + $p->shift); |
|
|
|
$e->t_start($e->t_start + $p->shift); |
|
|
|
$e->t_end ($e->t_end + $p->shift); |
|
|
|
$e->t_end ($e->t_end + $p->shift); |
|
|
|
} # foreach |
|
|
|
} # foreach @events |
|
|
|
} # while |
|
|
|
} # while @points |
|
|
|
} |
|
|
|
} |
|
|
|
} elsif ($mode eq 'drift') { |
|
|
|
} elsif ($mode eq 'drift') { |
|
|
|
if ($points[0]->time >= 0.2) { |
|
|
|
if ($points[0]->time >= 0.2) { |
|
|
@ -155,18 +152,22 @@ if ($mode eq 'framerate') { |
|
|
|
my $p = Subtitle::TimePoint->new(time => $maxtime, shift => 0.0); |
|
|
|
my $p = Subtitle::TimePoint->new(time => $maxtime, shift => 0.0); |
|
|
|
push @points, $p; |
|
|
|
push @points, $p; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($opts{loglevel} >= 1) { |
|
|
|
# dump points list |
|
|
|
# dump points list |
|
|
|
print "Final points list:\n"; |
|
|
|
print "Final points list:\n"; |
|
|
|
foreach my $p (@points) { |
|
|
|
foreach my $p (@points) { |
|
|
|
printf "- %d:%02d:%02d.%03d ~ %.3f\n", make_timing($p->time), $p->shift; |
|
|
|
printf "- %d:%02d:%02d.%03d ~ %.3f\n", make_timing($p->time), $p->shift; |
|
|
|
} |
|
|
|
} |
|
|
|
print "-" x 30, "\n"; |
|
|
|
print "-" x 30, "\n"; |
|
|
|
|
|
|
|
} |
|
|
|
# real retime |
|
|
|
# real retime |
|
|
|
$ssa->sort_events; |
|
|
|
$ssa->sort_events; |
|
|
|
foreach my $e (@{ $ssa->events }) { |
|
|
|
foreach my $e (@{ $ssa->events }) { |
|
|
|
while ($points[1]->time <= $e->t_start) { |
|
|
|
while ($points[1]->time <= $e->t_start) { |
|
|
|
|
|
|
|
if ($opts{loglevel} >= 2) { |
|
|
|
printf "move timepoints: %d:%02d:%02d.%03d (endpoint) <= %d:%02d:%02d.%03d (event)\n", |
|
|
|
printf "move timepoints: %d:%02d:%02d.%03d (endpoint) <= %d:%02d:%02d.%03d (event)\n", |
|
|
|
make_timing($points[1]->time), make_timing($e->t_start); |
|
|
|
make_timing($points[1]->time), make_timing($e->t_start); |
|
|
|
|
|
|
|
} |
|
|
|
shift @points; |
|
|
|
shift @points; |
|
|
|
} |
|
|
|
} |
|
|
|
my ($a, $b) = @points; |
|
|
|
my ($a, $b) = @points; |
|
|
@ -179,6 +180,7 @@ if ($mode eq 'framerate') { |
|
|
|
: ($a->shift + $abs * $pct); |
|
|
|
: ($a->shift + $abs * $pct); |
|
|
|
$e->t_start($e->t_start + $mod); |
|
|
|
$e->t_start($e->t_start + $mod); |
|
|
|
$e->t_end ($e->t_end + $mod); |
|
|
|
$e->t_end ($e->t_end + $mod); |
|
|
|
|
|
|
|
next unless $opts{loglevel} >= 2; |
|
|
|
printf "- %d:%02d:%02d.%03d ~ %.3f\n", make_timing($e->t_start), $mod; |
|
|
|
printf "- %d:%02d:%02d.%03d ~ %.3f\n", make_timing($e->t_start), $mod; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|