我使用VB脚本将ARF文件转换为MP4和WMV格式。该脚本使用网络录制播放器中的API(用于查看和转换ARF格式的Web-Ex视频)。但是,我遇到了一个非常奇怪的错误。 WMV转换在我尝试的任何机器上都能正常工作,但这与MP4不同,MP4仅适用于我的机器,但不适用于我尝试过的其他机器。
该脚本通过将位于特定文件夹中的所有ARF文件(在我的情况下,在C驱动器中称为“Webex”的文件夹)转换为MP4和WMV,并将它们保存在同一文件夹中。 当我在运行脚本后打开文件夹时,我可以看到转换过程中创建的某些文件,一旦完成,只剩下WMV视频。 MP4开始转换然后在某些机器上停止。您可以看到正在创建的“videoname”-mp4.cfg文件,但它会立即消失。
不知道问题是什么,任何帮助都将受到赞赏。
以下是我的文章:
Option Explicit
'Main
Sub Main
Dim Path
Dim a: a = ListDir("C:\Webex\*.arf")
Dim FileName
Dim FileName1
Dim FileName2
Dim mp4
Dim wmv
Dim objFSO
Dim objFile
Dim objTextFile
Dim WSHShell
Dim StrCMDLine
Dim d: d = ListDir("C:\Webex\*.cfg")
Set WSHShell = CreateObject("WScript.Shell")
For Each FileName In d
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(Filename)
Next
For Each FileName In a
mp4 = 0
wmv = 0
'WScript.Echo FileName
'WScript.Echo Left(Filename,(Len(Filename)-4))
Dim b: b = ListDir(Left(Filename,(Len(Filename)-4))+".mp4")
For Each FileName1 In b
'WScript.Echo FileName1
mp4 = 1
Next
Dim c: c = ListDir(Left(Filename,(Len(Filename)-4))+".wmv")
For Each FileName2 In c
'WScript.Echo FileName2
wmv = 1
Next
If mp4 = 0 Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(Left(Filename,(Len(Filename)-4))+"-mp4.cfg")
objTextFile.WriteLine("")
objTextFile.WriteLine("[Console]")
objTextFile.WriteLine("inputfile="+Filename)
objTextFile.WriteLine("media=MP4")
objTextFile.WriteLine("showui=0")
objTextFile.WriteLine("[UI]")
objTextFile.WriteLine("chat=0")
objTextFile.WriteLine("qa=0")
objTextFile.WriteLine("largeroutline=1")
objTextFile.WriteLine("[MP4]")
objTextFile.WriteLine("outputfile="+Left(Filename,(Len(Filename)-4))+".mp4")
objTextFile.WriteLine("width=1024")
objTextFile.WriteLine("height=768")
objTextFile.WriteLine("framerate=8")
objTextFile.Close
End If
If wmv = 0 Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(Left(Filename,(Len(Filename)-4))+"-wmv.cfg")
objTextFile.WriteLine("[Console]")
objTextFile.WriteLine("inputfile="+Filename)
objTextFile.WriteLine("media=WMV")
objTextFile.WriteLine("showui=0")
objTextFile.WriteLine("PCAudio=0")
objTextFile.WriteLine("[UI]")
objTextFile.WriteLine("largeroutline=0")
objTextFile.WriteLine("[WMV]")
objTextFile.WriteLine("outputfile="+Left(Filename,(Len(Filename)-4))+".wmv")
objTextFile.WriteLine("width=1024")
objTextFile.WriteLine("height=768")
objTextFile.WriteLine("videocodec=Windows Media Video 9")
objTextFile.WriteLine("audiocodec=Windows Media Audio 9.2 Lossless")
objTextFile.WriteLine("videoformat=default")
objTextFile.WriteLine("audioformat=default")
objTextFile.WriteLine("videokeyframes=4")
objTextFile.WriteLine("maxstream=1000")
objTextFile.Close
End If
Next
Dim e: e = ListDir("c:\Webex\*.cfg")
For Each FileName In e
Set objFSO = CreateObject("Scripting.FileSystemObject")
StrCMDLine = "cmd /c C: & CD %windir% & C:\ProgramData\WebEx\WebEx\500\nbrplay.exe -Convert " + """" + FileName + """" + " & exit"
'WScript.Echo StrCMDLine
wshShell.run StrCMDLine ,0,True
objFSO.DeleteFile(Filename)
Next
End Sub
Public Function ListDir (ByVal Path)
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
If Path = "" Then Path = "*.*"
Dim Parent, Filter
If fso.FolderExists(Path) Then ' Path is a directory
Parent = Path
Filter = "*"
Else
Parent = fso.GetParentFolderName(Path)
If Parent = "" Then If Right(Path,1) = ":" Then Parent = Path: Else Parent = "."
Filter = fso.GetFileName(Path)
If Filter = "" Then Filter = "*"
End If
ReDim a(10)
Dim n: n = 0
Dim Folder: Set Folder = fso.GetFolder(Parent)
Dim Files: Set Files = Folder.Files
Dim File
For Each File In Files
If CompareFileName(File.Name,Filter) Then
If n > UBound(a) Then ReDim Preserve a(n*2)
a(n) = File.Path
n = n + 1
End If
Next
ReDim Preserve a(n-1)
ListDir = a
End Function
Private Function CompareFileName (ByVal Name, ByVal Filter) ' (recursive)
CompareFileName = False
Dim np, fp: np = 1: fp = 1
Do
If fp > Len(Filter) Then CompareFileName = np > Len(name): Exit Function
If Mid(Filter,fp) = ".*" Then ' special case: ".*" at end of filter
If np > Len(Name) Then CompareFileName = True: Exit Function
End If
If Mid(Filter,fp) = "." Then ' special case: "." at end of filter
CompareFileName = np > Len(Name): Exit Function
End If
Dim fc: fc = Mid(Filter,fp,1): fp = fp + 1
Select Case fc
Case "*"
CompareFileName = CompareFileName2(name,np,Filter,fp)
Exit Function
Case "?"
If np <= Len(Name) And Mid(Name,np,1) <> "." Then np = np + 1
Case Else
If np > Len(Name) Then Exit Function
Dim nc: nc = Mid(Name,np,1): np = np + 1
If StrComp(fc,nc,vbTextCompare)<>0 Then Exit Function
End Select
Loop
End Function
Private Function CompareFileName2 (ByVal Name, ByVal np0, ByVal Filter, ByVal fp0)
Dim fp: fp = fp0
Dim fc2
Do ' skip over "*" and "?" characters in filter
If fp > Len(Filter) Then CompareFileName2 = True: Exit Function
fc2 = Mid(Filter,fp,1): fp = fp + 1
If fc2 <> "*" And fc2 <> "?" Then Exit Do
Loop
If fc2 = "." Then
If Mid(Filter,fp) = "*" Then ' special case: ".*" at end of filter
CompareFileName2 = True: Exit Function
End If
If fp > Len(Filter) Then ' special case: "." at end of filter
CompareFileName2 = InStr(np0,Name,".") = 0: Exit Function
End If
End If
Dim np
For np = np0 To Len(Name)
Dim nc: nc = Mid(Name,np,1)
If StrComp(fc2,nc,vbTextCompare)=0 Then
If CompareFileName(Mid(Name,np+1),Mid(Filter,fp)) Then
CompareFileName2 = True: Exit Function
End If
End If
Next
CompareFileName2 = False
End Function
答案 0 :(得分:1)
我同意Nathan Rice的观点,这不是VBScript问题。您需要检索命令行在cmd执行时转储的错误。
所以尝试重写一遍:
StrCMDLine = "cmd /c C: & CD %windir% & C:\ProgramData\WebEx\WebEx\500\nbrplay.exe -Convert " + """" + FileName + """" + " & exit"
到此:
dim timelog : timelog = replace(replace(formatdatetime(Now, 3), ":", "-"), " ", "-")
StrCMDLine = "cmd /c C: & CD %windir% & C:\ProgramData\WebEx\WebEx\500\nbrplay.exe -Convert " + """" + FileName + """" + " > C:\dumplog-" + timelog + ".txt & exit"
这将允许您每次检索命令日志文件并查找命令提示符报告的错误。