Skip to content

Instantly share code, notes, and snippets.

@catphive
Created February 15, 2012 07:50
Show Gist options
  • Save catphive/1834250 to your computer and use it in GitHub Desktop.
Save catphive/1834250 to your computer and use it in GitHub Desktop.
code to adjust SRT subtitle timing in emacs
(defun incr-time (adjust-millis hour minute second milli)
(message (format "test %d" adjust-millis))
(let ((total-millis (+ milli (* second 1000) (* minute 60 1000) (* hour 60 60 1000))))
(setq total-millis (+ total-millis adjust-millis))
(format "%02d:%02d:%02d,%03d"
(/ total-millis 3600000)
(% (/ total-millis 60000) 60)
(% (/ total-millis 1000) 60)
(% total-millis 1000))))
(defun c5-replace (regexp to-string &optional delimited start end)
(replace-regexp regexp
(query-replace-compile-replacement to-string t)
delimited start end))
(defun fixup (millis)
(interactive "nAdjust milliseconds: ")
(c5-replace "\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\),\\([0-9]\\{3\\}\\)"
(format "\\,(incr-time %d \\#1 \\#2 \\#3 \\#4)" millis)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment