Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Time shift for SRT subtitles

by ccn (Vicar)
on Sep 13, 2009 at 09:05 UTC ( [id://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;

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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-19 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found