Commit: 4bd127be9858214089a05e52c67b6276da3e571a
Parent: f12c65ad08ecfb452ca65bb4f6085ed89c174646
Author: Randy Palamar
Date: Mon, 6 Sep 2021 16:21:17 -0600
add an awk script for adjusting srt timings
Diffstat:
1 file changed, 48 insertions(+), 0 deletions(-)
diff --git a/bin/srt-adjust b/bin/srt-adjust
@@ -0,0 +1,48 @@
+#!/bin/awk -f
+
+# adjusts a provided srt file by the given time in milliseconds
+
+function usage() {
+ printf "usage: %s [-]time(ms) srt\n", ARGV[0]
+ exit(1)
+}
+
+function tomsecs(a) {
+ gsub(/,/, ":", a)
+ split(a, t, ":")
+ return (t[1] * 3600 + t[2] * 60 + t[3]) * 1000 + t[4]
+}
+
+function ftime(a) {
+ ms = a % 1000
+ a = (a - ms) / 1000
+ s = a % 60
+ a = (a - s) / 60
+ m = a % 60
+ h = (a - m) / 60
+
+ return sprintf("%02d:%02d:%02d,%03d", h, m, s, ms)
+}
+
+function bump(a, time) {
+ return ftime(tomsecs(a) + time)
+}
+
+BEGIN {
+ if (ARGC != 3) {
+ usage()
+ }
+
+ adj = ARGV[1]
+ delete ARGV[1]
+ FS = " --> "
+}
+
+!/[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9]/ {
+ print
+ next
+}
+
+{
+ printf("%s --> %s\n", bump($1, adj), bump($2, adj))
+}