home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2007-10-10 | 157.8 KB | 4,983 lines
'***************************************************************************** ' ' Microsoft Windows Media ' Copyright (C) Microsoft Corporation. All rights reserved. ' ' FileName: WMCMD.VBS ' ' Abstract: Windows Media Encoder Command Line Script Utility ' Use Cscript.exe wmcmd.vbs /? for Help ' ' Last Update: October 11, 2007 ' ' Visit http://www.citizeninsomniac.com/WMV for latest (unofficial) updates. '***************************************************************************** Option Explicit ' Check to see if script is run within cscript host. if instr( LCase(WScript.Fullname),"cscript.exe" ) = 0 then dim WshShell set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Popup "This script must be run using cscript.exe from a command window." , 0 , "Windows Media Encoder Command Line Script Utility" , 64 WScript.Quit() end if ' These variables are part of encoder idl. However vbs cannot use them directly. So these are redefined dim WMENC_ENCODER_STARTING dim WMENC_ENCODER_RUNNING dim WMENC_ENCODER_PAUSED dim WMENC_ENCODER_STOPPING dim WMENC_ENCODER_STOPPED dim WMENC_ENCODER_END_PREPROCESS dim WMENC_ARCHIVE_LOCAL dim WMENC_ARCHIVE_RUNNING dim WMENC_ARCHIVE_PAUSED dim WMENC_ARCHIVE_STOPPED dim WMENC_AUDIO dim WMENC_VIDEO dim WMENC_SCRIPT dim WMENC_FILETRANSFER dim WMENC_SOURCE_START dim WMENC_SOURCE_STOP dim WMENC_SOURCE_PREPARE dim WMENC_SOURCE_UNPREPARE dim WMENC_START_FILETRANSFER dim WMENC_STOP_FILETRANSFER dim WMENC_PROTOCOL_HTTP dim WMENC_PROTOCOL_PUSH_DISTRIBUTION dim WMENC_PVM_NONE dim WMENC_PVM_PEAK dim WMENC_PVM_UNCONSTRAINED dim WMENC_PVM_BITRATE_BASED dim WMASTD_FOURCC dim WMAPRO_FOURCC dim WMALSL_FOURCC dim WMSPEECH_FOURCC dim PCM_FOURCC dim WMV7_FOURCC dim WMV8_FOURCC dim WMV9_FOURCC dim WVC1_FOURCC dim WMS9_FOURCC dim MP41_FOURCC dim UNCOMP_FOURCC dim WMASTD dim WMAPRO dim WMALSL dim WMSPEECH dim PCM dim WMV7 dim WMV8 dim WMV9 dim WVC1 dim WMS9 dim MP41 dim UNCOMP dim WMENC_CONTENT_ONE_AUDIO dim WMENC_CONTENT_ONE_VIDEO dim WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO dim WMENC_VIDEO_STANDARD dim WMENC_VIDEO_DEINTERLACE dim WMENC_VIDEO_INVERSETELECINE dim WMENC_VIDEO_PROCESS_INTERLACED dim WMENC_VIDEO_TELECINE_AUTO dim WMENC_VIDEO_TELECINE_AA_TOP dim WMENC_VIDEO_TELECINE_BB_TOP dim WMENC_VIDEO_TELECINE_BC_TOP dim WMENC_VIDEO_TELECINE_CD_TOP dim WMENC_VIDEO_TELECINE_DD_TOP dim WMENC_VIDEO_TELECINE_AA_BOTTOM dim WMENC_VIDEO_TELECINE_BB_BOTTOM dim WMENC_VIDEO_TELECINE_BC_BOTTOM dim WMENC_VIDEO_TELECINE_CD_BOTTOM dim WMENC_VIDEO_TELECINE_DD_BOTTOM dim WMENC_VIDEO_INTERLACED_AUTO dim WMENC_VIDEO_INTERLACED_TOP_FIRST dim WMENC_VIDEO_INTERLACED_BOTTOM_FIRST dim WMENC_PIXELFORMAT_IYUV dim WMENC_PIXELFORMAT_I420 dim WMENC_PIXELFORMAT_YV12 dim WMENC_PIXELFORMAT_YUY2 dim WMENC_PIXELFORMAT_UYVY dim WMENC_PIXELFORMAT_YVYU dim WMENC_PIXELFORMAT_YVU9 dim WMENC_PIXELFORMAT_RGB24 dim WMENC_PIXELFORMAT_RGB32 dim WMENC_PIXELFORMAT_RGB555 dim WMENC_PIXELFORMAT_RGB565 dim WMENC_PIXELFORMAT_RGB8 WMENC_ENCODER_STARTING = 1 WMENC_ENCODER_RUNNING = 2 WMENC_ENCODER_PAUSED = 3 WMENC_ENCODER_STOPPING = 4 WMENC_ENCODER_STOPPED = 5 WMENC_ENCODER_END_PREPROCESS = 6 WMENC_ARCHIVE_LOCAL = 1 WMENC_ARCHIVE_RUNNING = 1 WMENC_ARCHIVE_PAUSED = 2 WMENC_ARCHIVE_STOPPED = 3 WMENC_AUDIO = 1 WMENC_VIDEO = 2 WMENC_SCRIPT = 4 WMENC_FILETRANSFER = 8 WMENC_SOURCE_START = 1 WMENC_SOURCE_STOP = 2 WMENC_SOURCE_PREPARE = 3 WMENC_SOURCE_UNPREPARE = 4 WMENC_START_FILETRANSFER = 5 WMENC_STOP_FILETRANSFER = 6 WMENC_PROTOCOL_HTTP = 1 WMENC_PROTOCOL_PUSH_DISTRIBUTION = 2 WMENC_PVM_NONE = 1 WMENC_PVM_PEAK = 2 WMENC_PVM_UNCONSTRAINED = 3 WMENC_PVM_BITRATE_BASED = 4 WMASTD_FOURCC = 353 WMAPRO_FOURCC = 354 WMALSL_FOURCC = 355 WMSPEECH_FOURCC = 10 PCM_FOURCC = 0 WMV7_FOURCC = 827739479 WMV8_FOURCC = 844516695 WMV9_FOURCC = 861293911 WVC1_FOURCC = 826496599 WMS9_FOURCC = 844321613 MP41_FOURCC = 1395937357 UNCOMP_FOURCC = 0 WMASTD = "WMASTD" WMAPRO = "WMAPRO" WMALSL = "WMALSL" WMSPEECH = "WMSP" PCM = "PCM" WMV7 = "WMV7" WMV8 = "WMV8" WMV9 = "WMV9" WVC1 = "WVC1" WMS9 = "WMS9" MP41 = "MP41" UNCOMP = "UNCOMP" WMENC_CONTENT_ONE_AUDIO = 1 WMENC_CONTENT_ONE_VIDEO = 16 WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO = 17 WMENC_VIDEO_STANDARD = 1 WMENC_VIDEO_DEINTERLACE = 2 WMENC_VIDEO_INVERSETELECINE = 3 WMENC_VIDEO_PROCESS_INTERLACED = 4 WMENC_VIDEO_TELECINE_AA_TOP = &H23 WMENC_VIDEO_TELECINE_BB_TOP = &H33 WMENC_VIDEO_TELECINE_BC_TOP = &H43 WMENC_VIDEO_TELECINE_CD_TOP = &H53 WMENC_VIDEO_TELECINE_DD_TOP = &H63 WMENC_VIDEO_TELECINE_AA_BOTTOM = &H73 WMENC_VIDEO_TELECINE_BB_BOTTOM = &H83 WMENC_VIDEO_TELECINE_BC_BOTTOM = &H93 WMENC_VIDEO_TELECINE_CD_BOTTOM = &HA3 WMENC_VIDEO_TELECINE_DD_BOTTOM = &HB3 WMENC_VIDEO_INTERLACED_AUTO = 4 WMENC_VIDEO_INTERLACED_TOP_FIRST = &H2004 WMENC_VIDEO_INTERLACED_BOTTOM_FIRST = &H3004 WMENC_PIXELFORMAT_IYUV = &H56555949 WMENC_PIXELFORMAT_I420 = &H30323449 WMENC_PIXELFORMAT_YV12 = &H32315659 WMENC_PIXELFORMAT_YUY2 = &H32595559 WMENC_PIXELFORMAT_UYVY = &H59565955 WMENC_PIXELFORMAT_YVYU = &H55595659 WMENC_PIXELFORMAT_YVU9 = &H39555659 WMENC_PIXELFORMAT_RGB24 = &HE436EB7D WMENC_PIXELFORMAT_RGB32 = &HE436EB7E WMENC_PIXELFORMAT_RGB555 = &HE436EB7C WMENC_PIXELFORMAT_RGB565 = &HE436EB7B WMENC_PIXELFORMAT_RGB8 = &HE436EB7A dim g_strProductName dim g_strProductCopyright dim g_strInput dim g_strAudioInput dim g_strOutput dim g_strOutputString dim g_intSessionType dim g_strProfile dim g_strTitle dim g_strAlbum dim g_strGenre dim g_intTrackNo dim g_strYear dim g_strAuthor dim g_strCopyright dim g_strDescription dim g_strRating dim g_strWMEFile dim g_strProfileSave dim g_strProfileLoad dim g_strVideoEncoderRegistryKey dim g_strLogFile dim g_intAudioDevice dim g_intVideoDevice dim g_intProfile dim g_intBroadcast dim g_strPushServer dim g_strPublishingPoint dim g_strPushTemplate dim g_intMarkInTime dim g_intMarkOutTime dim g_intDuration dim g_intVerbose dim g_intAudioSourceDuration dim g_intVideoSourceDuration dim g_objEncoder dim g_objSourceGroup dim g_objAudioSource dim g_objVideoSource dim g_objProfile dim g_objFileSystem dim g_objWshShell dim g_objLogFile dim g_blnEncoderStarted dim g_blnEndPreProcess dim g_blnEncoderStopped dim g_intErrorCode dim g_intRunningSource dim g_blnDevice dim g_blnAudioOnly dim g_blnVideoOnly dim g_blnSilent dim g_blnDurationError dim g_blnLogOutput dim g_intAudioVBRMode dim g_strAudioCodec dim g_strAudioSetting dim g_intAudioPeakBitrate dim g_intAudioPeakBuffer dim g_intAudioSpeechContent dim g_strAudioSpeechEdl dim g_intAudioSurroundMix dim g_intAudioCenterMix dim g_intAudioLEFMix dim g_strAudioCodecName dim g_intVideoVBRMode dim g_strVideoCodec dim g_intVideoBitrate dim g_intVideoWidth dim g_intVideoHeight dim g_intVideoFramerate dim g_intVideoKeydist dim g_intVideoBuffer dim g_intVideoQuality dim g_intVideoQP dim g_intVideoPeakBitrate dim g_intVideoPeakBuffer dim g_intVideoPreprocess dim g_strPixelFormat dim g_intPixelAspectRatioX dim g_intPixelAspectRatioY dim g_intVideoPerformance dim g_strVideoCodecName dim g_strVideoDevConf dim g_intMaxPacketSize dim g_intMinPacketSize dim g_intVideoCompOpt dim g_intVideoDenoise dim g_intVideoDquantOption dim g_intVideoDquantStrength dim g_intVideoBDeltaQP dim g_intVideoLoopfilter dim g_intVideoMedian dim g_intVideoEdgeRemoval dim g_intVideoNumThreads dim g_intVideoRangeRedux dim g_intVideoOverlap dim g_intVideoScaling dim g_intVideoLookahead dim g_intVideoLookaheadRC dim g_intVideoMBModeCost dim g_intVideoMMatch dim g_intVideoMSLevel dim g_intVideoMSRange dim g_intVideoMVCoding dim g_intVideoMVCost dim g_intVideoBFrameDist dim g_intVideoPercOpt dim g_intVideoType dim g_intVideoCodedWidth dim g_intVideoCodedHeight dim g_strVideoPreset dim g_intVideoThreadAffinity dim g_EncoderRegSettings(30, 1) dim i dim j dim g_blnCreateCustomProfile dim g_tStartTime dim g_tStopTime dim g_intClipLeft dim g_intClipRight dim g_intClipTop dim g_intClipBottom g_objLogFile = Null g_strProductName = "Microsoft (R) Windows Media Encoder Command Line Script Utility" g_strProductCopyright = "Copyright (C) Microsoft Corporation. All rights reserved." g_strInput = "" g_strAudioInput = "" g_strOutput = "" g_strOutputString = "" g_intSessionType = WMENC_CONTENT_ONE_AUDIO g_strProfile = "" g_strTitle = "" g_strAuthor = "" g_strAlbum = "" g_intTrackNo = "" g_strYear = "" g_strGenre = "" g_strCopyright = "" g_strDescription = "" g_strRating = "" g_strWMEFile = "" g_strProfileSave = "" g_strProfileLoad = "" g_strProfile = "" g_strVideoEncoderRegistryKey = "HKCU\Software\Microsoft\Scrunch\WMVideo" g_intAudioDevice = -1 g_intVideoDevice = -1 g_intProfile = -1 g_intBroadcast = -1 g_strPushServer = "" g_strPublishingPoint = "" g_strPushTemplate = "" g_intMarkInTime = -1 g_intMarkOutTime = -1 g_intDuration = -1 g_intVerbose = 2 g_intAudioSourceDuration = -1 g_intVideoSourceDuration = -1 g_blnEncoderStarted = false g_blnEncoderStopped = false g_blnEndPreProcess = false g_blnDevice = false g_intErrorCode = 0 g_intRunningSource = 0 g_blnAudioOnly = false g_blnVideoOnly = false g_blnDurationError = false g_blnLogOutput = false g_intAudioVBRMode = -1 g_strAudioCodec = "" g_strAudioSetting = "" g_intAudioPeakBitrate = -1 g_intAudioPeakBuffer = -1 g_intAudioSpeechContent = -1 g_strAudioSpeechEdl = "" g_intAudioSurroundMix = -1 g_intAudioCenterMix = -1 g_intAudioLEFMix = -1 g_strAudioCodecName = "" g_intVideoVBRMode = -1 g_strVideoCodec = "" g_intVideoBitrate = -1 g_intVideoWidth = -1 g_intVideoHeight = -1 g_intVideoFramerate = -1 g_intVideoKeydist = -1 g_intVideoBuffer = -1 g_intVideoQuality = -1 g_intVideoQP = -1 g_intVideoPeakBitrate = -1 g_intVideoPeakBuffer = -1 g_intVideoPreprocess = -1 g_strPixelFormat = "" g_intPixelAspectRatioX = -1 g_intPixelAspectRatioY = -1 g_intVideoPerformance = -1 g_strVideoCodecName = "" g_strVideoDevConf = "" g_intMaxPacketSize = -1 g_intMinPacketSize = -1 g_intVideoCompOpt = -128 g_intVideoDenoise = -128 g_intVideoDquantOption = -128 g_intVideoDquantStrength = -128 g_intVideoBDeltaQP = -128 g_intVideoLoopfilter = -128 g_intVideoMedian = -128 g_intVideoEdgeRemoval = -128 g_intVideoNumThreads = -128 g_intVideoRangeRedux = -128 g_intVideoOverlap = -128 g_intVideoScaling = -128 g_intVideoLookahead = -128 g_intVideoLookaheadRC = -128 g_intVideoMBModeCost = -128 g_intVideoMMatch = -128 g_intVideoMSLevel = -128 g_intVideoMSRange = -128 g_intVideoMVCoding = -128 g_intVideoMVCost = -128 g_intVideoBFrameDist = -128 g_intVideoPercOpt = -128 g_intVideoType = -128 g_intVideoCodedWidth = -128 g_intVideoCodedHeight = -128 g_strVideoPreset = "" g_intVideoThreadAffinity = -128 for i = 0 to 30 g_EncoderRegSettings(i,0) = "" g_EncoderRegSettings(i,1) = -128 next g_intClipLeft = -1 g_intClipRight = -1 g_intClipTop = -1 g_intClipBottom = -1 g_blnCreateCustomProfile = true ' Create an encoder object. on error resume next set g_objEncoder = WScript.CreateObject( "WMEncEng.WMEncoder" ) if not isObject(g_objEncoder) then OutputInfo "Error: Cannot initialize Windows Media Encoder object. Please verify that" OutputInfo "Windows Media Encoder 9 Series is correctly installed on your system." OutputInfo "If running 64-bit Windows, make sure that the version of cscript.exe used" OutputInfo "corresponds to the version (x86/x64) of WME9 installed on your system." WScript.Quit() end if On Error Goto 0 WScript.ConnectObject g_objEncoder, "Encoder_" ' Setup call back events set g_objFileSystem = WScript.CreateObject( "Scripting.FileSystemObject" ) set g_objWshShell = WScript.CreateObject("WScript.Shell") g_objSourceGroup = Null g_objAudioSource = Null g_objVideoSource = Null g_objProfile = NULL ' Read a integer value from the paramters list. ' args is the paramters list to be read. ' intIndex1 is the position of the parameter name. ' intIndex2 is the position of the parameter value. ' It will return the integer if it can read a integer value from the parameter list ' It will return -1 if it can not get a integer value from the paramters list. function ReadInteger( args, intIndex1, intIndex2 ) on error resume next dim strTypeName ' Check the range of index. if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then OutputInfo "Invalid format for parameter " & args(intIndex1) ReadInteger = -1 exit function end if strTypeName = typename( eval( args(intIndex2) ) ) ' Convert it to an integer value. ReadInteger = CLng( args(intIndex2) ) ' The value is not in integer fommat. if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" ) then OutputInfo "Expect integer value for parameter " & args(intIndex1) ReadInteger = -1 err.Clear end if end function ' Read a float value from the paramters list. ' args is the paramters list to be read. ' intIndex1 is the position of the parameter name. ' intIndex2 is the position of the parameter value. ' It will return the float if it can read a float value from the parameter list ' It will return -1 if it can not get a float value from the paramters list. function ReadFloat( args, intIndex1, intIndex2 ) on error resume next dim strTypeName ' Check the range of index. if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then OutputInfo "Invalid format for parameter " & args(intIndex1) ReadFloat = -1 exit function end if strTypeName = typename( eval( args(intIndex2) ) ) ' Convert it to an integer value. ReadFloat = CSng( args(intIndex2) ) ' The value is not in integer fommat. if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" and strTypeName <> "Single" and strTypeName <> "Double" ) then OutputInfo "Expect float value for parameter " & args(intIndex1) ReadFloat = -1 err.Clear end if end function ' Read a var value from the paramters list. ' args is the paramters list to be read. ' intIndex1 is the position of the parameter name. ' intIndex2 is the position of the parameter value. ' It will return the var if it can not get a var value from the paramters list. ' It will return "" if it can not get a var value from the paramters list. function ReadString( args, intIndex1, intIndex2 ) ' Check the range of index. if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then OutputInfo "Invalid format for parameter " & args(intIndex1) ReadString = "" exit function end if ReadString = args(intIndex2) end function function ConvertStringToInteger( strInput ) on error resume next dim strTypeName strTypeName = typename( eval( strInput ) ) ' Convert it to an integer value. ConvertStringToInteger = CLng( strInput ) ' The value is not in integer fommat. if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" ) then OutputInfo "Invalid format " & strInput & " expecting integer value" ConvertStringToInteger = -1 err.Clear end if end function ' Parse parameters. if wscript.arguments.Length = 0 then ShowHelp() wscript.quit() end if dim colStrArgs() reDim colStrArgs( wscript.arguments.Length-1 ) for i = 0 to wscript.arguments.Length-1 colStrArgs(i) = wscript.arguments(i) next if ParseParameters( colStrArgs ) then ' Do different things depending on whether input is wme, directory encoding or file encoding if g_strInput <> "" and g_objFileSystem.FolderExists(g_strInput) then DoDirectoryModeEncoding() elseif SetupEncoder() then ' Transcode and show statistics information if Transcode() and not g_blnSilent then ShowStatistics() end if end if else OutputInfo "Command-line parsing completed." end if if not IsNull(g_objLogFile) then g_objLogFile.Close end if ' Some input sources are known to cause the script engine to hang ' Forcefully terminate this script TerminateEncoderProcess() WScript.Quit() ' Output information function OutputInfo( strInfo ) WScript.Echo( strInfo ) if g_blnLogOutput then g_objLogFile.WriteLine( strInfo ) end if end function ' Event handler for encoder state function Encoder_OnStateChange( enumState ) dim strState ' Translate encoder state select case enumState case WMENC_ENCODER_STARTING strState = "Starting" case WMENC_ENCODER_RUNNING strState = "Running" g_blnEncoderStarted = true case WMENC_ENCODER_PAUSED strState = "Paused" case WMENC_ENCODER_STOPPING strState = "Stopping" case WMENC_ENCODER_STOPPED g_tStopTime = Now() strState = "Stopped" g_blnEncoderStopped = true case WMENC_ENCODER_END_PREPROCESS strState = "End Preprorocess" g_blnEndPreProcess = true case else strState = "Unknown State" end select Encoder_OnStateChange = 1 end function ' Event handler for encoder error function Encoder_OnError( intResult ) g_intErrorCode = intResult Encoder_OnError = 0 end function function IsEncoderRegistryDirty() On Error Resume Next dim bDirtyFlag dim regDirtyFlag bDirtyFlag = false regDirtyFlag = g_objWshShell.RegRead(g_strVideoEncoderRegistryKey & "\WMCmdDirtyFlag") if err <> 0 then bDirtyFlag = false else if regDirtyFlag = 1 then bDirtyFlag = true else bDirtyFlag = false end if end if IsEncoderRegistryDirty = bDirtyFlag end function function SaveEncoderRegistrySettings() On Error Resume Next g_EncoderRegSettings(0,0) = "\Compression Optimization Type" g_EncoderRegSettings(1,0) = "\DenoiseOption" g_EncoderRegSettings(2,0) = "\Dquant Option" g_EncoderRegSettings(3,0) = "\Dquant Strength" g_EncoderRegSettings(4,0) = "\Force B Frame Delta QP" g_EncoderRegSettings(5,0) = "\Force Encoding Width" g_EncoderRegSettings(6,0) = "\Force Encoding Height" g_EncoderRegSettings(7,0) = "\Force LoopFilter" g_EncoderRegSettings(8,0) = "\Force Median" g_EncoderRegSettings(9,0) = "\Force NoiseEdgeRemoval" g_EncoderRegSettings(10,0) = "\Force NumThreads" g_EncoderRegSettings(11,0) = "\Force Range Reduction" g_EncoderRegSettings(12,0) = "\Force Overlap" g_EncoderRegSettings(13,0) = "\Force Video Scaling" g_EncoderRegSettings(14,0) = "\Lookahead" g_EncoderRegSettings(15,0) = "\Lookahead Ratecontrol" g_EncoderRegSettings(16,0) = "\Macroblock Mode Cost Method" g_EncoderRegSettings(17,0) = "\Motion Match Method" g_EncoderRegSettings(18,0) = "\Motion Search Level" g_EncoderRegSettings(19,0) = "\Motion Search Range" g_EncoderRegSettings(20,0) = "\Motion Vector Coding Method" g_EncoderRegSettings(21,0) = "\Motion Vector Cost Method" g_EncoderRegSettings(22,0) = "\NumBFrames" g_EncoderRegSettings(23,0) = "\Perceptual Option" g_EncoderRegSettings(24,0) = "\VideoType" g_EncoderRegSettings(25,0) = "\Encoder Thread Affinity" for i = 0 to 25 g_EncoderRegSettings(i,1) = g_objWshShell.RegRead(g_strVideoEncoderRegistryKey & g_EncoderRegSettings(i,0)) next On Error Goto 0 end function function RestoreEncoderRegistrySettings() On Error Resume Next for i = 0 to 30 if (g_EncoderRegSettings(i,0) <> "") and (g_EncoderRegSettings(i,1) <> -128) then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & g_EncoderRegSettings(i,0), g_EncoderRegSettings(i,1), "REG_DWORD" end if next On Error Goto 0 end function ' Deletes WVC1 encoder parameters from the registry function ClearEncoderRegistrySettings() On Error Resume Next g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Compression Optimization Type" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\DenoiseOption" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Dquant Option" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Dquant Strength" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force B Frame Delta QP" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force Encoding Width" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force Encoding Height" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force LoopFilter" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force Median" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force NoiseEdgeRemoval" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force NumThreads" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force Range Reduction" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force Overlap" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Force Video Scaling" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Lookahead" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Lookahead Ratecontrol" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Macroblock Mode Cost Method" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Motion Match Method" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Motion Search Level" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Motion Search Range" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Motion Vector Coding Method" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Motion Vector Cost Method" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\NumBFrames" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Perceptual Option" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\VideoType" g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\Encoder Thread Affinity" On Error Goto 0 end function ' Parse the parameters of this program. function ParseParameters( args ) dim reParser dim colMatches dim strMarkOutTime dim strArguments, strArgumentsQuoted dim strSaveToCfgFile dim strLoadFromCfgFile dim strCfgFileArguments dim colStrConfigArgs dim objTextFile dim intVideoRangeReduxYR, intVideoRangeReduxYE, intVideoRangeReduxCR, intVideoRangeReduxCE dim intArgIndex ' First traverse of the arguments just checks for config saving and loading args for intArgIndex=0 to UBound(args) if args(intArgIndex) = "-s_config" then intArgIndex = intArgIndex + 1 else if InStr(args(intArgIndex)," ") > 0 then strArgumentsQuoted = strArgumentsQuoted & Chr(34) & args(intArgIndex) & Chr(34) & " " else strArgumentsQuoted = strArgumentsQuoted & args(intArgIndex) & " " end if strArguments = strArguments & args(intArgIndex) & " " end if if args(intArgIndex) = "-config" then strLoadFromCfgFile = ReadString( args, intArgIndex, intArgIndex+1 ) if strLoadFromCfgFile = "" then ParseParameters = false exit function end if intArgIndex = intArgIndex + 1 strLoadFromCfgFile = g_objFileSystem.GetAbsolutePathName( strLoadFromCfgFile ) set objTextFile = g_objFileSystem.OpenTextFile( strLoadFromCfgFile, 1 ) strCfgFileArguments = objTextFile.ReadLine objTextFile.Close strCfgFileArguments = Trim( strCfgFileArguments ) if strCfgFileArguments = "" then OutputInfo "Configuration file " & strLoadFromCfgFile & " is empty." ParseParameters = false exit function end if ' Splits the argument string into an array using space as separator but respecting quotes set reParser = New RegExp reParser.Pattern = "\s*(" & Chr(34) & "([^" & Chr(34) & "]*)" & Chr(34) & "|([^" & " " & "]+))\s*" reParser.Global = true set colMatches = reParser.Execute(strCfgFileArguments) ReDim colStrConfigArgs(colMatches.Count - 1) for j=0 to colMatches.Count - 1 colStrConfigArgs(j) = Replace(Trim(colMatches(j).Value), Chr(34), "") next set reParser = nothing set colMatches = nothing if ParseParameters( colStrConfigArgs ) = false then ParseParameters = false exit function end if end if next 'OutputInfo "Args = " & strArguments 'OutputInfo "ArgsQuoted = " & strArgumentsQuoted if UBound(args) = 0 then ' If it has only has one parameter, check the content of this parameter. select case LCase( args(0) ) case "-devices": ' List all audio and video devices. ListDevices() ParseParameters = false exit function case "-a_codecs": ' List all audio codecs. ListAudioCodecs() ParseParameters = false exit function case "-a_formats" ' List audio formats ListAudioFormats() ParseParameters = false exit function case "-v_codecs": ' List all video codecs. ListVideoCodecs() ParseParameters = false exit function case "-help": ' Show help information. ShowHelp() ParseParameters = false exit function case "-?": ' Show help information. ShowHelp() ParseParameters = false exit function case "-all?": ' Show help information. ShowHelp() ParseParameters = false exit function case "/?": ' Show help information. ShowHelp() ParseParameters = false exit function end select end if if UBound(args) = 1 then select case LCase( args(0) ) case "-input" ' Print out info about file specified g_strInput = ReadString( args, 0, 1 ) if g_strInput = "" then ParseParameters = false exit function end if PrintFileInfo() ParseParameters = false exit function case "-log" ' Print all output to log file OutputInfo "Log file can only be used with a valid encoding session." ParseParameters = false exit function end select end if ' Check all parameters. for i=0 to UBound(args) select case LCase( args(i) ) ' Parse all input related stuff case "-wme" ' Get the WME file name to be load. g_strWMEFile = ReadString( args, i, i+1 ) if g_strWMEFile = "" then ParseParameters = false exit function end if i = i + 1 case "-input" ' Get input source file name. g_strInput = ReadString( args, i, i+1 ) if g_strInput = "" then ParseParameters = false exit function end if i = i + 1 case "-audioonly" g_blnAudioOnly = true case "-videoonly" g_blnVideoOnly = true case "-adevice" g_blnDevice = true ' Get audio device index. if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then g_intAudioDevice = ReadInteger( args, i, i+1 ) if g_intAudioDevice = -1 then ParseParameters = false exit function end if i = i + 1 else g_intAudioDevice = 0 ' default audio device end if case "-vdevice" g_blnDevice = true ' Get video device index. if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then g_intVideoDevice = ReadInteger( args, i, i+1 ) if g_intVideoDevice = -1 then ParseParameters = false exit function end if i = i + 1 else g_intVideoDevice = 0 ' default video device end if ' Parse all profile related stuff case "-profile" ' Get input source file name. g_strProfile = ReadString( args, i, i+1 ) if g_strProfile = "" then ParseParameters = false exit function end if i = i + 1 ' Parse audio related stuff case "-a_input" ' Get alternate audio input source file name. g_strAudioInput = ReadString( args, i, i+1 ) if g_strAudioInput = "" then ParseParameters = false exit function end if i = i + 1 case "-a_mode" g_intAudioVBRMode = ReadInteger( args, i, i+1 ) if g_intAudioVBRMode = -1 then ParseParameters = false exit function end if i = i + 1 case "-a_codec" 'Get audio codec name g_strAudioCodec = ReadString( args, i, i+1 ) g_strAudioCodec = UCase( g_strAudioCodec ) if g_strAudioCodec = "WMA9STD" then g_strAudioCodec = "WMASTD" if g_strAudioCodec = "WMA9PRO" then g_strAudioCodec = "WMAPRO" if g_strAudioCodec = "WMA9LSL" then g_strAudioCodec = "WMALSL" if g_strAudioCodec = "WMSP9" then g_strAudioCodec = "WMSP9" if g_strAudioCodec <> WMASTD and g_strAudioCodec <> WMAPRO and g_strAudioCodec <> WMALSL and g_strAudioCodec <> WMSPEECH and g_strAudioCodec <> PCM then OutputInfo "Please enter correct audio codec index only" ParseParameters = false exit function end if if g_strAudioCodec = "" then ParseParameters = false exit function end if i = i + 1 case "-a_setting" 'Get audio setting g_strAudioSetting = ReadString( args, i, i+1 ) if g_strAudioSetting = "" then ParseParameters = false exit function end if i = i + 1 case "-a_peakbitrate" 'Get audio peakbitrate size g_intAudioPeakBitrate = ReadInteger( args, i, i+1 ) if g_intAudioPeakBitrate = -1 then ParseParameters = false exit function end if i = i + 1 case "-a_peakbuffer" 'Get audio peakbuffer size g_intAudioPeakBuffer = ReadInteger( args, i, i+1 ) if g_intAudioPeakBuffer = -1 then ParseParameters = false exit function end if i = i + 1 case "-a_content" 'Get content type for speech g_intAudioSpeechContent = ReadInteger( args, i, i+1 ) if g_intAudioSpeechContent = -1 then ParseParameters = false exit function elseif g_intAudioSpeechContent < 0 or g_intAudioSpeechContent > 2 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-a_contentedl" 'Get EDL file for speech content g_strAudioSpeechEdl = ReadString( args, i, i+1 ) if g_strAudioSpeechEdl = "" then ParseParameters = false exit function end if i = i + 1 case "-a_folddown6to2" 'Get EDL file for speech content g_intAudioSurroundMix = ReadInteger( args, i, i+1 ) if g_intAudioSurroundMix = -1 then ParseParameters = false exit function end if g_intAudioCenterMix = ReadInteger( args, i, i+2 ) if g_intAudioCenterMix = -1 then ParseParameters = false exit function end if g_intAudioLEFMix = ReadInteger( args, i, i+3 ) if g_intAudioLEFMix = -1 then ParseParameters = false exit function end if i = i + 3 ' Parse video related stuff case "-v_mode" g_intVideoVBRMode = ReadInteger( args, i, i+1 ) if g_intVideoVBRMode = -1 then ParseParameters = false exit function end if i = i + 1 case "-v_codec" 'Get video codec name g_strVideoCodec = ReadString( args, i, i+1 ) g_strVideoCodec = UCase( g_strVideoCodec ) if g_strVideoCodec <> WMV7 and g_strVideoCodec <> WMV8 and g_strVideoCodec <> WMV9 and g_strVideoCodec <> WVC1 and g_strVideoCodec <> WMS9 and g_strVideoCodec <> UNCOMP and g_strVideoCodec <> MP41 then OutputInfo "Please enter correct video codec index only" ParseParameters = false exit function end if if g_strVideoCodec = "" then ParseParameters = false exit function end if i = i + 1 case "-v_bitrate" 'Get video bitrate g_intVideoBitrate = ReadInteger( args, i, i+1 ) if g_intVideoBitrate = -1 then ParseParameters = false exit function end if i = i + 1 case "-v_buffer" 'Get video buffer g_intVideoBuffer = ReadInteger( args, i, i+1 ) if g_intVideoBuffer = -1 then ParseParameters = false exit function end if i = i + 1 case "-v_width" 'Get video width g_intVideoWidth = ReadInteger( args, i, i+1 ) if g_intVideoWidth = -1 then ParseParameters = false exit function end if i = i + 1 case "-v_height" 'Get video height g_intVideoHeight = ReadInteger( args, i, i+1 ) if g_intVideoHeight = -1 then ParseParameters = false exit function end if i = i + 1 case "-v_framerate" 'Get video framerate g_intVideoFramerate = ReadFloat( args, i, i+1 ) if g_intVideoFramerate = -1 then ParseParameters = false exit function end if g_intVideoFramerate = 1000 * g_intVideoFramerate i = i + 1 case "-v_keydist" 'Get video keyframe distance g_intVideoKeydist = ReadFloat( args, i, i+1 ) if g_intVideoKeydist = -1 then ParseParameters = false exit function end if g_intVideoKeydist = 1000 * g_intVideoKeydist i = i + 1 case "-v_quality" 'Get video crispness (CBR) or quality (VBR) g_intVideoQuality = ReadInteger( args, i, i+1 ) if g_intVideoQuality = -1 then ParseParameters = false exit function end if i = i + 1 case "-v_qp" 'Get video quantizer parameter (VBR) g_intVideoQP = ReadFloat( args, i, i+1 ) if g_intVideoQP = -1 then ParseParameters = false exit function end if g_intVideoQP = Round(g_intVideoQP*2)/2 if g_intVideoQP < 1.0 or g_intVideoQP > 31.0 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_peakbitrate" 'Get video peakbitrate size g_intVideoPeakBitrate = ReadInteger( args, i, i+1 ) if g_intVideoPeakBitrate = -1 then ParseParameters = false exit function end if i = i + 1 case "-v_peakbuffer" 'Get video peakbuffer size g_intVideoPeakBuffer = ReadInteger( args, i, i+1 ) if g_intVideoPeakBuffer = -1 then ParseParameters = false exit function end if i = i + 1 case "-v_complexity" 'Get video complexity setting on codec 0-5 scale, but give v_performance priority if (g_intVideoPerformance = -1) then g_intVideoPerformance = ReadInteger( args, i, i+1 ) * 20 if g_intVideoPerformance <> 0 and g_intVideoPerformance <> 20 and g_intVideoPerformance <> 40 and g_intVideoPerformance <> 60 and g_intVideoPerformance <> 80 and g_intVideoPerformance <> 100 then ParseParameters = false exit function end if end if i = i + 1 case "-v_performance" 'Get video complexity setting on WME9 0-100 scale g_intVideoPerformance = ReadInteger( args, i, i+1 ) if g_intVideoPerformance <> 0 and g_intVideoPerformance <> 20 and g_intVideoPerformance <> 40 and g_intVideoPerformance <> 60 and g_intVideoPerformance <> 80 and g_intVideoPerformance <> 100 then ParseParameters = false exit function end if i = i + 1 case "-v_preproc" 'Get video preprocess setting g_intVideoPreprocess = ReadInteger( args, i, i+1 ) if g_intVideoPreprocess = -1 or g_intVideoPreprocess > 18 then OutputInfo "Invalid preproc value: " & args(i+1) ParseParameters = false exit function end if i = i + 1 case "-pixelformat" ' Get pixelformat. g_strPixelFormat = ReadString( args, i, i+1 ) if g_strPixelFormat = "" then ParseParameters = false exit function end if i = i + 1 case "-pixelratio" ' Get pixelformat. g_intPixelAspectRatioX = ReadInteger( args, i, i+1 ) g_intPixelAspectRatioY = ReadInteger( args, i, i+2 ) if g_intPixelAspectRatioX = -1 or g_intPixelAspectRatioY = -1 then ParseParameters = false exit function end if i = i + 2 case "-v_clip" ' Get clipping values. g_intClipLeft = ReadInteger( args, i, i+1 ) g_intClipTop = ReadInteger( args, i, i+2 ) g_intClipRight = ReadInteger( args, i, i+3 ) g_intClipBottom = ReadInteger( args, i, i+4 ) if g_intClipLeft = -1 or g_intClipTop = -1 or g_intClipRight = -1 or g_intClipBottom = -1 then ParseParameters = false exit function end if i = i + 4 case "-v_profile" ' Get video device conformance value g_strVideoDevConf = ReadString( args, i, i+1 ) g_strVideoDevConf = UCase( g_strVideoDevConf ) if g_strVideoDevConf = "SIMPLE" then g_strVideoDevConf = "SP" if g_strVideoDevConf = "MAIN" then g_strVideoDevConf = "MP" if g_strVideoDevConf = "ADVANCED" then g_strVideoDevConf = "AP" ' Translate old pre-VC1 Complex Profile to Advanced Profile if g_strVideoDevConf = "CP" then g_strVideoDevConf = "AP" if g_strVideoDevConf = "" then ParseParameters = false exit function end if i = i + 1 ' Parse advanced WMV settings case "-v_compopt" g_intVideoCompOpt = ReadInteger( args, i, i+1 ) if g_intVideoCompOpt < 0 or g_intVideoCompOpt > 2 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_denoise" g_intVideoDenoise = ReadInteger( args, i, i+1 ) if g_intVideoDenoise < 0 or g_intVideoDenoise > 5 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_dquantoption" g_intVideoDquantOption = ReadInteger( args, i, i+1 ) if g_intVideoDquantOption < 0 or g_intVideoDquantOption > 3 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_dquantstrength" g_intVideoDquantStrength = ReadInteger( args, i, i+1 ) if g_intVideoDquantStrength < 0 or g_intVideoDquantStrength > 4 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_bdeltaqp" g_intVideoBDeltaQP = ReadInteger( args, i, i+1 ) if g_intVideoBDeltaQP < 0 or g_intVideoBDeltaQP > 31 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_loopfilter" g_intVideoLoopfilter = ReadInteger( args, i, i+1 ) if g_intVideoLoopfilter < 0 or g_intVideoLoopfilter > 1 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_median" g_intVideoMedian = ReadInteger( args, i, i+1 ) if g_intVideoMedian < 0 or g_intVideoMedian > 1 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_edgeremoval" g_intVideoEdgeRemoval = ReadInteger( args, i, i+1 ) if g_intVideoEdgeRemoval < 0 or g_intVideoEdgeRemoval > 1 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_threadaffinity" g_intVideoThreadAffinity = ReadInteger( args, i, i+1 ) if g_intVideoThreadAffinity < 0 or g_intVideoThreadAffinity > 1 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_numthreads" g_intVideoNumThreads = ReadInteger( args, i, i+1 ) if g_intVideoNumThreads <> 1 and g_intVideoNumThreads <> 2 and g_intVideoNumThreads <> 4 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_rangeredux" intVideoRangeReduxYR = ReadInteger( args, i, i+1 ) intVideoRangeReduxYE = ReadInteger( args, i, i+2 ) intVideoRangeReduxCR = ReadInteger( args, i, i+3 ) intVideoRangeReduxCE = ReadInteger( args, i, i+4 ) if intVideoRangeReduxYR < 0 or intVideoRangeReduxYR > 8 or intVideoRangeReduxYE < 0 or intVideoRangeReduxYE > 8 or intVideoRangeReduxCR < 0 or intVideoRangeReduxCR > 8 or intVideoRangeReduxCE < 0 or intVideoRangeReduxCE > 8 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if 'Convert into hexadecimal 0x0Y0y0C0c format g_intVideoRangeRedux = intVideoRangeReduxYR * 16777216 + intVideoRangeReduxYE * 65536 + intVideoRangeReduxCR * 256 + intVideoRangeReduxCE i = i + 4 case "-v_overlap" g_intVideoOverlap = ReadInteger( args, i, i+1 ) if g_intVideoOverlap < 0 or g_intVideoOverlap > 1 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_scaling" g_intVideoScaling = ReadInteger( args, i, i+1 ) if g_intVideoScaling < 0 or g_intVideoScaling > 2 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_lookahead" g_intVideoLookahead = ReadInteger( args, i, i+1 ) if g_intVideoLookahead < 0 or g_intVideoLookahead > 16 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_lrc" g_intVideoLookaheadRC = ReadInteger( args, i, i+1 ) if g_intVideoLookaheadRC < 0 or g_intVideoLookaheadRC > 150 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_mbmodecost" g_intVideoMBModeCost = ReadInteger( args, i, i+1 ) if g_intVideoMBModeCost < 0 or g_intVideoMBModeCost > 1 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_mmatch" g_intVideoMMatch = ReadInteger( args, i, i+1 ) if g_intVideoMMatch < 0 or g_intVideoMMatch > 2 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if g_intVideoMMatch = g_intVideoMMatch - 1 i = i + 1 case "-v_mslevel" g_intVideoMSLevel = ReadInteger( args, i, i+1 ) if g_intVideoMSLevel < 0 or g_intVideoMSLevel > 4 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_msrange" g_intVideoMSRange = ReadInteger( args, i, i+1 ) if g_intVideoMSRange < 0 or g_intVideoMSRange > 4 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if g_intVideoMSRange = g_intVideoMSRange - 1 i = i + 1 case "-v_mvcoding" g_intVideoMVCoding = ReadInteger( args, i, i+1 ) if g_intVideoMVCoding < 0 or g_intVideoMVCoding > 3 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_mvcost" g_intVideoMVCost = ReadInteger( args, i, i+1 ) if g_intVideoMVCost < 0 or g_intVideoMVCost > 1 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_bframedist" g_intVideoBFrameDist = ReadInteger( args, i, i+1 ) if g_intVideoBFrameDist < 0 or g_intVideoBFrameDist > 7 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_percopt" g_intVideoPercOpt = ReadInteger( args, i, i+1 ) if g_intVideoPercOpt < 0 or g_intVideoPercOpt > 23 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if ' Disallow usage of old dquant which might create illegal bitstreams if g_intVideoPercOpt = 1 then g_intVideoPercOpt = 4 end if OutputInfo "Warning: -v_percopt option has been deprecated and replaced with -v_adz." OutputInfo " See help listing for more details." i = i + 1 case "-v_adz" if g_intVideoPercOpt = -128 then g_intVideoPercOpt = ReadInteger( args, i, i+1 ) if g_intVideoPercOpt < 0 or g_intVideoPercOpt > 20 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if if g_intVideoPercOpt > 0 then g_intVideoPercOpt = g_intVideoPercOpt + 3 end if end if i = i + 1 case "-v_type" g_intVideoType = ReadInteger( args, i, i+1 ) if g_intVideoType < 0 or g_intVideoType > 4 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_codedwidth" g_intVideoCodedWidth = ReadInteger( args, i, i+1 ) if g_intVideoCodedWidth < 32 or g_intVideoCodedWidth > 8192 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_codedheight" g_intVideoCodedHeight = ReadInteger( args, i, i+1 ) if g_intVideoCodedHeight < 32 or g_intVideoCodedHeight > 8192 then OutputInfo "Invalid range for parameter " & args(i) ParseParameters = false exit function end if i = i + 1 case "-v_preset" ' Get video preset g_strVideoPreset = ReadString( args, i, i+1 ) g_strVideoPreset = LCase( g_strVideoPreset ) if g_strVideoPreset = "" or ( g_strVideoPreset <> "fast" and g_strVideoPreset <> "good" and g_strVideoPreset <> "better" and g_strVideoPreset <> "best" and g_strVideoPreset <> "insane" ) then OutputInfo "Invalid preset name used. Available presets are: fast, good, better, best, insane." ParseParameters = false exit function end if select case g_strVideoPreset case "fast" ' Complexity = 2 / Lookahead = 16 / Loopfilter = On / Overlap = On / B frames = 1 if g_intVideoPerformance = -1 then g_intVideoPerformance = 40 if g_intVideoLookahead = -128 then g_intVideoLookahead = 16 if g_intVideoLoopfilter = -128 then g_intVideoLoopfilter = 1 if g_intVideoOverlap = -128 then g_intVideoOverlap = 1 if g_intVideoBFrameDist = -128 then g_intVideoBFrameDist = 1 case "good" ' Complexity = 3 / Lookahead = 16 / Loopfilter = On / B frames = 1 if g_intVideoPerformance = -1 then g_intVideoPerformance = 60 if g_intVideoLookahead = -128 then g_intVideoLookahead = 16 if g_intVideoLoopfilter = -128 then g_intVideoLoopfilter = 1 if g_intVideoBFrameDist = -128 then g_intVideoBFrameDist = 1 case "better" ' Complexity = 3 / Lookahead = 16 / Loopfilter = On / B frames = 1 / MS Level = Integer Chroma / MS Range = Auto if g_intVideoPerformance = -1 then g_intVideoPerformance = 60 if g_intVideoLookahead = -128 then g_intVideoLookahead = 16 if g_intVideoLoopfilter = -128 then g_intVideoLoopfilter = 1 if g_intVideoBFrameDist = -128 then g_intVideoBFrameDist = 1 if g_intVideoMSLevel = -128 then g_intVideoMSLevel = 1 if g_intVideoMSRange = -128 then g_intVideoMSRange = -1 case "best" ' Complexity = 5 / Lookahead = 16 / Loopfilter = On / B frames = 1 / MS Range = Auto if g_intVideoPerformance = -1 then g_intVideoPerformance = 100 if g_intVideoLookahead = -128 then g_intVideoLookahead = 16 if g_intVideoLoopfilter = -128 then g_intVideoLoopfilter = 1 if g_intVideoBFrameDist = -128 then g_intVideoBFrameDist = 1 if g_intVideoMSRange = -128 then g_intVideoMSRange = -1 case "insane" 'Complexity = 4 / Lookahead = 16 / Loopfilter = On / B frames = 1 / MS Level = True Chroma / MS Range = Auto / Motion Match = Auto if g_intVideoPerformance = -1 then g_intVideoPerformance = 80 if g_intVideoLookahead = -128 then g_intVideoLookahead = 16 if g_intVideoLoopfilter = -128 then g_intVideoLoopfilter = 1 if g_intVideoBFrameDist = -128 then g_intVideoBFrameDist = 1 if g_intVideoMSLevel = -128 then g_intVideoMSLevel = 2 if g_intVideoMSRange = -128 then g_intVideoMSRange = -1 if g_intVideoMMatch = -128 then g_intVideoMMatch = -1 end select i = i + 1 ' Parse all output related stuff case "-output" ' Get output file name. g_strOutput = ReadString( args, i, i+1 ) if g_strOutput = "" then ParseParameters = false exit function end if i = i + 1 case "-outputstring" ' Read in the string that is to be appended to output file name g_strOutputString = ReadString( args, i, i+1 ) if g_strOutputString = "" then ParseParameters = false exit function end if i = i + 1 case "-broadcast" ' Get broadcast port number. if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then g_intBroadcast = ReadInteger( args, i, i+1 ) if g_intBroadcast = -1 then ParseParameters = false exit function end if i = i + 1 else g_intBroadcast = 8080 end if case "-push" ' Get push server, pub point and template name (optional) g_strPushServer = ReadString( args, i, i+1 ) g_strPublishingPoint = ReadString( args, i, i+2 ) if g_strPushServer = "" or g_strPublishingPoint = "" then ParseParameters = false exit function end if ' Check if template name is specified if i+1 <= UBound(args) and Left( args(i+3), 1 ) <> "-" then g_strPushTemplate = ReadString( args, i, i+3 ) i = i + 3 else i = i + 2 end if case "-time" ' Get the mark in time of the source file. g_intMarkInTime = ReadInteger( args, i, i+1 ) ' Get the markout time of the source file strMarkOutTime = ReadString( args, i, i+2 ) if strMarkOutTime <> "end" then g_intMarkOutTime = ConvertStringToInteger( strMarkOutTime ) else g_intMarkOutTime = 0 end if if g_intMarkInTime = -1 or g_intMarkOutTime = -1 then ParseParameters = false exit function end if i = i + 2 case "-duration" ' Get the duration of the encoding session. g_intDuration = ReadInteger( args, i, i+1 ) if g_intDuration = -1 then ParseParameters = false exit function end if i = i + 1 case "-silent" g_blnSilent = true case "-log" ' Print all output to log file g_strLogFile = ReadString( args, i, i+1 ) if g_strLogFile <> "" then on error resume next g_strLogFile = g_objFileSystem.GetAbsolutePathname(g_strLogFile) set g_objLogFile = g_objFileSystem.CreateTextFile( g_strLogFile, true) if IsNull(g_objLogFile) then OutputInfo "Invalid log file destination." ParseParameters = false exit function else g_blnLogOutput = true end if on error goto 0 else ParseParameters = false exit function end if i = i + 1 ' Parse all attributes case "-title" ' Get the title of the output file. g_strTitle = ReadString( args, i, i+1 ) i = i + 1 case "-author" ' Get the author of the output file. g_strAuthor = ReadString( args, i, i+1 ) i = i + 1 case "-album" ' Get the album of the output file. g_strAlbum = ReadString( args, i, i+1 ) i = i + 1 case "-trackno" ' Get the track number of the output file. g_intTrackNo = ReadString( args, i, i+1 ) i = i + 1 case "-year" ' Get the year of the output file. g_strYear = ReadString( args, i, i+1 ) i = i + 1 case "-genre" ' Get the genre of the output file. g_strGenre = ReadString( args, i, i+1 ) i = i + 1 case "-copyright" ' Get the copyright information of the output file. g_strCopyright = ReadString( args, i, i+1 ) i = i + 1 case "-description" ' Get the descrption of the output file. g_strDescription = ReadString( args, i, i+1 ) i = i + 1 case "-rating" ' Get the rating of the output file. g_strRating = ReadString( args, i, i+1 ) i = i + 1 case "-saveprofile" ' Get the profile file name to be saved. g_strProfileSave = ReadString( args, i, i+1 ) if g_strProfileSave = "" then ParseParameters = false exit function end if i = i + 1 case "-loadprofile" ' Get the profile file name to be loaded. g_strProfileLoad = ReadString( args, i, i+1 ) if g_strProfileLoad = "" then ParseParameters = false exit function end if i = i + 1 case "-verbose" ' Get the verbose mode. g_intVerbose = ReadInteger( args, i, i+1 ) if g_intVerbose = -1 then ParseParameters = false exit function end if i = i + 1 case "-s_config" ' Save the WEU configuration file strSaveToCfgFile = ReadString( args, i, i+1 ) if strSaveToCfgFile = "" then ParseParameters = false exit function end if i = i + 1 case "-config" if strLoadFromCfgFile = "" then ParseParameters = false exit function end if i = i + 1 case "-maxpacket" g_intMaxPacketSize = ReadInteger( args, i, i+1 ) if g_intMaxPacketSize = -1 then ParseParameters = false exit function end if i = i + 1 case "-minpacket" g_intMinPacketSize = ReadInteger( args, i, i+1 ) if g_intMinPacketSize = -1 then ParseParameters = false exit function end if i = i + 1 case else ' Show an error information for unrecognized parameter. OutputInfo "Invalid parameter: " & args(i) ParseParameters = false exit function end select next if strSaveToCfgFile <> "" then strSaveToCfgFile = g_objFileSystem.GetAbsolutePathName( strSaveToCfgFile ) ' Add extension if necessary if Right( LCase( strSaveToCfgFile ), 4 ) <> ".weu" then strSaveToCfgFile = strSaveToCfgFile & ".weu" end if CreateOutputFolder( g_objFileSystem.GetParentFolderName( strSaveToCfgFile ) ) set objTextFile = g_objFileSystem.OpenTextFile( strSaveToCfgFile, 2, True ) objTextFile.Write( strArgumentsQuoted ) objTextFile.close end if ParseParameters = true end function ' Show help information of this program. function ShowHelp() OutputInfo g_strProductName OutputInfo g_strProductCopyright OutputInfo "" OutputInfo "" OutputInfo "Encode from files or devices to Windows Media files or streams. Supported" OutputInfo "source file formats are .wmv, .wma, .asf, .avi, .wav, .mpg, .mp3, .bmp," OutputInfo ".jpg, and .avs." OutputInfo "" OutputInfo "" OutputInfo "Usage for I/O and statistics." OutputInfo "-----------------------------" OutputInfo "" OutputInfo "[-wme] <Windows Media Encoder session file>" OutputInfo " Loads an existing Windows Media Encoder session file." OutputInfo "[-input] <file or directory name>" OutputInfo " The file or directory to be encoded." OutputInfo " Specify a file or directory name. If you specify a directory, supported" OutputInfo " files in the directory will be encoded to the output directory, using" OutputInfo " the same encoding settings. " OutputInfo " Enclose file and directory names that have spaces in quotations." OutputInfo " For example: -input ""c:\my sample.wmv""" OutputInfo "[-output] <file or directory name>" OutputInfo " The name of the output file or directory." OutputInfo " If the input is a file, -output corresponds to a file name. If the input" OutputInfo " is a directory, -output corresponds to a directory name." OutputInfo " The output directory will be created if it doesn't already exist." OutputInfo " An extension is automatically appended to output files." OutputInfo " (.wma for audio-only Windows Media files, and .wmv for video-only or" OutputInfo " audio and video Windows Media files.)" OutputInfo "[-devices]" OutputInfo " Lists audio and video capture devices." OutputInfo "[-adevice] <audio device number>" OutputInfo " The audio capture device to encode from." OutputInfo " Use -devices to list all available capture devices." OutputInfo " When encoding from devices, you must specify a duration using -duration." OutputInfo "[-vdevice] <video device number>" OutputInfo " The video capture device to encode from." OutputInfo " Use -devices to list all available capture devices." OutputInfo " When capturing from devices, you must specify a duration using -duration." OutputInfo "[-duration] <seconds>" OutputInfo " Amount of time in seconds to encode. Use when sourcing from devices." OutputInfo "[-outputstring] <string>" OutputInfo " The string to be attached to every output file name for directory mode." OutputInfo "[-broadcast] <port>" OutputInfo " Broadcasts via HTTP on the port specified. The default port is 8080." OutputInfo "[-time] <start time> <end time>" OutputInfo " Specify the time segment (in msec) to be encoded. Use 'end' for" OutputInfo " <end time> if you want to encode to the end of the file." OutputInfo "[-silent]" OutputInfo " Prevents statistics from being displayed after encoding is finished." OutputInfo "[-config] <input configuration file>" OutputInfo " Inputs arguments from a configuration file. The default extension is .weu." OutputInfo " Parameters in the file can be overridden by later arguments." OutputInfo "[-s_config] <output configuration file>" OutputInfo " Creates a configuration file. The file name extension .weu is appended" OutputInfo " automatically." OutputInfo "[-maxpacket] <packet size>" OutputInfo " Specifies the maximum packet size in bytes." OutputInfo "[-minpacket] <packet size>" OutputInfo " Specifies the minimum packet size in bytes." OutputInfo "[-log] <log file>" OutputInfo " Writes all text output to a log file. Always overwrites." OutputInfo "" OutputInfo "" OutputInfo "Usage for profiles." OutputInfo "-------------------" OutputInfo " You can override parameters in a profile by appending arguments to a" OutputInfo " command." OutputInfo "" OutputInfo "[-profile] <profile code>" OutputInfo " Specifies a predefined profile to use in the session." OutputInfo "" OutputInfo "Codes and basic descriptions for the predefined profiles:" OutputInfo "Audio/Video:" OutputInfo " av20: Profile_AudioVideo_Modem_28K (actual rate: 20Kbps)" OutputInfo " av32: Profile_AudioVideo_Modem_56K (32 Kbps)" OutputInfo " av100: Profile_AudioVideo_LAN_100K (100 Kbps)" OutputInfo " av225: Profile_AudioVideo_LAN_256K (225 Kbps)" OutputInfo " av350: Profile_AudioVideo_LANDSL_384K (350 Kbps)" OutputInfo " av450: Profile_AudioVideo_LANDSL_768K (450 Kbps)" OutputInfo " av700: Profile_AudioVideo_NearBroadcast_700K (700 Kbps)" OutputInfo " av1400: Profile_AudioVideo_NearBroadcast_1400K (1400 Kbps)" OutputInfo " av350pal: Profile_AudioVideo_Broadband_PAL_384K (350 Kbps)" OutputInfo " av700pal: Profile_AudioVideo_NearBroadcast_PAL_700K (700 Kbps)" OutputInfo " av100_2p: Profile_AudioVideo_LAN_100K_2Pass (100 Kbps)" OutputInfo " av350_2p: Profile_AudioVideo_LANDSL_384K_2Pass (350 Kbps)" OutputInfo " av600vbr: Profile_AudioVideo_FilmVBR_600K (600 Kbps)" OutputInfo " avq97vbr: Profile_AudioVideo_FilmVBR_Quality97 (Quality 97)" OutputInfo "" OutputInfo "Audio-only:" OutputInfo " a20_1: Profile_AudioOnly_FMRadioMono_28K (20 Kbps)" OutputInfo " a20_2: Profile_AudioOnly_FMRadioStereo_28K (20 Kbps)" OutputInfo " a32: Profile_AudioOnly_Modem_56K (32 Kbps)" OutputInfo " a48: Profile_AudioOnly_NearCDQuality_48K (48 Kbps)" OutputInfo " a64: Profile_AudioOnly_CDQuality_64K (64 Kbps)" OutputInfo " a96: Profile_AudioOnly_CDAudiophileQuality_96K (96 Kbps)" OutputInfo " a128: Profile_AudioOnly_CDAudiophileQuality_128K (128 Kbps)" OutputInfo "" OutputInfo "Video-only:" OutputInfo " v20: Profile_VideoOnly_Modem_28K (20 Kbps)" OutputInfo " v32: Profile_VideoOnly_Modem_56K (32 Kbps)" OutputInfo "" OutputInfo "[-loadprofile] <profile file name>" OutputInfo " Specifies a Windows Media Encoder or custom profile to use." OutputInfo "[-saveprofile] <profile file name>" OutputInfo " Saves current settings to a file for later reuse. Default file name" OutputInfo " extension is .prx." OutputInfo "" OutputInfo "" OutputInfo "Usage for audio settings." OutputInfo "-------------------------" OutputInfo "" OutputInfo "[-a_input]" OutputInfo " Sets a separate input file to be used as audio source when encoding" OutputInfo " to a .wmv containing both video and audio streams." OutputInfo " Must use -input to also specify the video source, otherwise -a_input" OutputInfo " will be ignored. Audio source defined by -a_input will override any" OutputInfo " audio stream present in the main -input source." OutputInfo " Enclose file names that have spaces in quotations." OutputInfo " For example: -a_input ""c:\my sample.wav""" OutputInfo "[-a_codecs]" OutputInfo " Lists all available audio codecs." OutputInfo "[-a_formats]" OutputInfo " Lists all audio formats for each codec." OutputInfo "[-a_codec] <codec index>" OutputInfo " Audio codec to be used. Use -a_codecs to list available codecs." OutputInfo " Specify codec index:" OutputInfo " WMASTD: Windows Media Audio (default)." OutputInfo " WMAPRO: Windows Media Audio Professional." OutputInfo " WMALSL: Windows Media Audio Lossless." OutputInfo " WMSP: Windows Media Audio Voice." OutputInfo " PCM: No compression." OutputInfo "" OutputInfo " Legacy indexes WMA9STD, WMA9PRO, WMA9LSL and WMSP9 will translate" OutputInfo " to new version-agnostic indexes." OutputInfo "[-a_mode] <mode>" OutputInfo " Audio encoding mode to be used." OutputInfo " 0: 1-pass CBR (default)." OutputInfo " 1: 2-pass CBR." OutputInfo " 2: Quality-based VBR." OutputInfo " 3: Bit rate-based VBR (two-pass)." OutputInfo " 4: Bit rate-based peak VBR (two-pass)." OutputInfo "[-a_content] <mode>" OutputInfo " Audio content mode for the Windows Media Audio Voice codec." OutputInfo " 0 = No special mode for the audio content (default)" OutputInfo " 1 = Speech mode" OutputInfo " 2 = Mixed (speech and music) mode (also requires -a_contentedl)" OutputInfo " You must also specify the Windows Media Audio Voice codec." OutputInfo "[-a_contentedl] <file name>" OutputInfo " Specifies the places in audio content where music starts and ends. To do" OutputInfo " this, you must first create an optimization definition file. You" OutputInfo " must specify the Windows Media Audio Voice codec and -a_content 2 when" OutputInfo " when you use the -a_contentedl option." OutputInfo "[-a_folddown6to2] <surround mix> <center mix> <LFE>" OutputInfo " Fold-down coefficients for multichannel audio. Use whole numbers only." OutputInfo " Values will be converted to negative numbers. Valid numbers are 0 to 144." OutputInfo " For example, -a_folddown6to2 10 3 3" OutputInfo "[-a_peakbitrate] <peak bit rate>" OutputInfo " Specifies the peak bit rate in bits per second for peak bit rate-based" OutputInfo " VBR for audio. If not specified, the peak bit rate is 1.5 times the" OutputInfo " audio bit rate." OutputInfo "[-a_peakbuffer] <peak buffer>" OutputInfo " Buffer in msec for audio with peak bit rate-based VBR. If not specified," OutputInfo " the default of 3000 msec is used." OutputInfo "[-a_setting] <setting>" OutputInfo " Specifies the formats for audio setting." OutputInfo " Use -a_formats to list supported audio formats for each codec." OutputInfo "" OutputInfo " -a_setting Bitrate_SamplingRate_Channels. For example, -a_setting 48_44_2" OutputInfo " specifies 48 Kbps, 44 kHz, and two channels. The default is 64_44_2." OutputInfo "" OutputInfo " If you use quality-based VBR: -a_setting Qxx_SamplingRate_Channels." OutputInfo " For example, -a_setting Q90_44_2 specifies a quality level of 90, 44 kHz," OutputInfo " and 2 channels." OutputInfo "" OutputInfo " If you use the Windows Media Audio Professional codec:" OutputInfo " -a_setting Bitrate_SamplingRate_Channels_BitDepth." OutputInfo " For example, -a_setting 250_44_2_24 specifies 250 Kbps, 44 kHz, " OutputInfo " two channels, and 24-bit encoding. Use either 16- or 24-bit encoding." OutputInfo " 24-bit is the default." OutputInfo "" OutputInfo " If you use the Windows Media Audio Lossless codec:" OutputInfo " -a_setting Qxx_SamplingRate_Channels_BitDepth. For example," OutputInfo " -a_setting Q100_44_2_24 specifies VBR Quality 100, 44 kHz, two channel," OutputInfo " 24-bit encoding. (Quality-based VBR and a quality level of 100 is" OutputInfo " required with this codec.)" OutputInfo "[-audioonly]" OutputInfo " Encodes the audio portion of the stream only." OutputInfo "" OutputInfo "" OutputInfo "Usage for video settings." OutputInfo "-------------------------" OutputInfo "" OutputInfo "[-v_codecs]" OutputInfo " Lists all available video codecs." OutputInfo "[-v_codec] <codec index>" OutputInfo " Video codec to be used. Use -v_codecs to list available video codecs." OutputInfo " Specify codec index:" OutputInfo " WMV9: Windows Media Video 9 Simple & Main Profiles (default)." OutputInfo " WVC1: Windows Media Video 9 Advanced Profile." OutputInfo " WMS9: Windows Media Video 9 Screen." OutputInfo " WMV8: Windows Media Video V8." OutputInfo " WMV7: Windows Media Video V7." OutputInfo " UNCOMP: Full frames (uncompressed)." OutputInfo "[-v_mode] <mode>" OutputInfo " Video encoding mode to be used." OutputInfo " 0: 1-pass CBR (default)." OutputInfo " 1: 2-pass CBR." OutputInfo " 2: Quality-based VBR." OutputInfo " 3: Bit rate-based VBR (two-pass)." OutputInfo " 4: Peak bit rate-based VBR (two-pass)." OutputInfo "[-v_width] <width>" OutputInfo " Video frame width in pixels to be encoded. Default: Source video width." OutputInfo "[-v_height] <height>" OutputInfo " Video frame height in pixels to be encoded. Default: Source video height." OutputInfo "[-v_framerate] <rate>" OutputInfo " Video frame rate in floating point to be encoded. Default: Source video" OutputInfo " frame rate, or 30 fps." OutputInfo "[-v_keydist] <time>" OutputInfo " Key frame distance in seconds for video. Default: 10 seconds." OutputInfo "[-v_preproc] <filter number>" OutputInfo " Video preprocessing for certain input sources." OutputInfo " 0: None (for progressive video input). Default." OutputInfo " 1, 2, 3, 4:" OutputInfo " Deinterlace but preserve source size and framerate." OutputInfo " For example, 640x480x30 interlace to 640x480x30 progressive." OutputInfo " The encoder uses a simple field blending deinterlace method which" OutputInfo " produces good quality in still scenes but might result in ghosting" OutputInfo " or blurring in high motion scenes." OutputInfo " 5: Inverse telecine from 30fps to 24fps." OutputInfo " 6: Inverse telecine - First field is top field with AA telecine pattern." OutputInfo " 7: Inverse telecine - First field is top field with BB telecine pattern." OutputInfo " 8: Inverse telecine - First field is top field with BC telecine pattern." OutputInfo " 9: Inverse telecine - First field is top field with CD telecine pattern." OutputInfo " 10: Inverse telecine - First field is top field with DD telecine pattern." OutputInfo " 11: Inverse telecine - First field is bottom field with AA telecine " OutputInfo " pattern." OutputInfo " 12: Inverse telecine - First field is bottom field with BB telecine" OutputInfo " pattern." OutputInfo " 13: Inverse telecine - First field is bottom field with BC telecine" OutputInfo " pattern." OutputInfo " 14: Inverse telecine - First field is bottom field with CD telecine" OutputInfo " pattern." OutputInfo " 15: Inverse telecine - First field is bottom field with DD telecine" OutputInfo " pattern." OutputInfo " 16: Interlaced encoding - Auto detect field order." OutputInfo " 17: Interlaced encoding - First field is top field." OutputInfo " 18: Interlaced encoding - First field is bottom field." OutputInfo "[-v_clip] <left> <top> <right> <bottom>" OutputInfo " The region of the image (with respect to source) to be clipped/encoded." OutputInfo " If the right is 0 or greater than width, it is ignored and re-assigned" OutputInfo " to width. If the bottom is 0 or greater than height, it is ignored and" OutputInfo " re-assigned to height." OutputInfo "[-v_bitrate] <bit rate>" OutputInfo " Video bit rate in bits per second to be encoded. Default: 250000 bps." OutputInfo " Set this to 0 for audio-only coding." OutputInfo "[-v_buffer] <buffer>" OutputInfo " Delay buffer in milliseconds for video. Default: 5000 msec." OutputInfo "[-v_quality] <quality>" OutputInfo " CBR: Quality/smoothness tradeoff. 0 to 100, 0 being the smoothest." OutputInfo " Higher values might drop frames in order to maintain image quality." OutputInfo " Default: 75." OutputInfo " Quality-based VBR: Image quality for the video. Encode video to the" OutputInfo " specified quality, regardless of bit rate. Default: 95." OutputInfo " In 2-pass modes the quality parameter is ignored." OutputInfo "[-v_qp] <quantizer parameter>" OutputInfo " An alternative method of specifying image quality in quality-based VBR" OutputInfo " mode. Because quality-based VBR uses a fixed QP for all encoded frames," OutputInfo " this method allows direct mapping to QP levels. Valid range is 1.0 to" OutputInfo " 31.0 in 0.5 intervals. Default: 2.5" OutputInfo " If v_quality is also specified it will override v_qp." OutputInfo "[-v_peakbitrate] <peak bit rate>" OutputInfo " Peak bit rate in bits per second for peak bit rate-based VBR for video." OutputInfo " If not specified, the peak bit rate is 1.5 times the video bit rate." OutputInfo "[-v_peakbuffer] <peak buffer>" OutputInfo " Buffer in msec for video, with peak bit rate-based VBR. If not specified," OutputInfo " the default of 5000 msec is used." OutputInfo "[-v_performance] <performance level>" OutputInfo " Sets the encoder performance/quality level. Possible values: 0, 20, 40," OutputInfo " 60, 80, and 100, where 0 is fastest and 100 is highest quality. If you" OutputInfo " do not specify a value, codec defaults are used." OutputInfo " Default: 60 (WMV9 and WVC1)." OutputInfo "[-v_complexity] <complexity level>" OutputInfo " Same as v_performance but expressed on a scale from 0 to 5." OutputInfo " If v_performance is also specified it will override v_complexity." OutputInfo "[-v_profile] <conformance profile>" OutputInfo " Sets the VC-1 conformance profile for the encoded video. Video profiles" OutputInfo " are used to indicate the decoding complexity of the video, as well as to" OutputInfo " indicate which features a decoder needs to have implemented in order to" OutputInfo " correctly decode the video. In order to stay conformant to the requested" OutputInfo " profile, the encoder might ignore certain advanced WMV settings." OutputInfo " Possible values for WMV9 codec are SP (Simple) and MP (Main). WVC1 codec" OutputInfo " only allows AP (Advanced) value." OutputInfo " If you do not add the -v_profile option to a command, the correct profile" OutputInfo " level is selected automatically during encoding." OutputInfo "[-pixelratio] <x y>" OutputInfo " Specifies the video pixel aspect ratio. Common pixel aspect ratios:" OutputInfo " DV NTSC fullscreen 10:11" OutputInfo " DV NTSC widescreen 40:33" OutputInfo " DV PAL fullscreen 12:11" OutputInfo " DV PAL widescreen 16:11" OutputInfo "[-pixelformat] <format>" OutputInfo " Specifies the source video pixel format. Possible values:" OutputInfo " I420" OutputInfo " IYUV" OutputInfo " YV12" OutputInfo " UYVY" OutputInfo " YUY2" OutputInfo " YVYU" OutputInfo " YVU9" OutputInfo " RGB24" OutputInfo " RGB32" OutputInfo " RGB555" OutputInfo " RGB565" OutputInfo " RGB8" OutputInfo " By default the encoder will try to autodetect the source pixel format." OutputInfo "[-videoonly]" OutputInfo " Encodes video stream only." OutputInfo "" OutputInfo "" OutputInfo "Usage for advanced Windows Media Video settings." OutputInfo "------------------------------------------------" OutputInfo " Valid only with -v_codec set to WVC1 or WMV9." OutputInfo "" OutputInfo "[-v_compopt] <preset>" OutputInfo " Compression optimization preset." OutputInfo " 0: Off (default)." OutputInfo " 1: Best visual quality. Automatically sets:" OutputInfo " -v_bframedist 1" OutputInfo " -v_mslevel 1 (Integer Chroma)" OutputInfo " -v_msrange 0 (Adaptive)" OutputInfo " -v_mvcost 1 (Adaptive)" OutputInfo " -v_mmatch 0 (Adaptive)" OutputInfo " -v_dquantoption 2 (I & P frames)" OutputInfo " -v_loopfilter 1 (On)" OutputInfo " -v_complexity 3" OutputInfo " Setting additional parameters will override any values set by the preset." OutputInfo "[-v_dquantoption] <option>" OutputInfo " Specifies the type of frames to apply differential quantization to." OutputInfo " Dquant allows macroblocks containing smooth or dark areas to be encoded at" OutputInfo " a quantizer level lower than the rest of the image." OutputInfo " 0: Off (default)." OutputInfo " 1: Apply to I frame only." OutputInfo " 2: Apply to I and P frames." OutputInfo " 3: Apply to I, P and B frames." OutputInfo "[-v_dquantstrength] <strength>" OutputInfo " Specifies the method and strength of dquant application. Only valid" OutputInfo " when used with -v_dquantoption parameter set greater than 0." OutputInfo " 0: Regular dquant method (default)." OutputInfo " 1: Fixed QP dquant method for smooth areas (QP 2)." OutputInfo " 2: Fixed QP dquant method for very smooth areas (QP 1)." OutputInfo " 3: Fixed QP dquant method for dark areas (QP 1)." OutputInfo " 4: Regular dquant method for dark areas." OutputInfo "[-v_adz] <strength>" OutputInfo " Controls adaptive dead-zone, a quantization method which attempts to" OutputInfo " balance the bit distribution within a picture between smooth areas with" OutputInfo " fine details and textured areas with coarse details. Increasing the" OutputInfo " strength controls how aggressively areas are mapped to larger dead-zones" OutputInfo " where image detail is irretrievably lost." OutputInfo " Valid range is 0 to 15, where 0 (default) disables the ADZ option." OutputInfo " Using high values can result in loss of too much image detail." OutputInfo "[-v_loopfilter] <setting>" OutputInfo " Controls the in-loop deblocking filter. This filter reduces blocking" OutputInfo " artifacts at encoding time so that future P and B frames don't carry" OutputInfo " forward the blocking artifacts. If not specified, loop filter is" OutputInfo " enabled by default at resolutions below standard definition (SD)." OutputInfo " 0 to disable, 1 to enable." OutputInfo "[-v_overlap] <setting>" OutputInfo " Controls overlap smoothing. This filter smooths borders of adjacent" OutputInfo " macroblocks in an encoded video. If not specified, overlap smoothing" OutputInfo " is enabled by default at resolutions below standard definition (SD)." OutputInfo " 0 to disable, 1 to enable." OutputInfo "[-v_denoise] <setting>" OutputInfo " Controls the noise removal filter. Valid range is 0 to 5, where 0" OutputInfo " (default) disables denoising and 5 uses strongest denoising." OutputInfo "[-v_median] <setting>" OutputInfo " Controls the median filter. This filter tells the codec to ignore noise" OutputInfo " and grain when performing motion estimation which can improve video" OutputInfo " quality in very noisy video but can adversely affect clean video." OutputInfo " 0 to disable (default), 1 to enable." OutputInfo "[-v_scaling] <setting>" OutputInfo " Specifies whether to scale the luma range before encoding in order to" OutputInfo " improve efficiency. Scaled luma range is not expanded when decoded." OutputInfo " 0: Off (default)." OutputInfo " 1: Conservative. Compresses Y range to 26..229." OutputInfo " 2: Aggressive. Compresses Y range to 31..224." OutputInfo "[-v_edgeremoval] <setting>" OutputInfo " Specifies whether encoder should attempt to detect and remove noisy" OutputInfo " frame edges, such as VBI data often found in broadcast television." OutputInfo " 0 to disable (default), 1 to enable." OutputInfo "[-v_mslevel] <level>" OutputInfo " Specifies the level of color information used in motion search." OutputInfo " 0: Luma only (default)." OutputInfo " 1: Luma with nearest integer chroma." OutputInfo " 2: Luma with true chroma." 'OutputInfo " 3: Macroblock-adaptive with nearest integer chroma." 'OutputInfo " 4: Macroblock-adaptive with true chroma." OutputInfo "[-v_msrange] <range>" OutputInfo " Controls the search range used in motion search." OutputInfo " 0: Frame-adaptive." OutputInfo " 1: +63.75/-64.0 H, +31.75/-32.0 V (default)." OutputInfo " 2: +127.75/-128.0 H, +63.75/-64.0 V." OutputInfo " 3: +511.75/-512.0 H, +127.75/-128.0 V." OutputInfo " 4: +1023.75/-1024.0 H, +255.75/-256.0 V." OutputInfo "[-v_mmatch] <method>" OutputInfo " Specifies the method used to measure and identify motion." OutputInfo " 0: Macroblock-adaptive." OutputInfo " 1: SAD (default)." OutputInfo " 2: Hadamard." OutputInfo "[-v_mbmodecost] <method>" OutputInfo " Specifies the cost method used to decide the macroblock mode." OutputInfo " 0: SAD/Hadamard (default when v_performance < 60)." OutputInfo " 1: Rate Distortion (default when v_performance > 40)." OutputInfo "[-v_mvcoding] <method>" OutputInfo " Specifies the method used to code delta motion vectors in interlaced" OutputInfo " images. Wider motion vector distributions are more efficient at storing" OutputInfo " random motion within a frame." OutputInfo " 0: Default delta motion vector distribution size." OutputInfo " 1: Double horizontal delta motion vector distribution size." OutputInfo " 2: Double vertical delta motion vector distribution size." OutputInfo " 3: Double delta motion vector distribution size in both directions." OutputInfo "[-v_mvcost] <method>" OutputInfo " Specifies the motion vector cost method." OutputInfo " 0: Fixed motion vector cost." OutputInfo " 1: Adaptive motion vector cost (default)." OutputInfo "[-v_bframedist] <frames>" OutputInfo " Specifies the number of bidirectional predictive (B) frames that the" OutputInfo " encoder will use between other types of frames." OutputInfo " If not specified, the encoder will only use I and P type frames." OutputInfo " Valid range is 0 to 7, where 0 indicates that B-frames will not be used." OutputInfo "[-v_bdeltaqp] <delta>" OutputInfo " Sets the fixed increase between the anchor frame's picture quantizer level" OutputInfo " and the B frame's picture quantizer level. Valid range is 0 to 31. If not" OutputInfo " specified, the encoder will use variable deltas." OutputInfo "[-v_lookahead] <frames>" OutputInfo " Sets the number of frames to evaluate ahead for ratecontrol optimization." OutputInfo " Enabling lookahead might automatically insert B frames into the video in" OutputInfo " place of flash frames. To completely disable B frame insertion, also set" OutputInfo " -v_bframedist to 0. Lookahead is ignored in 2-pass ratecontrol modes." OutputInfo " Valid range is 0 to 16, where 0 disables the lookahead option." OutputInfo "[-v_rangeredux] <Y reduction> <Y expansion> <C reduction> <C expansion>" OutputInfo " Forces range reduction for the luma (Y) and chroma (C) channels. Reduced" OutputInfo " range is then expanded on decode by the set expansion factor." OutputInfo " Reducing the color/luma range reduces the encoded size of video frames," OutputInfo " but can introduce banding artifacts in the decoded frames." OutputInfo " Valid range for each reduction/expansion factor is 0 to 8." OutputInfo "[-v_codedwidth] <width>" OutputInfo " Encodes video at a width different than the decoded display width." OutputInfo " Valid range is 32 to 8192. Values will be rounded up internally to the" OutputInfo " nearest multiple of 32." OutputInfo "[-v_codedheight] <height>" OutputInfo " Encodes video at a height different than the decoded display height." OutputInfo " Valid range is 32 to 8192. Values will be rounded up internally to the" OutputInfo " nearest multiple of 32." OutputInfo "[-v_numthreads] <threads>" OutputInfo " Forces the encoder to use the specified number of threads for encoding." OutputInfo " Valid values are 1, 2 and 4. If not specified, encoder will match the" OutputInfo " number of logical processors reported by the operating system." OutputInfo "[-v_type] <type>" OutputInfo " Specifies progressive, field or frame picture encoding method." OutputInfo " For interlaced encoding you must also set -v_preproc to 16, 17 or 18." OutputInfo " 0: Progressive encoding (default when v_preproc < 16)." OutputInfo " 1: Interlaced frame encoding." OutputInfo " 2: Interlaced field encoding (default when v_preproc > 15)." OutputInfo " 3: Auto Interlaced frame/field switching." OutputInfo " 4: Auto Progressive/Interlaced frame/Interlaced field switching." OutputInfo " The auto options are designed to pick the most efficient coding method" OutputInfo " for every frame but do not affect the output frame rate or frame pattern." OutputInfo "[-v_preset] <preset>" OutputInfo " Selects a set of predefined settings that help improve speed or quality." OutputInfo " Available presets are:" OutputInfo " fast: Up to 1.5x faster than default with comparable quality." OutputInfo " -v_complexity 2" OutputInfo " -v_bframedist 1" OutputInfo " -v_lookahead 16" OutputInfo " -v_loopfilter 1" OutputInfo " -v_overlap 1" OutputInfo " good: Up to 1.5x slower than default." OutputInfo " -v_complexity 3" OutputInfo " -v_bframedist 1" OutputInfo " -v_lookahead 16" OutputInfo " -v_loopfilter 1" OutputInfo " better: Up to 2.5x slower than default." OutputInfo " -v_complexity 3" OutputInfo " -v_bframedist 1" OutputInfo " -v_lookahead 16" OutputInfo " -v_loopfilter 1" OutputInfo " -v_mslevel 1" OutputInfo " -v_msrange 0" OutputInfo " best: Up to 4.5x slower than default." OutputInfo " -v_complexity 5" OutputInfo " -v_bframedist 1" OutputInfo " -v_lookahead 16" OutputInfo " -v_loopfilter 1" OutputInfo " -v_msrange 0" OutputInfo " insane: The slowest and highest quality preset." OutputInfo " -v_complexity 4" OutputInfo " -v_bframedist 1" OutputInfo " -v_lookahead 16" OutputInfo " -v_loopfilter 1" OutputInfo " -v_mslevel 2" OutputInfo " -v_msrange 0" OutputInfo " -v_mmatch 0" OutputInfo " Setting additional parameters will override any values set by the preset." OutputInfo " Using video presets with -v_compopt 1 is not recommended." OutputInfo "" OutputInfo "" OutputInfo "Usage for metadata settings." OutputInfo "----------------------------" OutputInfo "" OutputInfo "[-title] <string>" OutputInfo "[-author] <string>" Outputinfo "[-album] <string>" Outputinfo "[-year] <string>" Outputinfo "[-trackno] <string>" Outputinfo "[-genre] <string>" OutputInfo "[-copyright] <string>" OutputInfo "[-description] <string> " OutputInfo "[-rating] <string>" OutputInfo "NOTE: The maximum string length for each one is 255. It is recommended" OutputInfo " that you enclose all string parameters in quotations. " end function ' Print out info about the input file function PrintFileInfo() dim objFileInfo dim strFileInfo dim strInput2 strInput2 = g_objFileSystem.GetAbsolutePathName( g_strInput ) set objFileInfo = WScript.CreateObject( "FileInfo.MediaInfo" ) objFileInfo.FileName = strInput2 strFileInfo = objFileInfo.MediaInfo OutputInfo strFileInfo end function ' List audio codecs. function ListAudioCodecs() dim objProfile dim objName dim intFourCC dim intVBRMode dim strCodecId dim intCount set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" ) OutputInfo vbCrLf & "Audio Codecs: " ' For all VBR modes for intVBRMode = 1 to 4 objProfile.VBRMode(WMENC_AUDIO, 0) = intVBRMode select case intVBRMode case WMENC_PVM_NONE OutputInfo "CBR Audio Mode :" case WMENC_PVM_PEAK OutputInfo "Peak Bit Rate-Based VBR Audio Mode :" case WMENC_PVM_UNCONSTRAINED OutputInfo "Quality-Based VBR Audio Mode :" case WMENC_PVM_BITRATE_BASED OutputInfo "Bit Rate-Based VBR Audio Mode :" case else OutputInfo "Unknown Mode" end select intCount = 0 ' Enum all audio codecs for i=0 to objProfile.AudioCodecCount-1 objProfile.EnumAudioCodec i, objName 'Check and display fourcc intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_AUDIO, i) select case intFourCC case WMASTD_FOURCC strCodecId = WMASTD case WMAPRO_FOURCC strCodecId = WMAPRO case WMALSL_FOURCC strCodecId = WMALSL case WMSPEECH_FOURCC strCodecId = WMSPEECH case PCM_FOURCC strCodecId = PCM case else strCodecId = "" end select if( strCodecId <> "" ) then OutputInfo vbTab & "[" & intCount & "] " & strCodecId & " : " & objName intCount = intCount + 1 end if next OutputInfo vbCrLf next end function ' List video codecs. function ListVideoCodecs() dim objProfile dim objName dim intFourCC dim intVBRMode dim strCodecId dim intCount set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" ) OutputInfo vbCrLf & "Video Codecs: " ' For all VBR modes for intVBRMode = 1 to 4 objProfile.VBRMode(WMENC_VIDEO, 0) = intVBRMode select case intVBRMode case WMENC_PVM_NONE OutputInfo "CBR Video Mode :" case WMENC_PVM_PEAK OutputInfo "Peak Bit Rate-Based VBR Video Mode :" case WMENC_PVM_UNCONSTRAINED OutputInfo "Quality-Based VBR Video Mode :" case WMENC_PVM_BITRATE_BASED OutputInfo "Bit Rate-Based VBR Video Mode :" case else OutputInfo "Unknown Mode" end select intCount = 0 ' Enum all video codecs for i=0 to objProfile.VideoCodecCount-1 objProfile.EnumVideoCodec i, objName 'Check and display fourcc intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_VIDEO, i) select case intFourCC case WMV7_FOURCC strCodecId = WMV7 case WMV8_FOURCC strCodecId = WMV8 case WMV9_FOURCC strCodecId = WMV9 case WVC1_FOURCC strCodecId = WVC1 case WMS9_FOURCC strCodecId = WMS9 case MP41_FOURCC strCodecId = MP41 case UNCOMP_FOURCC strCodecId = UNCOMP case else strCodecId = "" end select if( strCodecId <> "" ) then OutputInfo vbTab & "[" & i & "] " & strCodecId & " : " & objName intCount = intCount + 1 end if next OutputInfo vbCrLf next end function ' List audio formats. function ListAudioFormats() dim objProfile dim objName dim intFourCC dim intVBRMode dim strCodecId, strAudFormatName, strSetting dim intAudioSampleRate, intAudioChannels, intAudioBitsPerSample, intAudioBitrate dim intArgSpaceCount, intBitrateSpaceCount, intSamplingRateSpaceCount, intChannelSpaceCount intArgSpaceCount = 24 intBitrateSpaceCount = 16 intSamplingRateSpaceCount = 20 intChannelSpaceCount = 10 set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" ) OutputInfo vbCrLf & "Audio Codecs: " ' For all VBR modes for intVBRMode = 1 to 4 objProfile.VBRMode(WMENC_AUDIO, 0) = intVBRMode select case intVBRMode case WMENC_PVM_NONE OutputInfo "CBR Mode :" case WMENC_PVM_PEAK OutputInfo "Peak Bit Rate-Based VBR Audio Mode :" case WMENC_PVM_UNCONSTRAINED OutputInfo "Quality-Based VBR Audio Mode :" case WMENC_PVM_BITRATE_BASED OutputInfo "Bit Rate-Based VBR Audio Mode :" case else OutputInfo "Unknown Mode" end select ' Enum all audio codecs for i=0 to objProfile.AudioCodecCount-1 objProfile.EnumAudioCodec i, objName 'Check and display fourcc intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_AUDIO, i) select case intFourCC case WMASTD_FOURCC strCodecId = WMASTD case WMAPRO_FOURCC strCodecId = WMAPRO case WMALSL_FOURCC strCodecId = WMALSL case WMSPEECH_FOURCC strCodecId = WMSPEECH case PCM_FOURCC strCodecId = PCM end select if( strCodecId <> "" ) then OutputInfo vbTab & strCodecId & " : " & objName & " (" & strCodecId & "):" else OutputInfo vbTab & objName & ":" end if OutputInfo vbCrLf if intVBRMode = WMENC_PVM_UNCONSTRAINED then if strCodecId <> WMAPRO then OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Quality", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & "Channel" else OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Quality", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & PadSpaces("Channel", intChannelSpaceCount) & "BitsPerSample" end if else if strCodecId <> WMAPRO and strCodecId <> WMALSL then OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Bitrate", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & "Channel" else OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Bitrate", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & PadSpaces("Channel", intChannelSpaceCount) & "BitsPerSample" end if end if OutputInfo vbTab & vbTab & "------------------------------------------------------------------------------------" For j=0 To objProfile.audioFormatCount(i) - 1 intAudioBitrate = objProfile.EnumAudioFormat(i, j, strAudFormatName, intAudioSampleRate, intAudioChannels, intAudioBitsPerSample) if intVBRMode <> WMENC_PVM_UNCONSTRAINED then intAudioBitrate = CLng(intAudioBitrate / 1000) else intAudioBitrate = "Q" & intAudioBitrate end if if intAudioSampleRate = 96000 then intAudioSampleRate = 96 elseif intAudioSampleRate = 88200 then intAudioSampleRate = 88 elseif intAudioSampleRate = 48000 then intAudioSampleRate = 48 elseif intAudioSampleRate = 44100 then intAudioSampleRate = 44 elseif intAudioSampleRate = 22050 then intAudioSampleRate = 22 elseif intAudioSampleRate = 11025 then intAudioSampleRate = 11 else intAudioSampleRate = Clng(intAudioSampleRate / 1000) end if if strCodecId <> WMAPRO and strCodecId <> WMALSL then strSetting = intAudioBitrate & "_" & intAudioSampleRate & "_" & intAudioChannels OutputInfo vbTab & vbTab & PadSpaces(strSetting, intArgSpaceCount) & PadSpaces(intAudioBitrate, intBitrateSpaceCount) & PadSpaces(intAudioSampleRate, intSamplingRateSpaceCount) & intAudioChannels else strSetting = intAudioBitrate & "_" & intAudioSampleRate & "_" & intAudioChannels & "_" & intAudioBitsPerSample OutputInfo vbTab & vbTab & PadSpaces(strSetting, intArgSpaceCount) & PadSpaces(intAudioBitrate, intBitrateSpaceCount) & PadSpaces(intAudioSampleRate, intSamplingRateSpaceCount) & PadSpaces(intAudioChannels, intChannelSpaceCount) & intAudioBitsPerSample end if next OutputInfo vbCrLf & vbCrLf next OutputInfo vbCrLf next end function ' Add spaces to the end of arg to create intCount characters string function PadSpaces( arg, intCount ) if Len(arg) >= intCount then PadSpaces = arg exit function end if PadSpaces = arg & Space( intCount - Len(arg) ) end function ' List all audio and video devices. function ListDevices() dim objManager, objPlugin, i, j, k, count set objManager = g_objEncoder.SourcePluginInfoManager for i=0 to 1 if i = 0 then OutputInfo "audio device:" elseif i = 1 then OutputInfo "video device:" end if count = 0 for j=0 to objManager.Count-1 set objPlugin = objManager.Item(j) if objPlugin.Resources = true then if i = 0 then if objPlugin.MediaType = 1 or objPlugin.MediaType = 3 then ' Enum all devices in this type for k=0 to objPlugin.Count-1 OutputInfo vbTab & count & " : " & objPlugin.Item(k) count = count + 1 next end if elseif i = 1 then if objPlugin.MediaType = 2 or objPlugin.MediaType = 3 or objPlugin.MediaType = 6 then ' Enum all devices in this type for k=0 to objPlugin.Count-1 OutputInfo vbTab & count & " : " & objPlugin.Item(k) count = count + 1 next end if end if end if next next end function ' Setup encoder using the current settings. function SetupEncoder( ) if not CreateSourceGroup() then SetupEncoder = false exit function end if if not SetupInput() then SetupEncoder = false exit function end if if not SetupProfile() then SetupEncoder = false exit function end if if not SetupOutput() then SetupEncoder = false exit function end if if not SetupTime() then SetupEncoder = false exit function end if if not SetupDisplayInfo() then SetupEncoder = false exit function end if g_objEncoder.AutoStop = true SetupEncoder = true end function ' Create Source group by loading from wme or adding a new one function CreateSourceGroup() dim objProfile dim intCodecIndex ' If a WME file is provided, load the encoding configuration from this WME file. if g_strWMEFile <> "" then on error resume next ' Load enocder session from a WME file g_objEncoder.Load( g_objFileSystem.GetAbsolutePathName( g_strWMEFile ) ) ' Add a new source group. set g_objSourceGroup = g_objEncoder.SourceGroupCollection.Item(0) set objProfile = g_objSourceGroup.Profile set g_objProfile = WScript.CreateObject( "WMENCENG.WMEncProfile2" ) g_objProfile.LoadFromIWMProfile( objProfile ) ' If source file has an auido stream, get the audio source. if g_objSourceGroup.SourceCount( WMENC_AUDIO ) > 0 then set g_objAudioSource = g_objSourceGroup.Source( WMENC_AUDIO, 0 ) intCodecIndex = g_objProfile.Audience(0).AudioCodec( 0 ) g_objProfile.EnumAudioCodec intCodecIndex, g_strAudioCodecName end if ' If source file has a video stream, get the video source. if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then set g_objVideoSource = g_objSourceGroup.Source( WMENC_VIDEO, 0 ) intCodecIndex = g_objProfile.Audience(0).VideoCodec( 0 ) g_objProfile.EnumVideoCodec intCodecIndex, g_strVideoCodecName end if g_blnCreateCustomProfile = false if g_intMaxPacketSize = -1 then g_intMaxPacketSize = objProfile.MaxPacketSize end if if err.number <> 0 then OutputInfo "Loading the session (.wme) file failed: " & g_strWMEFile err.Clear CreateSourceGroup = false exit function end if else ' Create a new source group for this session set g_objSourceGroup = g_objEncoder.SourceGroupCollection.Add( "SG_1" ) end if CreateSourceGroup = true end function ' Setup profile configuration function SetupProfile() on error resume next dim objProfile dim objAudience dim blnRet dim strProfileLoad dim objFileInfo dim intVideoFramerateTemp dim intSourceVideoFramerate dim strInput2 ' save the global frame rate, since we might over-write it based on the input files frame rate intVideoFramerateTemp = g_intVideoFramerate if IsNull(g_objProfile) then Set g_objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" ) g_objProfile.ContentType = g_intSessionType g_objProfile.ProfileName = "WMCMDProfile" Set objAudience = g_objProfile.AddAudience( 10000000 ) else g_objProfile.ContentType = g_intSessionType Set objAudience = g_objProfile.Audience( 0 ) end if if g_intVideoFramerate = -1 then ' Assume 30 fps unless we can get the input files framerate g_intVideoFramerate = 30000 end if strInput2 = g_objFileSystem.GetAbsolutePathName( g_strInput ) set objFileInfo = WScript.CreateObject( "FileInfo.MediaInfo" ) objFileInfo.FileName = strInput2 intSourceVideoFramerate = 100000 intSourceVideoFramerate = objFileInfo.FrameRate * 1000 if intSourceVideoFramerate = 0 then intSourceVideoFramerate = 100000 end if ' Set the video frame rate to lower of the source input or user specified frame rate for better quality if intSourceVideoFramerate < g_intVideoFramerate then g_intVideoFramerate = intSourceVideoFramerate end if ' if profile string is specified load it if g_strProfile <> "" then blnRet = SetupPredefinedProfile( objAudience ) g_blnCreateCustomProfile = false if not blnRet then SetupProfile = false exit function end if end if if g_strProfileLoad <> "" then strProfileLoad = g_objFileSystem.GetAbsolutePathName( g_strProfileLoad ) g_objProfile.LoadFromFile strProfileLoad g_blnCreateCustomProfile = false Set objAudience = g_objProfile.Audience( 0 ) ' enable two pass if required if not isnull( g_objVideoSource ) then if g_objProfile.VBRMode( WMENC_VIDEO, 0 ) = WMENC_PVM_PEAK or g_objProfile.VBRMode( WMENC_VIDEO, 0 ) = WMENC_PVM_BITRATE_BASED then g_objVideoSource.PreProcessPass = 1 end if if objAudience.VideoFPS(0) > g_intVideoFramerate then objAudience.VideoFPS(0) = g_intVideoFramerate else g_intVideoFramerate = objAudience.VideoFPS(0) end if end if if not isnull( g_objAudioSource ) then if g_objProfile.VBRMode( WMENC_AUDIO, 0 ) = WMENC_PVM_PEAK or g_objProfile.VBRMode( WMENC_AUDIO, 0 ) = WMENC_PVM_BITRATE_BASED then g_objAudioSource.PreProcessPass = 1 end if end if end if ' First time: override the WME or predefined profile with custom values blnRet = SetupCustomProfile( objAudience ) if not blnRet then SetupProfile = false exit function end if if g_blnCreateCustomProfile then ' Second time: Update profile based on input specified and default values LoadProfileDefaults() blnRet = SetupCustomProfile( objAudience ) if not blnRet then SetupProfile = false exit function end if end if ' Set a few more things like interlaced coding and pixel ratio if g_intPixelAspectRatioX <> -1 or g_intPixelAspectRatioY <> -1 then g_objProfile.NonSquarePixelMode(0) = true end if if g_intVideoPreprocess >= 16 and g_intVideoPreprocess <= 18 then g_objProfile.InterlaceMode(0) = true end if if g_intMinPacketSize <> -1 then g_objProfile.MinPacketSize = g_intMinPacketSize end if ' Set the profile in encoder. g_objSourceGroup.Profile = g_objProfile if g_intMaxPacketSize <> -1 then g_objSourceGroup.Profile.MaxPacketSize = g_intMaxPacketSize end if g_intVideoFramerate = intVideoFramerateTemp if g_strVideoCodec = WMV9 and g_strVideoDevConf = "AP" then OutputInfo "WMV9 video codec does not include Advanced Profile." OutputInfo "If you wish to use Advanced Profile, please specify -v_codec WVC1" SetupProfile = false exit function end if if g_strVideoCodec = WVC1 and (g_strVideoDevConf = "SP" or g_strVideoDevConf = "MP") then OutputInfo "WVC1 video codec does not include Simple and Main profiles." OutputInfo "If you wish to use Simple or Main Profile, please specify -v_codec WMV9" SetupProfile = false exit function end if 'Set advanced WMV settings if g_strVideoCodec = WVC1 or g_strVideoCodec = WMV9 then ' Check if a previous WMCmd encoding session was aborted and registry settings were left behind accidentally - "dirty" flag if not IsEncoderRegistryDirty() then SaveEncoderRegistrySettings() end if ClearEncoderRegistrySettings() ' Set dirty flag that ensures we can detect if registry settings were accidentally left behind due to an aborted encode session g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\WMCmdDirtyFlag", 1, "REG_DWORD" ' Advanced Profile only if g_strVideoCodec = WVC1 then if g_intVideoCompOpt <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Compression Optimization Type", g_intVideoCompOpt, "REG_DWORD" end if if g_intVideoRangeRedux <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force Range Reduction", g_intVideoRangeRedux, "REG_DWORD" end if if g_intVideoMVCoding <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Motion Vector Coding Method", g_intVideoMVCoding, "REG_DWORD" end if if g_intVideoCodedWidth <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force Encoding Width", g_intVideoCodedWidth, "REG_DWORD" end if if g_intVideoCodedHeight <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force Encoding Height", g_intVideoCodedHeight, "REG_DWORD" end if if g_intVideoType <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\VideoType", g_intVideoType, "REG_DWORD" end if end if ' Advanced and Main Profiles only if not g_strVideoDevConf = "SP" then if g_intVideoDquantOption <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Dquant Option", g_intVideoDquantOption, "REG_DWORD" end if if g_intVideoDquantStrength <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Dquant Strength", g_intVideoDquantStrength, "REG_DWORD" end if if g_intVideoBDeltaQP <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force B Frame Delta QP", g_intVideoBDeltaQP, "REG_DWORD" end if if g_intVideoLoopfilter <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force LoopFilter", g_intVideoLoopfilter, "REG_DWORD" end if if g_intVideoMSRange <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Motion Search Range", g_intVideoMSRange, "REG_DWORD" end if if g_intVideoBFrameDist <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\NumBFrames", g_intVideoBFrameDist, "REG_DWORD" end if if g_intVideoPercOpt <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Perceptual Option", g_intVideoPercOpt, "REG_DWORD" end if end if ' All profiles if g_intVideoDenoise <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\DenoiseOption", g_intVideoDenoise, "REG_DWORD" end if if g_intVideoMedian <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force Median", g_intVideoMedian, "REG_DWORD" end if if g_intVideoEdgeRemoval <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force NoiseEdgeRemoval", g_intVideoEdgeRemoval, "REG_DWORD" end if if g_intVideoThreadAffinity <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Encoder Thread Affinity", g_intVideoThreadAffinity, "REG_DWORD" end if if g_intVideoNumThreads <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force NumThreads", g_intVideoNumThreads, "REG_DWORD" end if if g_intVideoOverlap <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force Overlap", g_intVideoOverlap, "REG_DWORD" end if if g_intVideoScaling <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Force Video Scaling", g_intVideoScaling, "REG_DWORD" end if if g_intVideoLookahead <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Lookahead", g_intVideoLookahead, "REG_DWORD" end if if g_intVideoLookaheadRC <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Lookahead Ratecontrol", g_intVideoLookaheadRC, "REG_DWORD" end if if g_intVideoMBModeCost <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Macroblock Mode Cost Method", g_intVideoMBModeCost, "REG_DWORD" end if if g_intVideoMMatch <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Motion Match Method", g_intVideoMMatch, "REG_DWORD" end if if g_intVideoMSLevel <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Motion Search Level", g_intVideoMSLevel, "REG_DWORD" end if if g_intVideoMVCost <> -128 then g_objWshShell.RegWrite g_strVideoEncoderRegistryKey & "\Motion Vector Cost Method", g_intVideoMVCost, "REG_DWORD" end if end if ' Invalid profile if err.number <> 0 then OutputInfo "Invalid profile: 0x" & Hex( err.number ) & " " & err.Description err.Clear SetupProfile = false exit function end if if g_strProfileSave <> "" then g_objProfile.SaveToFile g_strProfileSave end if SetupProfile = true end function ' Setup ouptut configuration. function SetupOutput() ' Is an output file name provided? if g_strOutput <> "" then ' Is this output name a directory? if g_objFileSystem.FolderExists( g_strOutput ) then ' If the output name is a directory, create the real output file name. ' If the input is a file, use the file name of the input file (extension is not ussed). ' If the inputs are devices, use 'output' as the output name. if g_strInput <> "" then g_strOutput = g_strOutput & "\\" & g_objFileSystem.GetBaseName( g_strInput ) else g_strOutput = g_strOutput & "\\output" end if end if ' If the output file name doesn't have a extension, create a proper one. if g_objFileSystem.GetExtensionName( g_strOutput ) = "" then ' Does "." already exist in the output file name. ' If not, append "." to the output file name. if Right( g_strOutput, 1 ) <> "." then g_strOutput = g_strOutput & "." end if ' Does this session have a video source? ' If it has video stream, append wmv extension, otherwise wma extension is appended. if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then g_strOutput = g_strOutput & "wmv" else g_strOutput = g_strOutput & "wma" end if end if CreateOutputFolder( g_objFileSystem.GetParentFolderName( g_objFileSystem.GetAbsolutePathName( g_strOutput ) ) ) g_objEncoder.File.LocalFileName = g_strOutput else ' Get the output file name from WME file. if not IsNull(g_objEncoder.File.LocalFileName) then g_strOutput = g_objEncoder.File.LocalFileName end if end if ' Enable HTTP broadcasting for the encoder if a broadcast port is provided. if g_intBroadcast <> -1 then g_objEncoder.Broadcast.PortNumber( WMENC_PROTOCOL_HTTP ) = g_intBroadcast end if ' Enable push if push server is specified if g_strPushServer <> "" then g_objEncoder.Broadcast.ServerName = g_strPushServer g_objEncoder.Broadcast.PublishingPoint = g_strPublishingPoint if g_strPushTemplate <> "" then g_objEncoder.Broadcast.Template = g_strPushTemplate end if end if SetupOutput = true end function ' Setup display configuration function SetupDisplayInfo() dim objDisplayInfo dim objAttributes set objDisplayInfo = g_objEncoder.DisplayInfo set objAttributes = g_objEncoder.Attributes ' Is title set? if g_strTitle <> "" then objDisplayInfo.Title = g_strTitle end if ' Is author set? if g_strAuthor <> "" then objDisplayInfo.Author = g_strAuthor end if ' Is album set? if g_strAlbum <> "" then objAttributes.Add "WM/AlbumTitle", CStr(g_strAlbum) end if ' Is genre set? if g_strGenre <> "" then objAttributes.Add "WM/Genre", CStr(g_strGenre) end if ' Is track number set? if (g_intTrackNo <> "") and (IsNumeric(g_intTrackNo)) then objAttributes.Add "WM/TrackNumber", CStr(CInt(g_intTrackNo)) objAttributes.Add "WM/Track", CStr(CInt(g_intTrackNo)-1) else g_intTrackNo = "" end if ' Is year set? if (g_strYear <> "") and (IsNumeric(g_strYear)) then objAttributes.Add "WM/Year", CStr(g_strYear) else g_strYear = "" end if ' Is copyright set? if g_strCopyright <> "" then objDisplayInfo.Copyright = g_strCopyright end if ' Is description set? if g_strDescription <> "" then objDisplayInfo.Description = g_strDescription end if ' Is rating set? if g_strRating <> "" then objDisplayInfo.Rating = g_strRating end if ' Add folddown coefficients if g_intAudioSurroundMix <> -1 then objAttributes.Add "SurroundMix", -g_intAudioSurroundMix objAttributes.Add "CenterMix", -g_intAudioCenterMix objAttributes.Add "LFEMix", -g_intAudioLEFMix end if SetupDisplayInfo = true end function ' Setup a new profile based on predefined profiles function SetupPredefinedProfile(objAudience) dim intAudioCodecIndex, intVideoCodecIndex ' The following defined built in profiles. Built in profiles are defined by the following: ' Audio: Codec, channels, sample rate, bit rate, bit depth ' Video: Codec, bit rate, width, height, fpsx1000, buffer (ms), smoothness, key frame ' New built in profiles can be added by creating a new case statement and specifying ' audio and video profile settings. select case LCase( g_strProfile ) case "av20": SetupAudioAudience objAudience, "WMASTD", 1, 8000, 5000, 16 SetupVideoAudience objAudience, "WMV9", 15000, 160, 120, 15000, 5000, 75, 10000 case "av32": SetupAudioAudience objAudience, "WMASTD", 1, 11025, 10168, 16 SetupVideoAudience objAudience, "WMV9", 22000, 176, 144, 15000, 5000, 75, 10000 case "av100": SetupAudioAudience objAudience, "WMASTD", 1, 16000, 16000, 16 SetupVideoAudience objAudience, "WMV9", 84000, 320, 240, 15000, 5000, 75, 10000 case "av225": SetupAudioAudience objAudience, "WMASTD", 2, 32000, 40000, 16 SetupVideoAudience objAudience, "WMV9", 185000, 320, 240, 30000, 5000, 75, 10000 case "av350": SetupAudioAudience objAudience, "WMASTD", 2, 32000, 48000, 16 SetupVideoAudience objAudience, "WMV9", 302000, 320, 240, 30000, 5000, 75, 10000 case "av450": SetupAudioAudience objAudience, "WMASTD", 2, 44100, 64040, 16 SetupVideoAudience objAudience, "WMV9", 386000, 320, 240, 30000, 5000, 75, 10000 case "av700": SetupAudioAudience objAudience, "WMASTD", 2, 44100, 64040, 16 SetupVideoAudience objAudience, "WMV9", 636000, 320, 240, 30000, 5000, 75, 10000 case "av1400": SetupAudioAudience objAudience, "WMASTD", 2, 44100, 128040, 16 SetupVideoAudience objAudience, "WMV9", 1272000, 320, 240, 30000, 5000, 75, 10000 case "av350pal": SetupAudioAudience objAudience, "WMASTD", 2, 32000, 48000, 16 SetupVideoAudience objAudience, "WMV9", 302000, 384, 288, 25000, 5000, 75, 10000 case "av700pal": SetupAudioAudience objAudience, "WMASTD", 2, 44100, 64040, 16 SetupVideoAudience objAudience, "WMV9", 636000, 384, 288, 25000, 5000, 75, 10000 case "av100_2p": SetupAudioAudience objAudience, "WMASTD", 1, 16000, 16000, 16 SetupVideoAudience objAudience, "WMV9", 84000, 320, 240, 15000, 5000, 75, 10000 g_objAudioSource.PreProcessPass = 1 g_objVideoSource.PreProcessPass = 1 case "av350_2p" SetupAudioAudience objAudience, "WMASTD", 2, 32000, 48000, 16 SetupVideoAudience objAudience, "WMV9", 302000, 320, 240, 30000, 5000, 75, 10000 g_objAudioSource.PreProcessPass = 1 g_objVideoSource.PreProcessPass = 1 case "av600vbr": g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK SetupAudioAudience objAudience, "WMASTD", 2, 44100, 64040, 16 SetupVideoAudience objAudience, "WMV9", 536000, 320, 240, 24000, 5000, 75, 10000 objAudience.VideoPeakBitrate(0) = 1.5 * objAudience.VideoBitrate(0) objAudience.VideoBufferMax(0) = 5000 ' Turn telecine and two pass video on g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE g_objVideoSource.PreProcessPass = 1 case "avq97vbr": g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED SetupAudioAudience objAudience, "WMASTD", 2, 44100, 64040, 16 SetupVideoAudience objAudience, "WMV9", 536000, 320, 240, 24000, 5000, 97, 10000 ' Turn telecine on g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE case "a20_1": SetupAudioAudience objAudience, "WMASTD", 1, 22050, 20008, 16 case "a20_2": SetupAudioAudience objAudience, "WMASTD", 2, 22050, 20008, 16 case "a32": SetupAudioAudience objAudience, "WMASTD", 2, 32000, 32000, 16 case "a48": SetupAudioAudience objAudience, "WMASTD", 2, 32000, 48024, 16 case "a64": SetupAudioAudience objAudience, "WMASTD", 2, 44100, 64016, 16 case "a96": SetupAudioAudience objAudience, "WMASTD", 2, 44100, 96024, 16 case "a128": SetupAudioAudience objAudience, "WMASTD", 2, 44100, 128016, 16 case "v20": SetupVideoAudience objAudience, "WMV9", 20000, 176, 144, 15000, 5000, 75, 10000 case "v32": SetupVideoAudience objAudience, "WMV9", 32000, 240, 176, 15000, 5000, 75, 10000 case else OutputInfo "No predefined profile found." SetupPredefinedProfile = false exit function end select SetupPredefinedProfile = true end function ' Given audio parameters this will setup the audience function SetupAudioAudience(objAudience, strAudioCodec, intChannels, intSampleRate, intBitrate, intBitsPerSample) dim intAudioCodecIndex intAudioCodecIndex = GetAudioCodecIndex(strAudioCodec) g_objProfile.EnumAudioCodec intAudioCodecIndex, g_strAudioCodecName objAudience.AudioCodec(0) = intAudioCodecIndex objAudience.SetAudioConfig 0, intChannels, intSampleRate, intBitrate, intBitsPerSample end function ' Given video parameters this will setup the audience function SetupVideoAudience(objAudience, strVideoCodec, intBitrate, intWidth, intHeight, intFps, intBufferWindow, intSmoothness, intKeyFrame) dim intVideoCodecIndex if intFps > g_intVideoFramerate then intFps = g_intVideoFramerate else g_intVideoFramerate = intFps end if intVideoCodecIndex = GetVideoCodecIndex(strVideoCodec) g_objProfile.EnumVideoCodec intVideoCodecIndex, g_strVideoCodecName objAudience.VideoCodec(0) = intVideoCodecIndex objAudience.VideoBitrate(0) = intBitrate objAudience.VideoWidth(0) = intWidth objAudience.VideoHeight(0) = intHeight objAudience.VideoFps(0) = intFps objAudience.VideoKeyFrameDistance(0) = intKeyFrame objAudience.VideoBufferSize(0) = intBufferWindow ' For quality vbr mode use intSmoothness as VBR quality if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED then objAudience.VideoCompressionQuality(0) = intSmoothness else objAudience.VideoImageSharpness(0) = intSmoothness end if end function ' Given audio string(eg WMASTD) this returns the audio codec index function GetAudioCodecIndex(strAudioCodec) dim intFourCC select case strAudioCodec case WMASTD intFourCC = WMASTD_FOURCC case WMAPRO intFourCC = WMAPRO_FOURCC case WMALSL intFourCC = WMALSL_FOURCC case WMSPEECH intFourCC = WMSPEECH_FOURCC case PCM intFourCC = PCM_FOURCC case else intFourCC = WMASTD_FOURCC end select GetAudioCodecIndex = g_objProfile.GetCodecIndexFromFourCC(WMENC_AUDIO, intFourCC) end function ' Given the video string(eg WMV9) this returns the video codec index function GetVideoCodecIndex(strVideoCodec) dim intFourCC select case strVideoCodec case WMV7 intFourCC = WMV7_FOURCC case WMV8 intFourCC = WMV8_FOURCC case WMV9 intFourCC = WMV9_FOURCC case WVC1 intFourCC = WVC1_FOURCC case WMS9 intFourCC = WMS9_FOURCC case MP41 intFourCC = MP41_FOURCC case UNCOMP intFourCC = UNCOMP_FOURCC case else intFourCC = WMV9_FOURCC end select GetVideoCodecIndex = g_objProfile.GetCodecIndexFromFourCC(WMENC_VIDEO, intFourCC) end function ' Setup a new profile based on predefined profiles function SetupCustomProfile(objAudience) dim intAudioCodecIndex, intVideoCodecIndex dim blnRet if not g_blnAudioOnly and not g_blnVideoOnly then if g_strVideoCodec = UNCOMP and g_strAudioCodec <> PCM then OutputInfo "Audio codec must be uncompressed when using uncompressed video codec" SetupCustomProfile = false exit function end if if g_strVideoCodec <> UNCOMP and g_strAudioCodec = PCM then OutputInfo "Video codec must be uncompressed when using uncompressed audio codec" SetupCustomProfile = false exit function end if end if if not isnull( g_objAudioSource ) then blnRet = SetupCustomAudioProfile( objAudience ) if not blnRet then SetupCustomProfile = false exit function end if end if if not isnull( g_objVideoSource ) then blnRet = SetupCustomVideoProfile( objAudience ) if not blnRet then SetupCustomProfile = false exit function end if end if SetupCustomProfile = true end function ' Setup the audio part of the custom profile function SetupCustomAudioProfile(objAudience) on error resume next ' Setup audio dim intAudioCodecIndex, intAudioBitrate, intAudioSampleRate, intAudioChannels, intBitDepth, intFourCC dim strTemp dim intNextArgStart, intNextArgEnd dim blnAudioQuality, blnValidBitrate, blnValidSampleRate, blnValidChannels, blnValidBitDepth 'Set audio vbr mode if g_intAudioVBRMode <> -1 then select case g_intAudioVBRMode case 0 ' 1 pass CBR case 1 ' 2 pass CBR g_objAudioSource.PreProcessPass = 1 case 2 ' Quality VBR mode g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_UNCONSTRAINED case 3 ' 2 pass bitrate based VBR g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_BITRATE_BASED g_objAudioSource.PreProcessPass = 1 case 4 ' 2 pass bitrate-based peak constrained VBR g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_PEAK g_objAudioSource.PreProcessPass = 1 case else OutputInfo "Invalid -a_mode <mode_number>" SetupCustomAudioProfile = false exit function end select end if ' Set audio codec if g_strAudioCodec <> "" then intAudioCodecIndex = GetAudioCodecIndex(g_strAudioCodec) intFourCC = g_objProfile.EnumAudioCodec(intAudioCodecIndex, g_strAudioCodecName) objAudience.AudioCodec(0) = intAudioCodecIndex end if 'Parse the a_setting string to extract audio bitrate sample rate and stuff like that if g_strAudioSetting <> "" then intNextArgStart = instr(g_strAudioSetting, "_") strTemp = left(g_strAudioSetting, intNextArgStart-1) if ucase( left(strTemp, 1) ) = "Q" then g_intAudioVBRMode = 2 g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_UNCONSTRAINED blnAudioQuality = true intAudioBitrate = ConvertStringToInteger( mid(strTemp, 2 ) ) else intAudioBitrate = ConvertStringToInteger( strTemp ) end if 'OutputInfo "****Audio bit rate is " & intAudioBitrate intNextArgEnd = instr(intNextArgStart+1, g_strAudioSetting, "_") strTemp = mid(g_strAudioSetting, intNextArgStart+1, intNextArgEnd-intNextArgStart-1) intAudioSampleRate = ConvertStringToInteger( strTemp ) 'OutputInfo "****Audio sample rate is " & intAudioSampleRate intNextArgStart = intNextArgEnd intNextArgEnd = instr(intNextArgStart+1, g_strAudioSetting, "_") if intNextArgEnd > 0 then strTemp = mid(g_strAudioSetting, intNextArgStart+1, intNextArgEnd-intNextArgStart-1) else strTemp = mid(g_strAudioSetting, intNextArgStart+1) end if intAudioChannels = ConvertStringToInteger( strTemp ) 'OutputInfo "****Audio channels are " & intAudioChannels if intNextArgEnd > 0 then strTemp = mid(g_strAudioSetting, intNextArgEnd+1) intBitDepth = ConvertStringToInteger( strTemp ) else intBitDepth = 16 end if 'OutputInfo "****Audio bit depth is " & intBitDepth if intAudioBitrate = -1 or intAudioSampleRate = -1 or intAudioChannels = -1 or intBitDepth = -1 then SetupCustomAudioProfile = false err.Raise &H80070057 exit function end if 'Convert bitrate and samplerate to actual values if blnAudioQuality = false then if intAudioBitrate = 1411 then intAudioBitrate = 1411200 elseif intAudioBitrate = 705 then intAudioBitrate = 705600 elseif intAudioBitrate = 353 then intAudioBitrate = 352800 else intAudioBitrate = 1000 * intAudioBitrate end if end if ' For peak vbr mode set peakbitrate and peak buffer if g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_PEAK then if g_intAudioPeakBuffer <> -1 then objAudience.AudioBufferMax(0) = g_intAudioPeakBuffer end if if g_intAudioPeakBitrate = -1 then objAudience.AudioPeakBitrate(0) = 1.5 * intAudioBitrate else objAudience.AudioPeakBitrate(0) = g_intAudioPeakBitrate end if 'OutputInfo "****Audio peak bit rate is " & objAudience.AudioPeakbitrate(0) 'OutputInfo "****Audio peak buffer is " & objAudience.AudioBufferMax(0) end if if intAudioSampleRate = 96 then intAudioSampleRate = 96000 elseif intAudioSampleRate = 88 then intAudioSampleRate = 88200 elseif intAudioSampleRate = 48 then intAudioSampleRate = 48000 elseif intAudioSampleRate = 44 then intAudioSampleRate = 44100 elseif intAudioSampleRate = 22 then intAudioSampleRate = 22050 elseif intAudioSampleRate = 11 then intAudioSampleRate = 11025 else intAudioSampleRate = 1000 * intAudioSampleRate end if ' Validate values for bitrate, samplerate, channels and depth if blnAudioQuality = false then blnValidBitrate = CheckForValidAudioBitRates( intAudioBitrate ) if blnValidBitrate = false then OutputInfo "Invalid audio bit rate " & intAudioBitrate SetupCustomAudioProfile = false exit function end if end if blnValidSampleRate = CheckForValidAudioSamplingRates( intAudioSampleRate ) if blnValidSampleRate = false then OutputInfo "Invalid audio sample rate " & intAudioSampleRate SetupCustomAudioProfile = false exit function end if blnValidChannels = CheckForValidAudioChannel( intAudioChannels ) if blnValidChannels = false then OutputInfo "Invalid audio channels " & intAudioChannels SetupCustomAudioProfile = false exit function end if blnValidBitDepth = CheckForValidDepth( intBitDepth ) if blnValidBitDepth = false then OutputInfo "Invalid bits per sample " & intBitDepth SetupCustomAudioProfile = false exit function end if objAudience.SetAudioConfig 0, intAudioChannels, intAudioSampleRate, intAudioBitrate, intBitDepth end if SetupCustomAudioProfile = true end function ' Setup the video part of the custom profile function SetupCustomVideoProfile(objAudience) on error resume next ' Setup audio dim intVideoCodecIndex, intFourCC 'Set video vbr mode if g_intVideoVBRMode <> -1 then select case g_intVideoVBRMode case 0 ' 1 pass CBR case 1 ' 2 pass CBR g_objVideoSource.PreProcessPass = 1 case 2 ' Quality VBR mode g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED case 3 ' 2 pass bitrate based VBR g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_BITRATE_BASED g_objVideoSource.PreProcessPass = 1 case 4 ' 2 pass bitrate-based peak constrained VBR g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK g_objVideoSource.PreProcessPass = 1 case else OutputInfo "Invalid -v_mode <mode_number>" SetupCustomVideoProfile = false exit function end select end if ' Set video codec if g_strVideoCodec <> "" then intVideoCodecIndex = GetVideoCodecIndex(g_strVideoCodec) intFourCC = g_objProfile.EnumVideoCodec(intVideoCodecIndex, g_strVideoCodecName) objAudience.VideoCodec(0) = intVideoCodecIndex end if if g_intVideoBitrate <> -1 then objAudience.VideoBitrate(0) = g_intVideoBitrate end if if g_intVideoWidth <> -1 then objAudience.VideoWidth(0) = g_intVideoWidth end if if g_intVideoHeight <> -1 then objAudience.VideoHeight(0) = g_intVideoHeight end if if g_intVideoFramerate <> -1 then objAudience.VideoFPS(0) = g_intVideoFramerate end if if g_intVideoKeydist <> -1 then objAudience.VideoKeyFrameDistance(0) = g_intVideoKeydist end if if g_intVideoBuffer <> -1 then objAudience.VideoBufferSize(0) = g_intVideoBuffer end if ' For quality vbr mode use intSmoothness as VBR quality if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED then if (g_intVideoQP <> -1) and (g_intVideoQuality = -1) then g_intVideoQuality = Int((31.01 - g_intVideoQP) / 0.3) end if if g_intVideoQuality <> -1 then objAudience.VideoCompressionQuality(0) = g_intVideoQuality end if else if g_intVideoQuality <> -1 then objAudience.VideoImageSharpness(0) = g_intVideoQuality end if end if ' For peak vbr mode set peakbitrate and peak buffer if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK then if g_intVideoPeakBuffer <> -1 then objAudience.VideoBufferMax(0) = g_intVideoPeakBuffer end if if g_intVideoPeakBitrate <> -1 then if objAudience.VideoBitrate(0) > g_intVideoPeakBitrate then objAudience.VideoBitrate(0) = g_intVideoPeakBitrate end if objAudience.VideoPeakBitrate(0) = g_intVideoPeakBitrate end if end if ' Setup video device conformance if g_strVideoDevConf <> "" then objAudience.Property( WMENC_VIDEO, 0, "DeviceConformanceTarget") = g_strVideoDevConf end if SetupCustomVideoProfile = true end function ' Load the default profile settings function LoadProfileDefaults() dim argsArray ' Audio profile settings ' Set default codec and/or VBR mode when appropriate if g_strAudioSetting <> "" then argsArray = Split ( g_strAudioSetting, "_" ) if UBound( argsArray ) = 3 and left(g_strAudioSetting, 4) <> "Q100" then g_strAudioCodec = WMAPRO end if end if if g_intAudioVBRMode = -1 then g_intAudioVBRMode = 0 end if if g_strAudioCodec = "" then g_strAudioCodec = "WMASTD" end if if g_intAudioPeakBuffer = -1 then g_intAudioPeakBuffer = 3000 end if ' Set default -a_setting based on format and mode if g_strAudioSetting = "" then if g_intAudioVBRMode = 2 and g_strAudioCodec = WMAPRO then g_strAudioSetting = "Q75_44_2_24" elseif g_intAudioVBRMode = 2 and g_strAudioCodec = WMALSL then g_strAudioSetting = "Q100_44_2_16" elseif g_intAudioVBRMode = 2 then g_strAudioSetting = "Q75_44_2" elseif g_intAudioVBRMode = 0 and g_strAudioCodec = WMSPEECH then g_strAudioSetting = "12_16_1" elseif g_intAudioVBRMode = 0 and g_strAudioCodec = PCM then g_strAudioSetting = "705_22_2" elseif g_strAudioCodec = WMAPRO then g_strAudioSetting = "128_44_2_24" else g_strAudioSetting = "64_44_2" end if end if ' Video profile settings if g_intVideoVBRMode = -1 then g_intVideoVBRMode = 0 end if if g_strVideoCodec = "" then g_strVideoCodec = "WMV9" end if if g_intVideoBitrate = -1 then g_intVideoBitrate = 250000 end if if g_intVideoWidth = -1 then g_intVideoWidth = 0 end if if g_intVideoHeight = -1 then g_intVideoHeight = 0 end if if g_intVideoKeydist = -1 then g_intVideoKeydist = 10000 end if if g_intVideoBuffer = -1 then g_intVideoBuffer = 5000 end if if g_intVideoPeakBuffer = -1 then g_intVideoPeakBuffer = 5000 end if if g_intVideoPeakBitrate = -1 then g_intVideoPeakBitrate = 1.5 * g_intVideoBitrate end if if g_intVideoQuality = -1 then if g_intVideoVBRMode = 2 then g_intVideoQuality = 95 else g_intVideoQuality = 75 end if end if end function ' Setup time configuration function SetupTime() if g_blnDevice then ' Duration must be specified when capture from a live device. if g_intDuration = -1 then OutputInfo "Duration must be specified when capturing from devices." SetupTime = false exit function end if end if ' Setup markin and markout if g_intMarkInTime <> -1 then ' Set start time for audio source (mark in) if it has a audio stream. if not IsNull(g_objAudioSource) then g_objAudioSource.MarkIn = g_intMarkInTime end if ' Set start time for video source (mark in) if it has a video stream. if not IsNull(g_objVideoSource) then g_objVideoSource.MarkIn = g_intMarkInTime end if end if ' Is a mark out time provided? if g_intMarkOutTime <> -1 then ' Set end time for audio source (mark out) if it has a audio stream. if not IsNull(g_objAudioSource) then g_objAudioSource.MarkOut = g_intMarkOutTime end if ' Set end time for video source (mark out) if it has a video stream. if not IsNull(g_objVideoSource) then g_objVideoSource.MarkOut = g_intMarkOutTime end if end if SetupTime = true end function ' Transcode function Transcode() on error resume next ' Prepare to encode g_objEncoder.PrepareToEncode( true ) ' Check if we got an error saying markout is greater that end of file. If so set markout to end of file if err.number = -1072882855 then err.Clear if not IsNull(g_objAudioSource) then g_objAudioSource.MarkOut = 0 end if if not IsNull(g_objVideoSource) then g_objVideoSource.MarkOut = 0 end if g_objEncoder.PrepareToEncode( true ) elseif err.number <> 0 then Transcode = false OutputInfo "Prepare to encode failed with error " & err.Number & " " & err.Description exit function end if ' Start encoder g_intErrorCode = 0 g_objEncoder.Start() if err.number <> 0 then Transcode = false OutputInfo "Start encoder failed with error " & err.Number & " " & err.Description exit function end if g_tStartTime = Now() ' Wait for start event while not g_blnEncoderStarted and g_intErrorCode = 0 WScript.Sleep( 1000 ) wend 'Once the encoder has started it's safe to clear and restore registry settings if g_strVideoCodec = WVC1 or g_strVideoCodec = WMV9 then ClearEncoderRegistrySettings() RestoreEncoderRegistrySettings() g_objWshShell.RegDelete g_strVideoEncoderRegistryKey & "\WMCmdDirtyFlag" end if on error goto 0 if g_intDuration >= 0 then ' Wait for time OutputInfo "Wait for " & g_intDuration & " seconds to stop encoder..." dim t1, t2 t1 = Now() ' Wait until an error code is received do while g_intErrorCode = 0 WScript.Sleep( 1000 ) t2 = Now() if DateDiff( "s", t1, t2 ) >= g_intDuration then OutputInfo "Duration time is reached. Stop encoder..." g_objEncoder.Stop() exit do end if if g_objEncoder.RunState = WMENC_ENCODER_STOPPED then OutputInfo "Encoding completed before duration time is reached." exit do end if loop else ShowProgress end if while not g_blnEncoderStopped and g_intErrorCode = 0 WScript.Sleep( 1000 ) wend ' Check error event if g_intErrorCode = 0 then OutputInfo "======== Encoding Completed ========" Transcode = true else OutputInfo "Error occurred in transcoding: Error Code = 0x" & Hex( g_intErrorCode ) Transcode = false end if end function ' Show statistics information of output function ShowStatistics() dim objProfile ' Output statistics for audio stream if not IsNull(g_objAudioSource) then dim objAudioStats set objAudioStats = g_objEncoder.Statistics.StreamOutputStats( WMENC_AUDIO, 0, 0 ) OutputInfo "" OutputInfo "Audio :" OutputInfo vbTab & "Codec: " & g_strAudioCodecName if g_intAudioVBRMode <> 2 then OutputInfo vbTab & "Expected bit rate: " & vbTab & objAudioStats.ExpectedBitrate & " bps" end if OutputInfo vbTab & "Average bit rate: " & vbTab & objAudioStats.AverageBitrate & " bps" OutputInfo vbTab & "Expected sample rate: " & vbTab & objAudioStats.ExpectedSampleRate OutputInfo vbTab & "Average sample rate: " & vbTab & objAudioStats.AverageSampleRate & "" OutputInfo vbTab & "Dropped byte count: " & vbTab & objAudioStats.DroppedByteCount*10000 & " bytes" OutputInfo vbTab & "Dropped sample rate: " & vbTab & objAudioStats.DroppedSampleCount*10000 & "" OutputInfo vbTab & "Total bytes: " & vbTab & vbTab & objAudioStats.ByteCount*10000 & " bytes" end if if not IsNull(g_objVideoSource) then dim objVideoStats set objVideoStats = g_objEncoder.Statistics.StreamOutputStats( WMENC_VIDEO, 0, 0 ) OutputInfo "" OutputInfo "Video :" OutputInfo vbTab & "Codec: " & g_strVideoCodecName if g_intVideoVBRMode <> 2 then OutputInfo vbTab & "Expected bit rate: " & vbTab & objVideoStats.ExpectedBitrate & " bps" end if OutputInfo vbTab & "Average bit rate: " & vbTab & objVideoStats.AverageBitrate & " bps" OutputInfo vbTab & "Expected fps: " & vbTab & vbTab & objVideoStats.ExpectedSampleRate / 1000 OutputInfo vbTab & "Dropped frame count: " & vbTab & objVideoStats.DroppedSampleCount*10000 & "" OutputInfo vbTab & "Total coded frames: " & vbTab & objVideoStats.SampleCount*10000 & "" OutputInfo vbTab & "Average sample rate: " & vbTab & objVideoStats.AverageSampleRate / 1000 & "" OutputInfo vbTab & "Dropped bytes: " & vbTab & vbTab & objVideoStats.DroppedByteCount*10000 & " bytes" OutputInfo vbTab & "Total bytes: " & vbTab & vbTab & objVideoStats.ByteCount*10000 & " bytes" end if ' Output statistics information of output stream OutputInfo "" OutputInfo "Overall:" OutputInfo vbTab & "Encoding time: " & vbTab & vbTab & DateDiff( "s", g_tStartTime, g_tStopTime ) & " seconds" OutputInfo vbTab & "Average bit rate: " & vbTab & g_objEncoder.Statistics.WMFOutputStats.AverageBitrate & " bps" if g_strOutput <> "" then dim objFileStats set objFileStats = g_objEncoder.Statistics.FileArchiveStats OutputInfo vbTab & "File size: " & vbTab & vbTab & objFileStats.FileSize*10000 & " bytes " OutputInfo vbTab & "File duration: " & vbTab & vbTab & objFileStats.FileDuration*10 & " seconds " end if end function ' Setup input configuration function SetupInput() dim strDeviceName ' The input file name is used if it is not empty, otherwise device index is used. if g_strInput <> "" then dim strInput2 strInput2 = g_objFileSystem.GetAbsolutePathName( g_strInput ) on error resume next ' Check for file existance if not g_objFileSystem.FileExists(strInput2) then err.Raise(53) OutputInfo "Input Error: 0x" & Hex(err.number) & " - " & err.description err.Clear SetupInput = false exit function end if if g_strProfile <> "" then dim strProfileName strProfileName = LCase( g_strProfile ) if Left( strProfileName, 1) = "a" and Mid( strProfileName, 2, 1 ) <> "v" then g_blnAudioOnly = true elseif Left( strProfileName, 1) = "v" then g_blnVideoOnly = true end if end if ' Check for existance of alternate audio input if g_strAudioInput <> "" then dim strAudioInput2 strAudioInput2 = g_objFileSystem.GetAbsolutePathName( g_strAudioInput ) ' Check for file existance if not g_objFileSystem.FileExists(strAudioInput2) then err.Raise(53) OutputInfo "Audio Input Error: 0x" & Hex(err.number) & " - " & err.description err.Clear SetupInput = false exit function end if end if ' Add this file into the source group. if g_blnAudioOnly then set g_objAudioSource = g_objSourceGroup.AddSource( WMENC_AUDIO ) g_objAudioSource.SetInput( strInput2 ) elseif g_blnVideoOnly then set g_objVideoSource = g_objSourceGroup.AddSource( WMENC_VIDEO ) g_objVideoSource.SetInput( strInput2 ) ' If alternate audio source is defined, add video and audio sources separately elseif strAudioInput2 <> "" then set g_objVideoSource = g_objSourceGroup.AddSource( WMENC_VIDEO ) g_objVideoSource.SetInput( strInput2 ) set g_objAudioSource = g_objSourceGroup.AddSource( WMENC_AUDIO ) g_objAudioSource.SetInput( strAudioInput2 ) ' Otherwise just automatically parse the single intput for streams else g_objSourceGroup.AutoSetFileSource( strInput2 ) ' If source file has an auido stream, get the audio source. if g_objSourceGroup.SourceCount( WMENC_AUDIO ) > 0 then set g_objAudioSource = g_objSourceGroup.Source( WMENC_AUDIO, 0 ) end if ' If source file has a video stream, get the video source. if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then set g_objVideoSource = g_objSourceGroup.Source( WMENC_VIDEO, 0 ) end if end if elseif g_intAudioDevice <> -1 or g_intVideoDevice <> -1 then if g_intAudioDevice <> -1 then strDeviceName = GetDeviceNameFromIndex( WMENC_AUDIO, g_intAudioDevice ) if strDeviceName = "" then OutputInfo "Error: Invalid audio device number specified" SetupInput = false exit function end if set g_objAudioSource = g_objSourceGroup.AddSource( WMENC_AUDIO ) g_objAudioSource.SetInput strDeviceName, "device" end if if g_intVideoDevice <> -1 then strDeviceName = GetDeviceNameFromIndex( WMENC_VIDEO, g_intVideoDevice ) if strDeviceName = "" then OutputInfo "Error: Invalid video device number specified" SetupInput = false exit function end if set g_objVideoSource = g_objSourceGroup.AddSource( WMENC_VIDEO ) g_objVideoSource.SetInput strDeviceName, "device" end if end if if g_objSourceGroup.SourceCount( WMENC_AUDIO ) and g_objSourceGroup.SourceCount( WMENC_VIDEO ) then g_intSessionType = WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO elseif g_objSourceGroup.SourceCount( WMENC_AUDIO ) then g_intSessionType = WMENC_CONTENT_ONE_AUDIO elseif g_objSourceGroup.SourceCount( WMENC_VIDEO ) then g_intSessionType = WMENC_CONTENT_ONE_VIDEO end if ' Set audio setting for speech if not IsNull(g_objAudioSource) then SetupAudioSource() end if ' Set video settings if not IsNull(g_objVideoSource) then SetupVideoSource() end if if err.number <> 0 then OutputInfo "Error: 0x" & Hex(err.number) & " - " & err.description err.Clear SetupInput = false exit function end if SetupInput = true end function 'Set speech related settings on audio source function SetupAudioSource() if g_intAudioSpeechContent <> -1 then g_objAudioSource.contentmode = g_intAudioSpeechContent end if if g_strAudioSpeechEdl <> "" then g_objAudioSource.contentedl = g_strAudioSpeechEdl end if end function 'Set settings on video source function SetupVideoSource() ' Set video preprocess select case g_intVideoPreprocess case 0 g_objVideoSource.Optimization = WMENC_VIDEO_STANDARD case 1 g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE case 2 g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE case 3 g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE case 4 g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE case 5 g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE case 6 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_AA_TOP case 7 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BB_TOP case 8 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BC_TOP case 9 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_CD_TOP case 10 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_DD_TOP case 11 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_AA_BOTTOM case 12 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BB_BOTTOM case 13 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BC_BOTTOM case 14 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_CD_BOTTOM case 15 g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_DD_BOTTOM case 16 g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_AUTO case 17 g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_TOP_FIRST case 18 g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_BOTTOM_FIRST end select 'Set pixelformat select case ucase( g_strPixelFormat ) case "I420" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_I420 case "IYUV" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_IYUV case "RGB24" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB24 case "RGB32" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB32 case "RGB555" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB555 case "RGB565" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB565 case "RGB8" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB8 case "UYVY" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_UYVY case "YUY2" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YUY2 case "YV12" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YV12 case "YVU9" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YVU9 case "YVYU" g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YVYU end select 'Set pixel aspect ratio if g_intPixelAspectRatioX <> -1 then g_objVideoSource.PixelAspectRatioX = g_intPixelAspectRatioX end if if g_intPixelAspectRatioY <> -1 then g_objVideoSource.PixelAspectRatioY = g_intPixelAspectRatioY end if 'Set performance if g_intVideoPerformance <> -1 then g_objEncoder.VideoComplexity = g_intVideoPerformance end if 'Set clipping margins if g_intClipLeft <> -1 then g_objVideoSource.CroppingLeftMargin = g_intClipLeft end if if g_intClipRight <> -1 then g_objVideoSource.CroppingRightMargin = g_intClipRight end if if g_intClipTop <> -1 then g_objVideoSource.CroppingTopMargin = g_intClipTop end if if g_intClipBottom <> -1 then g_objVideoSource.CroppingBottomMargin = g_intClipBottom end if end function 'This function is used to check if the bit rate specified for the a_setting param is valid function CheckForValidAudioBitRates( intBitRate ) select case intBitRate case 1536000, 1411200,1280000,1024000,768000,705600,640000,440000,384000,383000,_ 352800,320000,256000,255000,192000,191000,160000,128000,127000,96000,95000,_ 80000,64000,63000,48000,40000,32000,24000,22000,20000,17000,16000,12000,10000,_ 8000,6000,5000,4000,0 CheckForValidAudioBitRates = True case else CheckForValidAudioBitRates = False end select end function 'This function is used to check if the sampling rate specified for the a_setting param is valid function CheckForValidAudioSamplingRates( intSamplingRate ) select case intSamplingRate case 96000,88200,48000,44100,32000,22050,16000,11025,8000 CheckForValidAudioSamplingRates = True case else CheckForValidAudioSamplingRates = False end select end function 'This function is used to check if the channel specified for the a_setting param is valid function CheckForValidAudioChannel( intChannel ) select case intChannel case 1,2,6,8 CheckForValidAudioChannel = True case else CheckForValidAudioChannel = False end select end function 'This function is used to check if the depth specified for the a_setting param is valid function CheckForValidDepth( intAudioDepth ) select Case intAudioDepth case 16,20,24 CheckForValidDepth = True case else CheckForValidDepth = False end select end function 'This function is the top level function for directory based encoding function DoDirectoryModeEncoding() dim strInputFull dim strOutputFull if g_strOutput = "" then OutputInfo "Error: No output directory specified" DoDirectoryModeEncoding = false exit function end if strInputFull = g_objFileSystem.GetAbsolutePathName(g_strInput) strOutputFull = g_objFileSystem.GetAbsolutePathName(g_strOutput) EncodeFilesInFolder strInputFull, strOutputFull end function 'This function will create all folders down to the strFolderName level function CreateOutputFolder( strFolderName ) if g_objFileSystem.FolderExists(strFolderName) = false then CreateOutputFolder( g_objFileSystem.GetParentFolderName( strFolderName ) ) g_objFileSystem.CreateFolder( strFolderName ) end if end function 'This function will encode all files in the input directory and generate output files in output directory function EncodeFilesInFolder( strInputFolderName, strOutputFolderName ) dim objSubFoldersCollection dim objInputSubFolder dim strOutputSubFolderName, strFileType dim objFile, objFolder, objFileCollection OutputInfo "============== Encoding Files in Folder ============== " & strInputFolderName set objFolder = g_objFileSystem.GetFolder( strInputFolderName ) ' First encode all the files contained in the input folder set objFileCollection = objFolder.Files for each objFile in objFileCollection strFileType = right(objFile.name, len(objFile.name) - instrrev(objFile.name,".") ) select case lcase(strFileType) case "avi", "wav", "mpg", "mpeg", "vob" , "wmv" , "wma", "mp3", "asf", "avs" g_strInput = strInputFolderName & "\" & objFile.name g_strOutput = strOutputFolderName & "\" & Left(objFile.name, len(objFile.Name)-(len(objFile.name) - instrrev(objFile.name,".") + 1)) & g_strOutputString OutputInfo "============== Input " & g_strInput & " " & g_strOutput ' This will force wmcmd to append wmv/wma extension g_strOutput = g_strOutput & "." ' Encode files if SetupEncoder() then if Transcode() and not g_blnSilent then ShowStatistics() end if end if ' reset encoder states for next file g_objEncoder.PrepareToEncode( false ) g_objEncoder.SourceGroupCollection.Remove( "SG_1" ) g_objSourceGroup = Null g_objAudioSource = Null g_objVideoSource = Null g_blnEncoderStarted = false g_blnEncoderStopped = false g_blnEndPreProcess = false case else OutputInfo "Skipping: " & objFile.name end select next ' Then recurse into subfolders and encode all files there set objSubFoldersCollection = objFolder.SubFolders for each objInputSubFolder in objSubFoldersCollection strOutputSubFolderName = strOutputFolderName & "\" & objInputSubFolder.name EncodeFilesInFolder objInputSubFolder, strOutputSubFolderName Next end function ' Get device name from index function GetDeviceNameFromIndex(enumMediaType, intDeviceIndex) dim intLastDevice dim objSourceInfo, objSourcePluginManager intLastDevice = 0 set objSourcePlugInManager = g_objEncoder.SourcePlugInInfoManager for i = 0 to objSourcePlugInManager.count -1 set objSourceInfo = objSourcePlugInManager.Item(i) if objSourceInfo.Resources = true then if enumMediaType = WMENC_AUDIO then ' Audio ' For audio search audio and audio | video if objSourceInfo.MediaType = 1 or objSourceInfo.MediaType = 3 then if intDeviceIndex < intLastDevice + objSourceInfo.Count then GetDeviceNameFromIndex = objSourceInfo( intDeviceIndex - intLastDevice ) exit function else intLastDevice = intLastDevice + objSourceInfo.Count end if end if else ' Video ' For video search video, audio | video and video | script if objSourceInfo.MediaType = 2 or objSourceInfo.MediaType = 3 or objSourceInfo.MediaType = 6 then if intDeviceIndex < intLastDevice + objSourceInfo.Count Then GetDeviceNameFromIndex = objSourceInfo( intDeviceIndex - intLastDevice ) exit function else intLastDevice = intLastDevice + objSourceInfo.Count end if end if end if end if next GetDeviceNameFromIndex = "" end function function CheckAndEnablePlaybackinWMP(ext) On Error Resume Next dim regAVS, intPermissions, intRuntime ' Check if extension key already exists regAVS = g_objWshShell.RegRead("HKCU\Software\Microsoft\MediaPlayer\Player\Extensions\" & ext & "\") if err <> 0 then g_objWshShell.RegWrite "HKCU\Software\Microsoft\MediaPlayer\Player\Extensions\" & ext & "\Permissions", 1, "REG_DWORD" g_objWshShell.RegWrite "HKCU\Software\Microsoft\MediaPlayer\Player\Extensions\" & ext & "\Runtime", 7, "REG_DWORD" else intPermissions = -1 intRuntime = -1 intPermissions = g_objWshShell.RegRead("HKCU\Software\Microsoft\MediaPlayer\Player\Extensions\" & ext & "\Permissions") intRuntime = g_objWshShell.RegRead("HKCU\Software\Microsoft\MediaPlayer\Player\Extensions\" & ext & "\Runtime") if intPermissions < 1 then g_objWshShell.RegWrite "HKCU\Software\Microsoft\MediaPlayer\Player\Extensions\" & ext & "\Permissions", 1, "REG_DWORD" if intRuntime < 7 then g_objWshShell.RegWrite "HKCU\Software\Microsoft\MediaPlayer\Player\Extensions\" & ext & "\Runtime", 7, "REG_DWORD" end if end function function GetAlternateSourceDuration() On Error Resume Next dim intTimeOut dim intWMPMediaDuration dim objWMP dim strInput2 dim blnWMPError objWMP = Null intWMPMediaDuration = -1 blnWMPError = false strInput2 = g_objFileSystem.GetAbsolutePathName( g_strInput ) OutputInfo "Warning: Encoder failed to retrieve duration attribute from source plug-in." WScript.Stdout.Write " Trying alternate method now." ' Initialize Windows Media Player ActiveX control set objWMP = WScript.CreateObject( "WMPlayer.OCX" ) if not IsNull(objWMP) then ' If source unknown, enable playback in WMP - override security dialog CheckAndEnablePlaybackinWMP(Right( LCase( g_strInput ), 4 )) ' Mute player volume objWMP.settings.mute = True ' Load source media objWMP.URL = strInput2 intTimeOut = 0 ' Wait for the media to open or time out after 30 seconds do while (intTimeOut < 30) and not (objWMP.openState = 13) WScript.stdout.Write "." WScript.Sleep(1000) intTimeOut = intTimeOut + 1 loop OutputInfo "." ' Proceed only if media was successfully opened if intTimeOut < 30 then if not IsNull(objWMP.currentMedia) then ' If media is not playing yet, wait another 3 seconds before retrieving duration if objWMP.playState <> 3 then WScript.Sleep(3000) intWMPMediaDuration = objWMP.currentMedia.duration if intWMPMediaDuration <> -1 then g_intAudioSourceDuration = intWMPMediaDuration * 1000 g_intVideoSourceDuration = intWMPMediaDuration * 1000 OutputInfo "Source duration retrieved: " & intWMPMediaDuration & " seconds." else blnWMPError = true end if else blnWMPError = true end if else blnWMPError = true end if ' Request Player shutdown objWMP.Close() WScript.Sleep(500) set objWMP = Nothing else blnWMPError = true end if if blnWMPError then OutputInfo "" OutputInfo "Warning: Encoder failed to retrieve source duration again." OutputInfo " Encode process might not continue or progress report may be inaccurate." g_intAudioSourceDuration = 0 g_intVideoSourceDuration = 0 end if OutputInfo "" end function function ConvertSecondsToHHMMSS( intSeconds ) ' Takes time in seconds as input and outputs a string formatted as hh:mm:ss dim intHH, intMM, intSS dim strHH, strMM, strSS intSS = Int(intSeconds mod 60) intMM = Int((intSeconds\60) mod 60) intHH = Int(intSeconds\3600) if intSS < 10 then strSS = "0" & intSS else strSS = CStr(intSS) end if if intMM < 10 then strMM = "0" & intMM else strMM = CStr(intMM) end if if intHH < 10 then strHH = "0" & intHH else strHH = CStr(intHH) end if ConvertSecondsToHHMMSS = strHH & ":" & strMM & ":" & strSS end function function ShowProgress() dim intSleepDuration, intPercent, intADuration, intVDuration, intDuration dim intPasses, intLimit, intCurrentPosition, tPassStartTime, intTimeElapsed, intTimeLeft, intLastPosition OutputInfo g_strProductName OutputInfo g_strProductCopyright OutputInfo "" ' Display metadata information passed to the encoder script if g_strTitle <> "" then OutputInfo "Title: " & g_strTitle end if if (g_intTrackNo <> "") and (IsNumeric(g_intTrackNo)) then OutputInfo "Track No: " & g_intTrackNo end if if g_strAuthor <> "" then OutputInfo "Artist: " & g_strAuthor end if if g_strAlbum <> "" then OutputInfo "Album: " & g_strAlbum end if if g_strYear <> "" then OutputInfo "Year: " & g_strYear end if if g_strGenre <> "" then OutputInfo "Genre: " & g_strGenre end if if g_strCopyright <> "" then OutputInfo "Copyright: " & g_strCopyright end if if g_strDescription <> "" then OutputInfo "Comment: " & g_strDescription end if OutputInfo "" intPasses = 1 ' Compute number of passes required if not IsNull(g_objAudioSource) then if g_objAudioSource.PreProcessPass = 1 then intPasses = 2 end if end if if not IsNull(g_objVideoSource) then if g_objVideoSource.PreProcessPass = 1 then intPasses = 2 end if end if ' Check if source duration property is available - enable error handling On Error Resume Next if not IsNull(g_objAudioSource) then g_intAudioSourceDuration = g_objAudioSource.Duration if IsNull(g_objAudioSource.Duration) then g_blnDurationError = True end if end if if not IsNull(g_objVideoSource) then g_intVideoSourceDuration = g_objVideoSource.Duration if IsNull(g_objVideoSource.Duration) then g_blnDurationError = True end if end if if g_blnDurationError then ' Try to retrieve the source duration through Windows Media Player OCX GetAlternateSourceDuration() end if On Error Goto 0 ' Compute file duration and compensate for mark in/out if not IsNull(g_objAudioSource) then if g_objAudioSource.MarkOut <> 0 then intADuration = g_objAudioSource.MarkOut - g_objAudioSource.MarkIn else intADuration = g_intAudioSourceDuration - g_objAudioSource.MarkIn end if end if if not IsNull(g_objVideoSource) then if g_objVideoSource.MarkOut <> 0 then intVDuration = g_objVideoSource.MarkOut - g_objVideoSource.MarkIn else intVDuration = g_intVideoSourceDuration - g_objVideoSource.MarkIn end if end if if intADuration > intVDuration then intDuration = intADuration else intDuration = intVDuration end if intSleepDuration = 2000 intLimit = 100 ' For all passes show progress from 0 to 100 for j=0 to intPasses-1 intPercent = 0 intCurrentPosition = 0 intLastPosition = 0 intTimeElapsed = 0 intTimeLeft = 0 tPassStartTime = Now() if intPasses = 2 and j = 0 then OutputInfo "======== Begin Pass1 ========" elseif intPasses = 2 and j = 1 then OutputInfo "======== Begin Pass2 ========" end if do while g_objEncoder.RunState <> WMENC_ENCODER_STOPPED and g_intErrorCode = 0 and Int(intPercent) < intLimit if intDuration = 0 then WScript.stdout.Write "." else intPercent = g_objEncoder.Statistics.EncodingTime * 1000000 / intDuration intCurrentPosition = g_objEncoder.Statistics.EncodingTime*10 ' Check if the current position has lapped itself, indicating that 2nd pass has started if intPasses = 2 and j = 0 and intLastPosition > intCurrentPosition then exit Do end if ' Time elapsed since start of current pass. Total encoding time is tracked separately intTimeElapsed = DateDiff("s", tPassStartTime, Now()) ' Add 0.001 to divisor to prevent division-by-zero errors intTimeLeft = ( (0.001 * intDuration / (intCurrentPosition+0.001)) * intTimeElapsed ) - intTimeElapsed if intTimeLeft < 0 then intTimeLeft = 0 ' Prevents ugly negative output end if WScript.stdout.Write vbCr if intPasses = 2 and j = 0 then WScript.stdout.Write "Read: " else WScript.stdout.Write "Encoded: " end if WScript.stdout.Write Round(intCurrentPosition,1) & "s (" & Round(intPercent,1) & "%) " WScript.stdout.Write "Elapsed: " & ConvertSecondsToHHMMSS(intTimeElapsed) & " " WScript.stdout.Write "Left: " & ConvertSecondsToHHMMSS(intTimeLeft) & " [" WScript.stdout.Write Round(intCurrentPosition/(intTimeElapsed+0.001),2) & "x] " intLastPosition = intCurrentPosition end if WScript.Sleep intSleepDuration loop if g_intErrorCode <> 0 then OutputInfo vbCrLf & "Encoder error: 0x" & Hex( g_intErrorCode ) exit for end if if j = 0 and intPasses = 2 then do while not g_blnEndPreProcess and g_intErrorCode = 0 WScript.Sleep intSleepDuration loop end if if g_intErrorCode <> 0 then OutputInfo vbCrLf & "Encoder error: 0x" & Hex( g_intErrorCode ) exit for end if OutputInfo "" OutputInfo "" next end function function TerminateEncoderProcess() dim objWMIService dim objProcess On Error Resume Next ' Get Windows Manager object Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") ' Enumerate all CScript.exe processes dim colProcessList Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'cscript.exe'") dim strArguments strArguments = "" ' Enumerate all command-line arguments for i = 0 to wscript.arguments.Length-1 strArguments = strArguments & " " & wscript.arguments(i) next strArguments = Replace(strArguments, Chr(34), "") ' Kill the processes that match this one in name and arguments For Each objProcess in colProcessList if InStr(1, Replace(objProcess.CommandLine, Chr(34), ""), Trim(WScript.ScriptName & strArguments), 1 ) > 0 then objProcess.Terminate() end if Next ' What? Still not terminated? OK, kill first occurrence. For Each objProcess in colProcessList if InStr(1, objProcess.CommandLine, WScript.ScriptName) > 0 then objProcess.Terminate() end if Next end function