http://www.perlmonks.org?node_id=794976

This utility allows to shift subtitles time
#!/usr/bin/perl -pl # time shift for srt subtitles BEGIN { ($dt = shift @ARGV) != 0 or print "Usage: $0 SECONDS file" and exit; } s{ (\d+) : (\d\d) : (\d\d) , (\d+) } { my @t = ($1, $2, $3, $4 + $dt * 1E3); $t[2] += $t[3] / 1E3; $t[3] %= 1E3; $t[1] += $t[2] / 60; $t[2] %= 60; $t[0] += $t[1] / 60; $t[1] %= 60; sprintf '%02d:%02d:%02d,%03d', @t; }gxe;

Replies are listed 'Best First'.
Re: Time shift for SRT subtitles
by Anonymous Monk on Feb 19, 2012 at 14:48 UTC
    Hi, thanks for your idea for subtitle shifting. Unfortunately your code has a bug for negative time shifts. Here is alternative code that avoids the bug alltogether by first calculating the new time (in ms) and working out the other time values from there.
    s{ (\d+) : (\d\d) : (\d\d) , (\d+) } { $time = $1 * 3600E3 + $2 * 60E3 + ($3 + $dt) * 1E3 + $4; $h = int $time / 3600E3; $time %= 3600E3; $m = int $time / 60E3; $time %= 60E3; $s = int $time / 1E3; $time %= 1E3; $ms = int $time; sprintf "%02d:%02d:%02d,%03d", $h, $m, $s, $ms; }gxe;
Re: Time shift for SRT subtitles
by jdrago_999 (Hermit) on Sep 17, 2009 at 23:34 UTC

    by "srt" tables - do you mean closed caption data?