''''''''''''''''''''
' nskMovToMkv v0.4 '
''''''''''''''''''''
' Notes
'(ASCII 34 = Double Quotation Marks)
' Konfiguration
sMencoder = "r:\_run\_Progs\mencoder.exe"
sX264 = "r:\_run\_Progs\x264.exe"
sFfmpeg = "r:\_run\_Progs\ffmpeg.exe"
sMkvmerge = "r:\_run\_Progs\mkvmerge.exe"
'bOverwriteExisting = true ' to be implemented
bDeleteIntermediateFiles = true
bEndMessage = false
bPopunder = true
iLogMode = 1 ' 0 = off / 1 = log with script's name / 2 = log with input file name
' ------------------------- INIT --
' Create File System Object
Set objFso = CreateObject("Scripting.FileSystemObject")
' Argument (Quicktime .mov-File)
sInputMov = WScript.Arguments(0)
If WScript.Arguments.Count > 1 Then
iJumpTo = WScript.Arguments(1)
Else
iJumpTo = 2
End If
' Input without extension as basis for output files
' (should work if input is single file name and also if input is complete path)
sMainName = Left(sInputMov, InStrRev(SInputMov, ".") - 1)
sMainName = Right(sMainName, Len(sMainName) - InStrRev(sMainName, "\"))
' Input parent directory as basis for output files
Set objFsoMov = objFso.GetFile(sInputMov)
sMainFolder = objFsoMov.ParentFolder & "\"
sMainPrefix = sMainFolder & sMainName
sClTmpAvi = Chr(34) & sMencoder & Chr(34) & " " & Chr(34) & sMainPrefix & ".avs" & Chr(34) & _
" -o " & Chr(34) & sMainPrefix & "_hfyu.avi" & Chr(34) & _
" -of avi -forceidx -ovc lavc -nosound -lavcopts vcodec=ffvhuff:vstrict=-2:pred=2:context=1"
sClVideoPass1 = Chr(34) & sX264 & Chr(34) & " --pass 1 --bitrate 3500" & _
" --stats " & Chr(34) & sMainPrefix & "_hfyu.stats" & Chr(34) & _
" --ref 5 --mixed-refs --no-fast-pskip --bframes 3 --b-adapt 2 --b-pyramid --weightb --direct auto" & _
" --deblock -1:-1 --subme 8 --trellis 2 --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --ratetol 4.0" & _
" --me umh --merange 32 --threads auto --thread-input --sar 1:1 --progress --no-psnr --no-ssim" & _
" --output NUL " & Chr(34) & sMainPrefix & "_hfyu.avs" & Chr(34)
sClVideoPass2 = Chr(34) & sX264 & Chr(34) & "--pass 2 --bitrate 3500" & _
" --stats " & Chr(34) & sMainPrefix & "_hfyu.stats" & Chr(34) & _
" --ref 5 --mixed-refs --no-fast-pskip --bframes 3 --b-adapt 2 --b-pyramid --weightb --direct auto" & _
" --deblock -1:-1 --subme 8 --trellis 2 --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --ratetol 4.0" & _
" --me umh --merange 32 --threads auto --thread-input --sar 1:1 --progress --no-psnr --no-ssim" & _
" --output " & Chr(34) & sMainPrefix & "_onlyvideo.mkv" & Chr(34) & " " & Chr(34) & sMainPrefix & "_hfyu.avs" & Chr(34)
sClAudioEnc = Chr(34) & sFfmpeg & Chr(34) & _
" -i " & Chr(34) & sMainPrefix & ".mov" & Chr(34) & _
" -vn -ac 2 " & Chr(34) & sMainPrefix & ".aac"
sClMux = Chr(34) & sMkvmerge & Chr(34) & " -o " & Chr(34) & sMainPrefix & ".mkv" & Chr(34) & _
" --language 1:ger --track-name 1:Video --default-track 1:yes --noaudio " & Chr(34) & sMainPrefix & "_onlyvideo.mkv" & Chr(34) & _
" --engage keep_bitstream_ar_info" & _
" --language 0:ger --track-name 0:Audio --aac-is-sbr 0:1 --novideo " & Chr(34) & sMainPrefix & ".aac" & Chr(34) & _
" --track-order 0:1,1:0"
' ------------------------- PREPARE --
' Select logging mode
Select Case iLogMode
Case 0
sLogfileName = ""
Case 1
sLogfileName = WScript.ScriptFullName
Case 2
sLogfileName = sMainPrefix
Case Else
sLogfileName = ""
End Select
' Create log file
If sLogfileName <> "" Then
Set objFsoLog = objFso.CreateTextFile(sLogfileName & ".log", true)
End If
' Logging function
Public Sub subLog(sLogstring)
If iLogMode > 0 Then
objFsoLog.WriteLine(sLogstring)
End If
End Sub
subLog("nskMovToMkv v0.3 - (c) Nicolas Krzywinski, www.nskcomputing.de")
subLog(Date() & " " & Time() & " Log file opened for processing: " & Chr(34) & sInputMov & Chr(34))
subLog(" ")
' Create & Write avs files
subLog(Date() & " " & Time() & " *** Step 1 ***: Creating .avs files..")
Set objFsoAvs = objFso.CreateTextFile(sMainPrefix & ".avs", true)
objFsoAvs.WriteLine("DirectShowSource(" & Chr(34) & sMainPrefix & ".mov" & Chr(34) & ")")
objFsoAvs.Close
Set objFsoAvs = objFso.CreateTextFile(sMainPrefix & "_hfyu.avs", true)
objFsoAvs.WriteLine("AviSource(" & Chr(34) & sMainPrefix & "_hfyu.avi" & Chr(34) & ")")
objFsoAvs.Close
Set objFsoAvs = Nothing
subLog(Date() & " " & Time() & " ==> Step 1 completed: written " & Chr(34) & sMainPrefix & ".avs" & Chr(34) & " and " & Chr(34) & sMainPrefix & "_hfyu.avi" & Chr(34))
subLog(" ")
' ------------------------- RUN --
Dim objWshShell, objProcess
' Create Shell
Set objWshShell = WScript.CreateObject("wscript.shell")
' Coding Loop
For iStep = iJumpTo To 6
' What we have to do in this loop..
Select Case iStep
Case 2
sCommand = sClTmpAvi
sDesc = "Extracting .avi stream.."
sDelete1 = ".avs"
sDelete2 = ""
sSuffix = "_hfyu.avi"
Case 3
sCommand = sClVideoPass1
sDesc = "Encoding first pass.."
sDelete1 = ""
sDelete2 = ""
sSuffix = "_hfyu.stats"
Case 4
sCommand = sClVideoPass2
sDesc = "Encoding second pass.."
sDelete1 = "_hfyu.avi"
sDelete2 = "_hfyu.avs"
sSuffix = "_onlyvideo.mkv"
Case 5
sCommand = sClAudioEnc
sDesc = "Encoding audio.."
sDelete1 = "_hfyu.stats"
sDelete2 = ""
sSuffix = ".aac"
Case 6
sCommand = sClMux
sDesc = "Muxing video and audio stream.."
sDelete1 = "_onlyvideo.mkv"
sDelete2 = ".aac"
sSuffix = ".mkv"
Case Else
sCommand = ""
sDelete1 = ""
sDelete2 = ""
sSuffix = ""
End Select
' Talk about what we wanna do
subLog(Date() & " " & Time() & " *** Step " & iStep & " ***: " & sDesc)
subLog(" Command Line: " & sCommand)
' Select new window mode
If bPopunder Then
iWindowMode = 7
Else
iWindowMode = 1
End If
' Execute
'Set objProcess = objWshShell.Exec(sClTmpAvi)
if sCommand <> "" Then
iReturn = objWshShell.Run(sCommand, iWindowMode, true)
Else
iReturn = "Illegal loop"
End If
' Talk a bit what happened
'subLog("Created process " & objProcess.ProcessID & " and it tells me: " & objProcess.Status & " (Status), " & objProcess.ExitCode & " (ExitCode)")
if iReturn = 0 Then
subLog(Date() & " " & Time() & " ==> Step " & iStep & " completed: written " & Chr(34) & sMainPrefix & sSuffix & Chr(34))
Else
subLog(Date() & " " & Time() & " ==> Step " & iStep & " FAILURE (Return Code: " & iReturn & ") <==")
End If
' Delete intermediate files
If sDelete1 <> "" And bDeleteIntermediateFiles Then
If objFso.FileExists(sMainPrefix & sDelete1) Then
objFso.DeleteFile(sMainPrefix & sDelete1)
subLog(Date() & " " & Time() & " Deleted intermediate file: " & Chr(34) & sMainPrefix & sDelete1 & Chr(34))
Else
subLog(Date() & " " & Time() & " Could not delete intermediate file: " & Chr(34) & sMainPrefix & sDelete1 & Chr(34))
End If
End If
If sDelete2 <> "" And bDeleteIntermediateFiles Then
If objFso.FileExists(sMainPrefix & sDelete2) Then
objFso.DeleteFile(sMainPrefix & sDelete2)
subLog(Date() & " " & Time() & " Deleted intermediate file: " & Chr(34) & sMainPrefix & sDelete2 & Chr(34))
Else
subLog(Date() & " " & Time() & " Could not delete intermediate file: " & Chr(34) & sMainPrefix & sDelete2 & Chr(34))
End If
End If
subLog(" ")
Next
'while objProcess.Status = 0
' WScript.Sleep(500)
'wend
'while(!Pipe.StdOut.AtEndOfStream)
'WScript.StdOut.WriteLine(Pipe.StdOut.ReadLine())
' ------------------------- CLEAN --
subLog("I'm done .. bye!")
' Objekte freigeben
Set objProcess = Nothing
Set objWshShell = Nothing
Set objFsoMov = Nothing
If isObject(objFsoLog) Then
objFsoLog.Close
End If
Set objFsoLog = Nothing
Set objFso = Nothing
If bEndMessage Then
WScript.Echo "nskMovToMkv: Finished encoding " & Chr(34) & sMainName & ".mkv" & Chr(34)
End If