'06/06/23 Send Timecode via RS232 based on Video Events 'HH:MM:SS:mmm. 'videoTimecodeInfo LIBRARY "v30/bslCore.brs" Function videoTimecodeInfo_Initialize(msgPort As Object, userVariables As Object, bsp as Object) print "videoTimecodeInfo_Initialize - entry" print "type of msgPort is ";type(msgPort) print "type of userVariables is ";type(userVariables) videoTimecodeInfo = newvideoTimecodeInfo(msgPort, userVariables, bsp) return videoTimecodeInfo End Function Function newvideoTimecodeInfo(msgPort As Object, userVariables As Object, bsp as Object) print "initvideoTimecodeInfo V0.1" ' Create the object to return and set it up s = {} s.msgPort = msgPort s.userVariables = userVariables s.bsp = bsp s.ProcessEvent = videoTimecodeInfo_ProcessEvent s.vm=CreateObject("roVideoMode") s.sTime = createObject("roSystemTime") s.TimeintoMs = TimeintoMs s.MillisecondsToTimeString = MillisecondsToTimeString s.videoTimecodeInfoBuilder = videoTimecodeInfoBuilder s.HandleVideoEventPlugin = HandleVideoEventPlugin s.TheStore = CreateObject("roAssociativeArray") s.TheStore.TimecodeID = CreateObject("roArray", 1, true) s.TheStore.TimecodeData = CreateObject("roArray", 1, true) s.currentFileDuration = 0 s.objectName = "TimecodeInfo_object" return s End Function Function TimeintoMs(time as string) '00:00:12,829 ' hp= 0 ' mp=instr(hp, time, ":")+1 ' sp=instr(mp+1, time, ":")+1 ' fp=instr(sp+1, time, ":")+1 ' hours = val(mid(time, hp, mp - 1)) ' minutes = val(mid(time, mp, sp - mp - 1)) ' seconds = val(mid(time, sp, fp - sp - 1)) ' frames = val(mid(time, fp, 2)) RegexSepComma = CreateObject("roRegex", ",", "i") FindRegSepComma = RegexSepComma.IsMatch(time) if FindRegSepComma then SplitBlocksSepComma = RegexSepComma.split(time) msBlock = val(SplitBlocksSepComma[1]) end if RegexSepCln = CreateObject("roRegex", ":", "i") FindRegSepCln = RegexSepCln.IsMatch(SplitBlocksSepComma[0]) if FindRegSepCln then SplitBlocksSepCln = RegexSepCln.split(SplitBlocksSepComma[0]) hours = val(SplitBlocksSepCln[0]) minutes = val(SplitBlocksSepCln[1]) seconds = val(SplitBlocksSepCln[2]) end if 'time_in_ms = (((((hours * 60) + minutes) * 60) + seconds) * 1000) + (frames * 1000 / 30) time_in_ms = (((((hours * 60) + minutes) * 60) + seconds) * 1000) + msBlock return time_in_ms End Function Function videoTimecodeInfoBuilder() VideoStartTime = m.sTime.GetLocalDateTime().GetString() print "" print " @@@ VideoStartTime: " VideoStartTime print "" if m.bsp.sign.zoneshsm[0].videoplayer <> invalid then print "" print " @@@ Video File Duration: "; m.bsp.sign.zoneshsm[0].videoplayer.GetDuration() print "" m.currentFileDuration = m.bsp.sign.zoneshsm[0].videoplayer.GetDuration() timecodeItem = 0 timecodeId = 0 while timecodeItem + 200 < m.currentFileDuration timecodeItem = timecodeItem + 200 convertedTimeString = m.MillisecondsToTimeString(timecodeItem) m.TheStore.TimecodeData.push({id:timecodeId, timecodevalue:timecodeItem, timecodeString:convertedTimeString}) eventx = m.bsp.sign.zoneshsm[0].videoplayer.AddEvent(timecodeId, timecodeItem) timecodeId = timecodeId + 1 end while 'stop '?m.TheStore.TimecodeData[48].timecodeString end if End Function Function videoTimecodeInfo_ProcessEvent(event As Object) as boolean retval = false ' print "videoTimecodeInfo_ProcessEvent - entry" ' print "type of m is ";type(m) ' print "type of event is ";type(event) if type(event) = "roVideoEvent" then retval = HandleVideoEventPlugin(event, m) end if return retval End Function Function HandleVideoEventPlugin(origMsg as Object, m as Object) as boolean if type(origMsg) = "roVideoEvent" then print "" print "Video Event: ";origMsg.GetInt() if origMsg.GetInt() = 3 then m.videoTimecodeInfoBuilder() else if origMsg.GetInt() = 12 then id = origMsg.GetData() print " - Matched Video Timecode id: "; m.TheStore.TimecodeData[id].id print " - Timecode in ms: "; m.TheStore.TimecodeData[id].timecodevalue print " - Formatted Timecode: "; m.TheStore.TimecodeData[id].timecodestring print " - Video Timecode Event Time: "; m.sTime.GetLocalDateTime().GetString() if m.bsp.serial["2"] <> invalid then if m.TheStore.TimecodeData[id] <> invalid then m.bsp.serial["2"].sendline(m.TheStore.TimecodeData[id].timecodestring) end if end if else if origMsg.GetInt() = 8 then print "Video End Event Received" VideoEndTime = m.sTime.GetLocalDateTime().GetString() EndedFileDuration = m.MillisecondsToTimeString(m.currentFileDuration) if m.bsp.serial["2"] <> invalid then m.bsp.serial["2"].sendline(EndedFileDuration) end if print "" print " @@@ VideoEndTime: "; VideoEndTime print " @@@ EndedFileDuration: "; EndedFileDuration print "" end if end if End Function Function MillisecondsToTimeString(milliseconds As Integer) As String hours = milliseconds / 3600000 milliseconds = milliseconds Mod 3600000 minutes = milliseconds / 60000 milliseconds = milliseconds Mod 60000 seconds = milliseconds / 1000 milliseconds = milliseconds Mod 1000 hourStr = StrI(hours) hourStr = StripLeadingSpaces(hourStr) If hours < 10 Then hourStr = "0" + hourStr minuteStr = StrI(minutes) minuteStr = StripLeadingSpaces(minuteStr) If minutes < 10 Then minuteStr = "0" + minuteStr secondStr = StrI(seconds) secondStr = StripLeadingSpaces(secondStr) If seconds < 10 Then secondStr = "0" + secondStr millisecondStr = StrI(milliseconds) millisecondStr = StripLeadingSpaces(millisecondStr) If milliseconds < 10 Then millisecondStr = "00" + millisecondStr Else If milliseconds < 100 Then millisecondStr = "0" + millisecondStr End If timeString = "brightsign timestamp " + hourStr + ":" + minuteStr + ":" + secondStr + ":" + millisecondStr + chr(13) Return timeString End Function