strPathSource = "C:\h264\source\" strPathMencoder = "C:\h264\tools\mencoder.exe" strPathMplayer = "C:\h264\tools\mplayer.exe" strPathMP4Box = "C:\h264\tools\mp4box.exe" strPathFAAC = "C:\h264\tools\faac.exe" strPathOutputFolder = "C:\h264\output\" strPathTempFolder = "C:\h264\temp\" strPathLogDir = strPathOutputFolder Set objFSO = CreateObject("Scripting.FileSystemObject") Set Folder = objFSO.GetFolder(strPathSource) Set objFiles = Folder.Files For Each objFile in Folder.Files If objFSO.GetExtensionName(objFile) = "dv" Then strPathLogFile = strPathLogDir & objFSO.GetBaseName(objFile) & ".log" Set logStream = objFSO.createtextfile(strPathLogFile , True) Encode objFSO.GetBaseName(objFile) 'objFSO.DeleteFile objFile End If Next Sub Encode(SourceFileName) 'These settings produce quicktime compatible mp4-files strCommonMencoderOptions = "-cache 20480 " & _ "-passlogfile " & strPathTempFolder & SourceFileName & "-pass.log " & _ "-vf yadif,harddup " & _ "-of rawvideo " strCommonX264Options = ":bitrate=700" & _ ":bframes=1" & _ ":me=umh" & _ ":partitions=all" & _ ":trellis=1" & _ ":qp_step=4" & _ ":qcomp=0.7" & _ ":direct_pred=auto" & _ ":keyint=25" 'Extracting audio RunAndCaptureOutput strPathMplayer & " " & strPathSource & SourceFileName & ".dv " & _ " -dumpaudio " & _ " -dumpfile " & _ strPathTempFolder & SourceFileName & ".pcm" 'Encoding Audio RunAndCaptureOutput strPathFAAC & " -b 64 " & _ " --tns " & _ " --obj-type LC " & _ " --mpeg-vers 4 " & _ " -o " & strPathTempFolder & SourceFileName & ".mp4 " & _ " -P " & _ " -R 48000 " & _ " -B 16 " & _ " -C 2 " & _ " -X " & _ strPathTempFolder & SourceFileName & ".pcm" 'First Pass RunAndCaptureOutput strPathMencoder & " " & strPathSource & SourceFileName & ".dv " & _ " -o NUL " & _ " -ovc x264 " & _ " -x264encopts pass=1:turbo=2" & strCommonX264Options & _ " -nosound " & _ strCommonMencoderOptions 'Second Pass RunAndCaptureOutput strPathMencoder & " " & strPathSource & SourceFileName & ".dv " & _ " -o " & strPathTempFolder & SourceFileName & ".h264 " & _ " -ovc x264 " & _ " -x264encopts pass=2:frameref=5" & strCommonX264Options & _ " -nosound " & _ strCommonMencoderOptions 'Muxing video with previously created audio-only mp4-file RunAndCaptureOutput strPathMP4Box & " -add " & strPathTempFolder & SourceFileName & ".h264 " & _ strPathTempFolder & SourceFileName & ".mp4 " objFSO.MoveFile strPathTempFolder & SourceFileName & ".mp4", strPathOutputFolder & SourceFileName & ".mp4" 'Clean up temp files If objFSO.FileExists(strPathTempFolder & SourceFileName & "-pass.log") Then objFSO.DeleteFile strPathTempFolder & SourceFileName & "-pass.log" End If If objFSO.FileExists(strPathTempFolder & SourceFileName & ".h264") Then objFSO.DeleteFile strPathTempFolder & SourceFileName & ".h264" End If If objFSO.FileExists(strPathTempFolder & SourceFileName & ".pcm") Then objFSO.DeleteFile strPathTempFolder & SourceFileName & ".pcm" End If End Sub Sub WriteToLog(stringCommand, stringStdOut, stringStdErr) logstream.writeline "Command: " & " " & stringCommand logstream.writeline "StdOut: " & " " & stringStdOut logstream.writeline "StdErr: " & " " & stringStdErr End Sub Sub RunAndCaptureOutput(sCmd) Dim oSh, FSO, fErr, sData, fOut, ErrF, OutF, Cmd Set oSh = createobject("WScript.Shell") Set FSO = createobject("Scripting.FileSystemObject") fOut = strPathTempFolder & FSO.GetTempName fErr = strPathTempFolder & FSO.GetTempName Cmd = "%COMSPEC% /c " & sCmd & " 2>" & fErr & " 1>" & fOut oSh.Run Cmd, 0, True If FSO.FileExists(fOut) Then If FSO.GetFile(fOut).Size>0 Then Set OutF = FSO.OpenTextFile(fOut) sOut = OutF.Readall OutF.Close End If FSO.DeleteFile(fOut) End If If FSO.FileExists(fErr) Then If FSO.GetFile(fErr).Size>0 Then Set ErrF = FSO.OpenTextFile(fErr) sErr = ErrF.Readall ErrF.Close End If FSO.DeleteFile(fErr) End If WriteToLog Cmd, sOut, sErr End Sub