Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Time shift for SRT subtitles

by ccn (Vicar)
on Sep 13, 2009 at 09:05 UTC ( #794976=CUFP: print w/ replies, xml ) Need Help??

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;

Comment on Time shift for SRT subtitles
Download Code
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?

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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://794976]
Approved by planetscape
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-12-27 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls