I have a simply formatted text file (Edit Decision List) with rows of numbers (timecode frame rate 25) followed by rows of properties (names etc.).
Ultimately I am trying to:
retrieve the lines starting with * FROM CLIP NAME:
and the row/line (timecode) immediately above. On this line are Timecodes, there are 4 groups of numbers, each are expressed as 00:00:00:00 - or HH:MM:SS:FF or Hours, minutes, seconds, frames. Then I discard everything else.
Use the first 2 number groups (they are start and end times) to derive duration.
Then append duration to the Clip Name line.
Save file as "SourceFileName".txt (original is .edl so they won't overwrite).
As my frame rate is 25 frames per second I was expecting to decompose each group into a frame count.
I expected to convert Timecode to 25 frames per second:
That would make a group of 00:02:20:01 = 3501 frames
3501 modulo (%) 25 = 1 frame remainder
140/60 = 2 min
Then I would subtract the first group from the second to find the difference. Once I have the difference I recompose the Frame Count to a timecode, just reversing the math.
I can't work out how to specify the name line then grab the preceding line for arithemetic using the first 2 of the 4 groups.
So far (not far) I've only established a way for the user to define the source file on their desktop.
Option Explicit
Dim fso, oFile, y
Set fso = CreateObject("Scripting.FileSystemObject")
'get user to open file name
y = InputBox("name of file to save")
'next line opens a file with that name
Set oFile = fso.OpenTextfile(y & ".edl")
UPDATE: revised script, but I cannot even group the selected lines and their start/end values
Option Explicit
Dim fso, oFile, y, re, prev, line, matches
Set fso = createobject("Scripting.FileSystemObject")
'get user to open file name
y = inputbox("name of file to save")
'next line opens a file with that name
Set oFile = fso.Opentextfile(y&".edl")
Do Until oFile.AtEndOfStream
line = oFile.ReadLine
'At this point the variable prev either is empty (during the first loop
'cycle) or holds the content of the previous line.
If Left(line, 21) = "* FROM CLIP NAME: " Then
'do stuff here
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)
'print each pair of prev & Pattern match
prev = (line) & (matches)
wscript.echo prev
'don't know how to use submatch values
End If
Loop
Sample .edl file:
TITLE: test logan * COMMENT: CREATED BY GRASS VALLEY FOR EDIUS (CMX-3600) 001 0000 A C 00:00:04:23 00:00:42:04 00:00:00:00 00:00:37:06 * FROM CLIP NAME: 12 - Tech Sexy - D Cebert - FFP170 002 0000 A C 00:00:20:01 00:00:31:23 00:01:29:24 00:01:41:21 * FROM CLIP NAME: 03 - Web Of Deceit (Main) - J Woodall - SFT164 003 0000 A C 00:00:31:23 00:00:31:23 00:01:41:21 00:01:41:21 M2 0000 025.0 00:00:31:23 003 0000 A D 025 00:00:31:09 00:00:54:12 00:01:41:21 00:02:04:24 * EFFECT NAME: CROSS DISSOLVE * FROM CLIP NAME: 03 - Web Of Deceit (Main) - J Woodall - SFT164 * TO CLIP NAME: 03 - Web Of Deceit (Main) - J Woodall - SFT164 M2 0000 025.0 00:00:31:09 004 0000 A2 C 00:01:15:08 00:01:31:24 00:01:48:04 00:02:04:20 * FROM CLIP NAME: 12 - Environs A - T Juckes, S Kidd - SCDV354 005 0000 A2 C 00:00:11:12 00:00:30:05 00:02:06:24 00:02:25:17 * FROM CLIP NAME: 13 - Contagion (Main) - J Woodall - SFT164 006 0000 A2 C 00:00:06:13 00:00:56:09 00:02:27:04 00:03:17:00 * FROM CLIP NAME: 03 - Web Of Deceit (Main) - J Woodall - SFT164 007 0000 A2 C 00:00:56:09 00:00:56:09 00:03:17:00 00:03:17:00 M2 0000 025.0 00:00:56:09 007 0000 A2 D 025 00:00:55:08 00:01:54:03 00:03:17:00 00:04:15:20 * EFFECT NAME: CROSS DISSOLVE * FROM CLIP NAME: 03 - Web Of Deceit (Main) - J Woodall - SFT164 * TO CLIP NAME: 03 - Web Of Deceit (Main) - J Woodall - SFT164 M2 0000 025.0 00:00:55:08 008 0000 A2 C 00:01:15:08 00:01:37:12 00:05:04:10 00:05:26:14 * FROM CLIP NAME: 12 - Environs A - T Juckes, S Kidd - SCDV354 009 0000 A2 C 00:00:00:00 00:00:26:19 00:06:00:08 00:06:27:02 * FROM CLIP NAME: 38 - Signs Of Pollution - W Plass - SCDV354 010 0000 A2 C 00:00:25:08 00:01:13:03 00:06:39:16 00:07:27:11 * FROM CLIP NAME: 38 - Signs Of Pollution - W Plass - SCDV354 011 0000 A2 C 00:01:13:03 00:01:13:03 00:07:27:11 00:07:27:11 M2 0000 025.0 00:01:13:03 011 0000 A2 D 025 00:01:48:22 00:02:04:09 00:07:27:11 00:07:42:23 * EFFECT NAME: CROSS DISSOLVE * FROM CLIP NAME: 38 - Signs Of Pollution - W Plass - SCDV354 * TO CLIP NAME: 38 - Signs Of Pollution - W Plass - SCDV354 M2 0000 025.0 00:01:48:22
I have to do this in VBScript so that we can run it on various user's Windows desktops. We can't install other executables or run from command prompts. I don't have privileges for admin installs.
Remember the previous line in a separate variable when reading the file:
Do Until oFile.AtEndOfStream
line = oFile.ReadLine
'At this point the variable prev either is empty (during the first loop
'cycle) or holds the content of the previous line.
If Left(line, 19) = "* FROM CLIP NAME: " Then
'do stuff here
End If
prev = line
Loop
Use a regular expression for extracting start and end timestamps.
Set re = New RegExp
re.Pattern = " (\d{2}:\d{2}:\d{2}:\d{2}) (\d{2}:\d{2}:\d{2}:\d{2})"
Set matches = re.Execute(prev)
The timestamps are available as the first and second submatch of matches
.
Beware, however, that some of the FROM CLIP NAME
lines in your input file don't seem to be preceded by timestamp lines, so you'll need to handle that.