我正在编写脚本以简化字幕(srt)的生成。 我有一个热键从播放器中获取时间戳并粘贴它。 但是,播放器(Express Scribe)显示时间戳格式为00:00:00.00,SRT使用00:00:00,00。
我想做两件事。
对此的任何帮助将不胜感激。
答案 0 :(得分:2)
关于这一点真正棘手的是像时间戳这样的时间戳
05:59:59.60
不能轻易增加50
结果应该是
06:00:00,10
因为一厘秒不能超过99而一秒不能超过59(就像一分钟不能)。
所以我们需要在这里使用一些讨厌的数学:
playerFormat := "01:10:50.70"
;extract hour, minute, second and centisecond using regex
RegExMatch(playerFormat,"O)(?P<hour>\d+):(?P<minute>\d+):(?P<second>\d+)\.(?P<centisecond>\d+)",matches)
;convert the strings to numbers by removing the leading zeros
hour := LTrim(matches.hour,"0")
minute := LTrim(matches.minute,"0")
second := LTrim(matches.second,"0")
centisecond := LTrim(matches.centisecond,"0")
;translate the total time into centiseconds
centiSecondsTotal := centisecond + second*100 + minute*100*60 + hour*100*60*60
;add 50 centiseconds (=0.5 seconds) to it
centiSecondsTotal += 50
;useing some math to translate the centisecond number that we just added the 50 to into hours, minutes, seconds and remaining centiseconds again
hour := Floor(centiSecondsTotal / (60*60*100))
centiSecondsTotal -= hour*60*60*100
minute := Floor(centiSecondsTotal/(60*100))
centiSecondsTotal -= minute*100*60
second := Floor(centiSecondsTotal/(100))
centiSecondsTotal -= second*100
centisecond := centiSecondsTotal
;add leading zeros for all numbers that only have 1 now
hour := StrLen(hour)=1 ? "0" hour : hour
minute := StrLen(minute)=1 ? "0" minute : minute
second := StrLen(second)=1 ? "0" second : second
centisecond := StrLen(centisecond)=1 ? "0" centisecond : centisecond
;create the new timestamp string
newFormat := hour ":" minute ":" second "," centisecond
MsgBox, %newFormat% ;Output is 01:10:51,20