vbscripttimestamptimecodes

How do I change timecode strings into numerals in Vbscript?


I have this form of string entry:

002  0000     A     C        00:00:20:01 00:00:31:23 00:01:29:24 00:01:41:21

From previous question I can capture it with:

Set re = New RegExp
re.Pattern = "C        (\d{2}:\d{2}:\d{2}:\d{2}) (\d{2}:\d{2}:\d{2}:\d{2})"
matches = re.Execute(prev)

Now I have 2 submatches that I need to perform arithmetic on.

How can I seperate out each submatch to a list of digit pairs seperated by ":" into a list(not sure of term?)?

These strings are timestamps that I want to decompose down to frame counts.

I expected to convert Timecode to 25 frames per second:

  1. 1st pair is hours to frame time base (25fps) 1 hour = 1*60*(60*25) = 9000
  2. 2nd pair is minutes to frame time base (25fps) 1 minute = 1*(60*25) = 1500
  3. 3rd pair is seconds to frame time base (25fps) 1 second = 1*25f

For example a submatch of 00:02:20:01 would convert to 3501 frames

Previous question for reference

EDIT Here's what I ended up with. I had to find the difference (datediff) between time values which returned an answer in "seconds", Then I convert this to time format with timeserial. But it appended with an AM/PM clock so I set the scripts region to Germany, which turns off the AM/PM suffix.

Option Explicit
'change system location to Germany, to simulate 24hour clock *no AM PM time
setlocale "de-de"

'TBA read whole data doc to grab the NameDetails and TC


    Dim TC
    'temporary data set, I will need to send each line to this search
    TC ="002  0000     A     C        00:00:20:01 00:00:23:23 00:01:29:24 00:01:41:21"

    'Define search terms for each timecode element *this is not a result yet
    Dim re1
    re1 =".*?"  'Non-greedy match on filler
    Dim re2
    re2 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"  'HourMinuteSec 1
    Dim re3
    re3 =".*?"  'Non-greedy match on filler
    Dim re4
    re4 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 2
    Dim re5
    re5 =".*?"  'Non-greedy match on filler
    Dim re6
    re6 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 3
    Dim re7
    re7 =".*?"  'Non-greedy match on filler
    Dim re8
    re8 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 4

    'add timecode search terms to a search pattern
    Dim r
    Set r = New RegExp
    r.Pattern = re1+re2+re3+re4+re5+re6+re7+re8
    r.IgnoreCase = True

    Dim m, timeDur, ts, Timeofday
    Set m = r.Execute(TC)
    'loop through timecodes to find duration between first 2 entries
    If m.Item(0).SubMatches.Count > 0 Then
        Dim time1
        time1=m.Item(0).SubMatches.Item(0)
        Dim time2
        time2=m.Item(0).SubMatches.Item(1)
        Dim time3
        time3=m.Item(0).SubMatches.Item(2)
        Dim time4
        time4=m.Item(0).SubMatches.Item(3)

        'find duration/difference between first 2 times, in seconds
        timeDur=datediff("s", time1, time2)
        'format result to a serial time format eg. 00:00:00
        ts = TimeSerial(0, 0, timeDur)
        'print duration result, will need to append track info and repeat. Then save to file
        MsgBox (ts)

    End If

Solution

  • So, ultimately I'm guessing you want to match on regex "time", and use the VBScript function "split"... Here is an example that might help you:

    Dim txt
    txt ="002  0000     A     C        00:00:20:01 00:00:31:23 00:01:29:24 00:01:41:21"
    
    Dim re1
    re1 =".*?"  'Non-greedy match on filler
    Dim re2
    re2 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-  9])?(?:\s?(?:am|AM|pm|PM))?)"  'HourMinuteSec 1
    Dim re3
    re3 =".*?"  'Non-greedy match on filler
    Dim re4
    re4 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 2
    Dim re5
    re5 =".*?"  'Non-greedy match on filler
    Dim re6
    re6 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 3
    Dim re7
    re7 =".*?"  'Non-greedy match on filler
    Dim re8
    re8 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 4
    
    Dim r
    Set r = New RegExp
    r.Pattern = re1+re2+re3+re4+re5+re6+re7+re8
    r.IgnoreCase = True
    Dim m
    Set m = r.Execute(txt)
    If m.Item(0).SubMatches.Count > 0 Then
        Dim time1
        time1=m.Item(0).SubMatches.Item(0)
        Dim time2
        time2=m.Item(0).SubMatches.Item(1)
        Dim time3
        time3=m.Item(0).SubMatches.Item(2)
        Dim time4
        time4=m.Item(0).SubMatches.Item(3)
        Response.Write("("+Replace(time1,"<","&lt;")+")"+"("+Replace(time2,"<","&lt;")+")"+"("+Replace(time3,"<","&lt;")+")"+"("+Replace(time4,"<","&lt;")+")"+"")
    End If