删除EDL文本文件的元素,对其他部分执行算术

时间:2018-05-14 08:56:49

标签: vbscript timecodes

我有一个简单格式化的文本文件(编辑决策列表),其中包含数字行(时间码帧速率为25),后跟属性行(名称等)。

最终我想:

  1. 检索以* FROM CLIP NAME:  开头的行和上面的行/行(时间码)。在这一行是时间码,有4组数字,每组表示为00:00:00:00 - 或HH:MM:SS:FF或小时,分钟,秒,帧。然后我放弃其他一切。

  2. 使用前2个数字组(它们是开始和结束时间)来推导持续时间

  3. 然后将持续时间附加到剪辑名称行。

  4. 将文件另存为" SourceFileName" .txt(原文为.edl,因此无法覆盖)。

  5. 由于我的帧速率是每秒25帧,我希望将每个组分解为帧数

    我希望将时间码转换为每秒25帧:

    • 小时到帧时基(25fps)1小时= 1 * 60 *(60 * 25)= 9000
    • 分钟到帧时基(25fps)1分钟= 1 *(60 * 25)= 1500
    • 秒到帧时基(25fps)1秒= 1 * 25f

    这会产生一组00:02:20:01 = 3501帧

    • 3501整数除数// 25 fps = 140秒
    • 3501模数(%)25 = 1帧余数

    • 140/60 = 2分钟

    • 140%60 = 20秒

    然后我会从第二组中减去第一组以找出差异。一旦我有了差异,我就会将帧计数重新组合成一个时间码,只需要反转数学。

    我无法确定如何指定名称行,然后使用前4个组中的前两个来获取前一行的arithemetic。

    到目前为止(不远)我只为用户建立了一种在桌面上定义源文件的方法。

    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")
    

    更新 :修改后的脚本,但我甚至无法对选定的行及其开始/结束值进行分组

    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桌面上运行它。我们无法安装其他可执行文件或从命令提示符运行。我没有管理员安装权限。

1 个答案:

答案 0 :(得分:1)

在阅读文件时,请记住单独变量中的上一行:

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

使用regular expression提取开始和结束时间戳。

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的第一个和第二个子匹配。

请注意,输入文件中的某些FROM CLIP NAME行似乎没有时间戳行,因此您需要处理它。