#!/usr/bin/env lua -- srtdelta.lua -- Adjust times on srt subtitles. -- (c) 2005 Alexandre Erwin Ittner -- Distributed under the GNU GPL v2 or above. WITHOUT WARRANTIES. -- $Id$ local function time_join(h, m, s, f) return 3600 * h + 60 * m + s + 0.001 * f end local function time_fmt(tm) local h = math.floor(tm/3600.0) local m = math.floor(math.mod(tm, 3600)/60.0) local s = math.floor(tm - 3600*h - 60*m) local f = math.floor(1000*(tm - 3600*h - 60*m - s)) return string.format("%02d:%02d:%02d,%03d", h, m, s, f) end assert(arg[1], "Error: no time delay given on command line.") local delta = tonumber(arg[1]) local ttp = "([0-9 ][0-9]):([0-9][0-9]):([0-9][0-9]),([0-9][0-9][0-9])" local pat = ttp .. " %-%-> " .. ttp local line, h1, m1, s1, f1, h2, m2, s2, f2, _ for line in io.lines() do _, _, h1, m1, s1, f1, h2, m2, s2, f2 = string.find(line, pat) if f2 then print(time_fmt(time_join(h1, m1, s1, f1) + delta) .. " --> " .. time_fmt(time_join(h2, m2, s2, f2) + delta)) else print(line) end end