删除EDL文本文件的元素,对其他部分执行算术运算 [英] Remove elements of an EDL text file, perform arithmetic on other parts
问题描述
我有一个格式简单的文本文件(编辑决策列表"),其中包含数字行(时间码帧频25)和属性(名称等)行.
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.).
最终我正在尝试:
-
检索以
* FROM CLIP NAME:
开头的行以及紧接其上方的行/行(时间码).在此行上是时间码,有4组数字,每组数字表示为00:00:00:00-或HH:MM:SS:FF或小时,分钟,秒,帧.然后我丢弃其他所有东西.
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.
然后将 duration 附加到剪辑名称行.
Then append duration to the Clip Name line.
将文件另存为"SourceFileName" .txt(原始文件为.edl,因此它们不会被覆盖).
Save file as "SourceFileName".txt (original is .edl so they won't overwrite).
由于我的帧速率为每秒25帧,因此我希望将每个组分解为帧计数.
As my frame rate is 25 frames per second I was expecting to decompose each group into a frame count.
我希望将时间码转换为每秒25帧:
I expected to convert Timecode to 25 frames per second:
- 小时到帧时基(25fps)1小时= 1 * 60 *(60 * 25)= 9000
- 分钟到帧时基(25fps)1分钟= 1 *(60 * 25)= 1500
- 秒至帧时基(25fps)1秒= 1 * 25f
那将使一组00:02:20:01 = 3501帧
That would make a group of 00:02:20:01 = 3501 frames
- 3501整数除法//25 fps = 140秒
-
3501模(%)25 = 1剩余帧数
- 3501 integer divide // 25 fps = 140 sec
3501 modulo (%) 25 = 1 frame remainder
140/60 = 2分钟
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.
我不知道如何指定名称行,然后使用4组中的前2组抓住前一行进行算术运算.
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 :已修改脚本,但我什至无法将所选行及其开始/结束值分组
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
示例.edl文件:
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
我必须在VBScript中执行此操作,以便我们可以在各种用户的Windows桌面上运行它.我们无法安装其他可执行文件,也无法从命令提示符下运行.我没有管理员安装权限.
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)
时间戳记可作为matches
的第一和第二子匹配.
The timestamps are available as the first and second submatch of matches
.
但是请注意,输入文件中的某些FROM CLIP NAME
行似乎没有时间戳记行的开头,因此您需要进行处理.
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.
这篇关于删除EDL文本文件的元素,对其他部分执行算术运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!