home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 October / PCWorld_2002-10_cd.bin / Software / TemaCD / wmenc9 / WMEncoder.exe / WMEncoder.msi / WMCmd.vbs < prev    next >
Encoding:
Text File  |  2002-08-19  |  100.3 KB  |  3,351 lines

  1. 'The build number is 9.00.2799
  2. '*****************************************************************************
  3. '
  4. ' Microsoft Windows Media
  5. ' Copyright (C) Microsoft Corporation. All rights reserved.
  6. '
  7. ' FileName:            WMCMD.VBS
  8. '
  9. ' Abstract:            Windows Media Command Line Script Utility
  10. '                      Use Cscript.exe wmcmd.vbs /? for Help
  11. '
  12. '*****************************************************************************
  13.  
  14. Option Explicit
  15.  
  16. ' Check to see if script is run within cscript host.
  17. if instr( LCase(WScript.Fullname),"cscript.exe" ) = 0 then
  18.     WshShell.Popup "This script must be run using cscript.exe from a command window." , 0 , "Windows Media Encoder Command Script" , 64
  19.     WScript.Quit()
  20. end if
  21.  
  22. ' These variables are part of encoder idl. However vbs cannot use them directly. So these are redefined
  23. dim WMENC_ENCODER_STARTING
  24. dim WMENC_ENCODER_RUNNING
  25. dim WMENC_ENCODER_PAUSED
  26. dim WMENC_ENCODER_STOPPING
  27. dim WMENC_ENCODER_STOPPED
  28. dim WMENC_ENCODER_END_PREPROCESS
  29.  
  30. dim WMENC_ARCHIVE_LOCAL
  31. dim WMENC_ARCHIVE_RUNNING
  32. dim WMENC_ARCHIVE_PAUSED
  33. dim WMENC_ARCHIVE_STOPPED
  34.  
  35. dim WMENC_AUDIO
  36. dim WMENC_VIDEO
  37. dim WMENC_SCRIPT
  38. dim WMENC_FILETRANSFER
  39.  
  40. dim WMENC_SOURCE_START
  41. dim WMENC_SOURCE_STOP
  42. dim WMENC_SOURCE_PREPARE
  43. dim WMENC_SOURCE_UNPREPARE
  44. dim WMENC_START_FILETRANSFER
  45. dim WMENC_STOP_FILETRANSFER
  46.  
  47. dim WMENC_PROTOCOL_HTTP
  48. dim WMENC_PROTOCOL_PUSH_DISTRIBUTION
  49.  
  50. dim WMENC_PVM_NONE
  51. dim WMENC_PVM_PEAK
  52. dim WMENC_PVM_UNCONSTRAINED
  53. dim WMENC_PVM_BITRATE_BASED
  54.  
  55. dim WMA9STD_FOURCC
  56. dim WMA9PRO_FOURCC
  57. dim WMA9LSL_FOURCC
  58. dim WMSPEECH_FOURCC
  59. dim PCM_FOURCC
  60.  
  61. dim WMV7_FOURCC
  62. dim WMV8_FOURCC
  63. dim WMV9_FOURCC
  64. dim WMS9_FOURCC
  65. dim MP41_FOURCC
  66. dim UNCOMP_FOURCC
  67.  
  68. dim WMA9STD
  69. dim WMA9PRO
  70. dim WMA9LSL
  71. dim WMSPEECH
  72. dim PCM
  73.  
  74. dim WMV7
  75. dim WMV8
  76. dim WMV9
  77. dim WMS9
  78. dim MP41
  79. dim UNCOMP
  80.  
  81. dim WMENC_CONTENT_ONE_AUDIO
  82. dim WMENC_CONTENT_ONE_VIDEO
  83. dim WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO
  84.  
  85. dim WMENC_VIDEO_STANDARD
  86. dim WMENC_VIDEO_DEINTERLACE
  87. dim WMENC_VIDEO_INVERSETELECINE
  88. dim WMENC_VIDEO_PROCESS_INTERLACED
  89. dim WMENC_VIDEO_TELECINE_AUTO
  90. dim WMENC_VIDEO_TELECINE_AA_TOP
  91. dim WMENC_VIDEO_TELECINE_BB_TOP
  92. dim WMENC_VIDEO_TELECINE_BC_TOP
  93. dim WMENC_VIDEO_TELECINE_CD_TOP
  94. dim WMENC_VIDEO_TELECINE_DD_TOP
  95. dim WMENC_VIDEO_TELECINE_AA_BOTTOM
  96. dim WMENC_VIDEO_TELECINE_BB_BOTTOM
  97. dim WMENC_VIDEO_TELECINE_BC_BOTTOM
  98. dim WMENC_VIDEO_TELECINE_CD_BOTTOM
  99. dim WMENC_VIDEO_TELECINE_DD_BOTTOM
  100. dim WMENC_VIDEO_INTERLACED_AUTO
  101. dim WMENC_VIDEO_INTERLACED_TOP_FIRST
  102. dim WMENC_VIDEO_INTERLACED_BOTTOM_FIRST
  103. dim WMENC_PIXELFORMAT_IYUV
  104. dim WMENC_PIXELFORMAT_I420
  105. dim WMENC_PIXELFORMAT_YV12
  106. dim WMENC_PIXELFORMAT_YUY2
  107. dim WMENC_PIXELFORMAT_UYVY
  108. dim WMENC_PIXELFORMAT_YVYU
  109. dim WMENC_PIXELFORMAT_YVU9
  110. dim WMENC_PIXELFORMAT_RGB24
  111. dim WMENC_PIXELFORMAT_RGB32
  112. dim WMENC_PIXELFORMAT_RGB555
  113. dim WMENC_PIXELFORMAT_RGB565
  114. dim WMENC_PIXELFORMAT_RGB8
  115.  
  116. WMENC_ENCODER_STARTING = 1
  117. WMENC_ENCODER_RUNNING = 2
  118. WMENC_ENCODER_PAUSED = 3
  119. WMENC_ENCODER_STOPPING = 4
  120. WMENC_ENCODER_STOPPED = 5
  121. WMENC_ENCODER_END_PREPROCESS = 6
  122.  
  123. WMENC_ARCHIVE_LOCAL = 1
  124.  
  125. WMENC_ARCHIVE_RUNNING = 1
  126. WMENC_ARCHIVE_PAUSED = 2
  127. WMENC_ARCHIVE_STOPPED = 3
  128.  
  129. WMENC_AUDIO = 1
  130. WMENC_VIDEO = 2
  131. WMENC_SCRIPT = 4
  132. WMENC_FILETRANSFER = 8
  133.  
  134. WMENC_SOURCE_START = 1
  135. WMENC_SOURCE_STOP = 2
  136. WMENC_SOURCE_PREPARE = 3
  137. WMENC_SOURCE_UNPREPARE = 4
  138. WMENC_START_FILETRANSFER = 5
  139. WMENC_STOP_FILETRANSFER = 6
  140.  
  141. WMENC_PROTOCOL_HTTP = 1
  142. WMENC_PROTOCOL_PUSH_DISTRIBUTION = 2
  143.  
  144. WMENC_PVM_NONE = 1
  145. WMENC_PVM_PEAK = 2
  146. WMENC_PVM_UNCONSTRAINED = 3
  147. WMENC_PVM_BITRATE_BASED = 4
  148.  
  149. WMA9STD_FOURCC = 353
  150. WMA9PRO_FOURCC = 354
  151. WMA9LSL_FOURCC = 355
  152. WMSPEECH_FOURCC = 10
  153. PCM_FOURCC = 0
  154.  
  155. WMV7_FOURCC = 827739479
  156. WMV8_FOURCC = 844516695
  157. WMV9_FOURCC = 861293911
  158. WMS9_FOURCC = 844321613
  159. MP41_FOURCC = 1395937357
  160. UNCOMP_FOURCC = 0
  161.  
  162. WMA9STD = "WMA9STD"
  163. WMA9PRO = "WMA9PRO"
  164. WMA9LSL = "WMA9LSL"
  165. WMSPEECH = "WMSP9"
  166. PCM = "PCM"
  167.  
  168. WMV7 = "WMV7"
  169. WMV8 = "WMV8"
  170. WMV9 = "WMV9"
  171. WMS9 = "WMS9"
  172. MP41 = "MP41"
  173. UNCOMP = "UNCOMP"
  174.  
  175. WMENC_CONTENT_ONE_AUDIO = 1
  176. WMENC_CONTENT_ONE_VIDEO = 16
  177. WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO = 17
  178.  
  179. WMENC_VIDEO_STANDARD = 1
  180. WMENC_VIDEO_DEINTERLACE = 2
  181. WMENC_VIDEO_INVERSETELECINE = 3
  182. WMENC_VIDEO_PROCESS_INTERLACED = 4
  183. WMENC_VIDEO_TELECINE_AA_TOP = &H23
  184. WMENC_VIDEO_TELECINE_BB_TOP = &H33
  185. WMENC_VIDEO_TELECINE_BC_TOP = &H43
  186. WMENC_VIDEO_TELECINE_CD_TOP = &H53
  187. WMENC_VIDEO_TELECINE_DD_TOP = &H63
  188. WMENC_VIDEO_TELECINE_AA_BOTTOM = &H73
  189. WMENC_VIDEO_TELECINE_BB_BOTTOM = &H83
  190. WMENC_VIDEO_TELECINE_BC_BOTTOM = &H93
  191. WMENC_VIDEO_TELECINE_CD_BOTTOM = &HA3
  192. WMENC_VIDEO_TELECINE_DD_BOTTOM = &HB3
  193. WMENC_VIDEO_INTERLACED_AUTO = 4
  194. WMENC_VIDEO_INTERLACED_TOP_FIRST = &H2004
  195. WMENC_VIDEO_INTERLACED_BOTTOM_FIRST = &H3004
  196.  
  197. WMENC_PIXELFORMAT_IYUV = &H56555949
  198. WMENC_PIXELFORMAT_I420 = &H30323449
  199. WMENC_PIXELFORMAT_YV12 = &H32315659
  200. WMENC_PIXELFORMAT_YUY2 = &H32595559
  201. WMENC_PIXELFORMAT_UYVY = &H59565955
  202. WMENC_PIXELFORMAT_YVYU = &H55595659
  203. WMENC_PIXELFORMAT_YVU9 = &H39555659
  204. WMENC_PIXELFORMAT_RGB24 = &HE436EB7D
  205. WMENC_PIXELFORMAT_RGB32 = &HE436EB7E
  206. WMENC_PIXELFORMAT_RGB555 = &HE436EB7C
  207. WMENC_PIXELFORMAT_RGB565 = &HE436EB7B
  208. WMENC_PIXELFORMAT_RGB8 = &HE436EB7A
  209.  
  210. dim g_strInput
  211. dim g_strOutput
  212. dim g_strOutputString
  213. dim g_intSessionType
  214. dim g_strProfile
  215. dim g_strTitle
  216. dim g_strAuthor
  217. dim g_strCopyright
  218. dim g_strDescription
  219. dim g_strRating
  220. dim g_strWMEFile
  221. dim g_strProfileSave
  222.  
  223. dim g_intAudioDevice
  224. dim g_intVideoDevice
  225. dim g_intProfile
  226. dim g_intBroadcast
  227. dim g_strPushServer
  228. dim g_strPublishingPoint
  229. dim g_strPushTemplate
  230. dim g_intMarkInTime
  231. dim g_intMarkOutTime
  232. dim g_intDuration
  233. dim g_intVerbose
  234.  
  235. dim g_objEncoder
  236. dim g_objSourceGroup
  237. dim g_objAudioSource
  238. dim g_objVideoSource
  239. dim g_objProfile
  240. dim g_objFileSystem
  241.  
  242. dim g_blnEncoderStarted
  243. dim g_blnEncoderStopped
  244. dim g_intErrorCode
  245. dim g_intRunningSource
  246. dim g_blnDevice
  247. dim g_blnAudioOnly
  248. dim g_blnVideoOnly
  249. dim g_blnSilent
  250.  
  251. dim g_intAudioVBRMode
  252. dim g_strAudioCodec
  253. dim g_strAudioSetting
  254. dim g_intAudioPeakBitrate
  255. dim g_intAudioPeakBuffer
  256. dim g_intAudioSpeechContent
  257. dim g_strAudioSpeechEdl
  258. dim g_intAudioSurroundMix
  259. dim g_intAudioCenterMix
  260. dim g_intAudioLEFMix
  261. dim g_strAudioCodecName
  262.  
  263. dim g_intVideoVBRMode
  264. dim g_strVideoCodec
  265. dim g_intVideoBitrate
  266. dim g_intVideoWidth
  267. dim g_intVideoHeight
  268. dim g_intVideoFramerate
  269. dim g_intVideoKeydist
  270. dim g_intVideoBuffer
  271. dim g_intVideoQuality
  272. dim g_intVideoPeakBitrate
  273. dim g_intVideoPeakBuffer
  274. dim g_intVideoPreprocess
  275. dim g_strPixelFormat
  276. dim g_intPixelAspectRatioX
  277. dim g_intPixelAspectRatioY
  278. dim g_intVideoPerformance
  279. dim g_strVideoCodecName
  280. dim g_strVideoDevConf
  281.  
  282. dim i
  283. dim j
  284. dim g_blnCreateCustomProfile
  285.  
  286. dim g_tStartTime
  287. dim g_tStopTime
  288.  
  289. dim g_intClipLeft
  290. dim g_intClipRight
  291. dim g_intClipTop
  292. dim g_intClipBottom
  293.  
  294. g_strInput = ""
  295. g_strOutput = ""
  296. g_strOutputString = ""
  297. g_intSessionType = WMENC_CONTENT_ONE_AUDIO
  298. g_strProfile = ""
  299. g_strTitle = ""
  300. g_strAuthor = ""
  301. g_strCopyright = ""
  302. g_strDescription = ""
  303. g_strRating = ""
  304. g_strWMEFile = ""
  305. g_strProfileSave = ""
  306. g_strProfile = ""
  307.  
  308. g_intAudioDevice = -1
  309. g_intVideoDevice = -1
  310. g_intProfile = -1
  311. g_intBroadcast = -1
  312. g_strPushServer = ""
  313. g_strPublishingPoint = ""
  314. g_strPushTemplate = ""
  315. g_intMarkInTime = -1
  316. g_intMarkOutTime = -1
  317. g_intDuration = -1
  318. g_intVerbose = 2
  319.  
  320. g_blnEncoderStarted = false
  321. g_blnEncoderStopped = false
  322. g_blnDevice = false
  323. g_intErrorCode = 0
  324. g_intRunningSource = 0
  325. g_blnAudioOnly = false
  326. g_blnVideoOnly = false
  327.  
  328. g_intAudioVBRMode = -1
  329. g_strAudioCodec = ""
  330. g_strAudioSetting = ""
  331. g_intAudioPeakBitrate = -1
  332. g_intAudioPeakBuffer = -1
  333. g_intAudioSpeechContent = -1
  334. g_strAudioSpeechEdl = ""
  335. g_intAudioSurroundMix = -1
  336. g_intAudioCenterMix = -1
  337. g_intAudioLEFMix = -1
  338. g_strAudioCodecName = ""
  339.  
  340. g_intVideoVBRMode = -1
  341. g_strVideoCodec = ""
  342. g_intVideoBitrate = -1
  343. g_intVideoWidth = -1
  344. g_intVideoHeight = -1
  345. g_intVideoFramerate = -1
  346. g_intVideoKeydist = -1
  347. g_intVideoBuffer = -1
  348. g_intVideoQuality = -1
  349. g_intVideoPeakBitrate = -1
  350. g_intVideoPeakBuffer = -1
  351. g_intVideoPreprocess = -1
  352. g_strPixelFormat = ""
  353. g_intPixelAspectRatioX = 1
  354. g_intPixelAspectRatioY = 1
  355. g_intVideoPerformance = -1
  356. g_strVideoCodecName = ""
  357. g_strVideoDevConf = ""
  358.  
  359. g_intClipLeft = 0
  360. g_intClipRight = 0
  361. g_intClipTop = 0
  362. g_intClipBottom = 0
  363.  
  364. g_blnCreateCustomProfile = true
  365.  
  366. ' Create an encoder object.
  367. set g_objEncoder = WScript.CreateObject( "WMEncEng.WMEncoder" )
  368. WScript.ConnectObject g_objEncoder, "Encoder_"        ' Setup call back events
  369.     
  370. set g_objFileSystem = WScript.CreateObject( "Scripting.FileSystemObject" )
  371. g_objSourceGroup = Null
  372. g_objAudioSource = Null
  373. g_objVideoSource = Null
  374. g_objProfile = NULL
  375.  
  376. ' Read a integer value from the paramters list.
  377. ' args is the paramters list to be read.
  378. ' intIndex1 is the position of the parameter name.
  379. ' intIndex2 is the position of the parameter value.
  380. ' It will return the integer if it can read a integer value from the parameter list
  381. ' It will return -1 if it can not get a integer value from the paramters list.
  382. function ReadInteger( args, intIndex1, intIndex2 )
  383.     on error resume next
  384.     dim strTypeName
  385.  
  386.     ' Check the range of index.
  387.     if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then
  388.         OutputInfo "Invalid format for parameter " & args(intIndex1)
  389.         ReadInteger = -1
  390.         exit function
  391.     end if
  392.  
  393.     strTypeName = typename( eval( args(intIndex2) ) )
  394.  
  395.     ' Convert it to an integer value.
  396.     ReadInteger = CLng( args(intIndex2) )
  397.  
  398.     ' The value is not in integer fommat.
  399.     if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" )  then
  400.         OutputInfo "Expect integer value for parameter " & args(intIndex1)
  401.         ReadInteger = -1
  402.         err.Clear
  403.     end if
  404.  
  405. end function
  406.  
  407. ' Read a float value from the paramters list.
  408. ' args is the paramters list to be read.
  409. ' intIndex1 is the position of the parameter name.
  410. ' intIndex2 is the position of the parameter value.
  411. ' It will return the float if it can read a float value from the parameter list
  412. ' It will return -1 if it can not get a float value from the paramters list.
  413. function ReadFloat( args, intIndex1, intIndex2 )
  414.     on error resume next
  415.     dim strTypeName
  416.  
  417.     ' Check the range of index.
  418.     if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then
  419.         OutputInfo "Invalid format for parameter " & args(intIndex1)
  420.         ReadFloat = -1
  421.         exit function
  422.     end if
  423.  
  424.     strTypeName = typename( eval( args(intIndex2) ) )
  425.  
  426.     ' Convert it to an integer value.
  427.     ReadFloat = CSng( args(intIndex2) )
  428.  
  429.     ' The value is not in integer fommat.
  430.     if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" and strTypeName <> "Single" and strTypeName <> "Double" )  then
  431.         OutputInfo "Expect float value for parameter " & args(intIndex1)
  432.         ReadFloat = -1
  433.         err.Clear
  434.     end if
  435.  
  436. end function
  437.  
  438. ' Read a var value from the paramters list.
  439. ' args is the paramters list to be read.
  440. ' intIndex1 is the position of the parameter name.
  441. ' intIndex2 is the position of the parameter value.
  442. ' It will return the var if it can not get a var value from the paramters list.
  443. ' It will return "" if it can not get a var value from the paramters list.
  444. function ReadString( args, intIndex1, intIndex2 )
  445.     ' Check the range of index.
  446.     if intIndex2 > UBound(args) or Left( args(intIndex2), 1 ) = "-" then
  447.         OutputInfo "Invalid format for parameter " & args(intIndex1)
  448.         ReadString = ""
  449.         exit function
  450.     end if
  451.  
  452.     ReadString = args(intIndex2)
  453. end function
  454.  
  455. function ConvertStringToInteger( strInput )
  456.     on error resume next
  457.     dim strTypeName
  458.  
  459.     strTypeName = typename( eval( strInput ) )
  460.  
  461.     ' Convert it to an integer value.
  462.     ConvertStringToInteger = CLng( strInput )
  463.  
  464.     ' The value is not in integer fommat.
  465.     if err.number <> 0 or ( strTypeName <> "Integer" and strTypeName <> "Long" )  then
  466.         OutputInfo "Invalid format " & strInput & " expecting integer value"
  467.         ConvertStringToInteger = -1
  468.         err.Clear
  469.     end if
  470.  
  471. end function
  472.  
  473. ' Parse parameters.
  474.  
  475. if wscript.arguments.Length = 0 then
  476.     ShowHelp()
  477.     wscript.quit()
  478. end if
  479.  
  480. dim colStrArgs()
  481. reDim colStrArgs( wscript.arguments.Length-1 )
  482. for i = 0 to wscript.arguments.Length-1
  483.     colStrArgs(i) = wscript.arguments(i)
  484. next
  485.  
  486. if ParseParameters( colStrArgs ) then
  487.     ' Do different things depending on whether input is wme, directory encoding or file encoding
  488.     if g_strInput <> "" and g_objFileSystem.FolderExists(g_strInput) then
  489.         DoDirectoryModeEncoding()
  490.     elseif SetupEncoder() then
  491.         ' Transcode and show statistics information
  492.         if Transcode() and not g_blnSilent then 
  493.             ShowStatistics()
  494.         end if 
  495.     end if
  496. end if
  497.  
  498. WScript.Quit()
  499.  
  500. ' Output information
  501. function OutputInfo( strInfo )
  502.     WScript.Echo( strInfo )
  503. end function
  504.  
  505. ' Event handler for encoder state
  506. function Encoder_OnStateChange( enumState )
  507.     dim strState
  508.     ' Translate encoder state
  509.     select case  enumState
  510.         case WMENC_ENCODER_STARTING
  511.             strState = "Starting"
  512.  
  513.         case WMENC_ENCODER_RUNNING
  514.             strState = "Running"
  515.             g_blnEncoderStarted = true
  516.  
  517.         case WMENC_ENCODER_PAUSED
  518.             strState = "Paused"
  519.  
  520.         case WMENC_ENCODER_STOPPING
  521.             strState = "Stopping"
  522.  
  523.         case WMENC_ENCODER_STOPPED
  524.             g_tStopTime = Now()
  525.             strState = "Stopped"
  526.             g_blnEncoderStopped = true
  527.  
  528.         case WMENC_ENCODER_END_PREPROCESS
  529.             strState = "End Preprorocess"
  530.  
  531.         case else
  532.             strState = "Unknown State"
  533.     end select
  534.  
  535.     Encoder_OnStateChange = 1
  536. end function
  537.  
  538. ' Parse the parameters of this program.
  539. function ParseParameters( args )
  540.     dim strMarkOutTime
  541.     dim strArguments
  542.     dim strSaveToCfgFile
  543.     dim strLoadFromCfgFile
  544.     dim strCfgFileArguments
  545.     dim colStrConfigArgs
  546.     dim objTextFile
  547.  
  548.     for i=0 to UBound(args)
  549.         if args(i) = "-s_config" then
  550.             i = i + 1
  551.         else
  552.             strArguments = strArguments & args(i) & " "
  553.         end if
  554.  
  555.         if args(i) = "-config" then
  556.             strLoadFromCfgFile = ReadString( args, i, i+1 )
  557.             if strLoadFromCfgFile = "" then
  558.                 ParseParameters = false
  559.                 exit function
  560.             end if
  561.         
  562.             i = i + 1
  563.  
  564.             strLoadFromCfgFile = g_objFileSystem.GetAbsolutePathName( strLoadFromCfgFile )
  565.             set objTextFile = g_objFileSystem.OpenTextFile( strLoadFromCfgFile, 1 )
  566.             strCfgFileArguments = objTextFile.ReadLine
  567.             objTextFile.Close
  568.             
  569.             strCfgFileArguments = Trim( strCfgFileArguments )
  570.             if strCfgFileArguments = "" then
  571.                 OutputInfo "Configuration file " & strLoadFromCfgFile & " is empty"
  572.                 ParseParameters = false
  573.                 exit function
  574.             end if
  575.             colStrConfigArgs = Split( strCfgFileArguments )
  576.             if ParseParameters( colStrConfigArgs ) = false then
  577.                 ParseParameters = false
  578.                 exit function
  579.             end if
  580.         end if
  581.     next
  582.  
  583.     ' OutputInfo "Args = " & strArguments
  584.  
  585.     if UBound(args) = 0 then
  586.         ' If it has only has one parameter, check the content of this parameter.
  587.         select case LCase( args(0) )     
  588.             case "-devices":
  589.                 ' List all audio and video devices.
  590.                 ListDevices()
  591.                 ParseParameters = false
  592.                 exit function
  593.  
  594.             case "-a_codecs":
  595.                 ' List all audio codecs.
  596.                 ListAudioCodecs()
  597.                 ParseParameters = false
  598.                 exit function
  599.  
  600.             case "-a_formats"
  601.                 ' List audio formats
  602.                 ListAudioFormats()
  603.                 ParseParameters = false
  604.                 exit function
  605.             
  606.             case "-v_codecs":
  607.                 ' List all video codecs.
  608.                 ListVideoCodecs()
  609.                 ParseParameters = false
  610.                 exit function
  611.             
  612.             case "-help":
  613.                 ' Show help information.
  614.                 ShowHelp()
  615.                 ParseParameters = false
  616.                 exit function
  617.  
  618.             case "-?":
  619.                 ' Show help information.
  620.                 ShowHelp()
  621.                 ParseParameters = false
  622.                 exit function
  623.  
  624.             case "-all?":
  625.                 ' Show help information.
  626.                 ShowHelp()
  627.                 ParseParameters = false
  628.                 exit function
  629.             
  630.             case "/?":
  631.                 ' Show help information.
  632.                 ShowHelp()
  633.                 ParseParameters = false
  634.                 exit function
  635.             
  636.             case "-help?"
  637.                 ' Being up the encoder util chm
  638.                 ShowHelpChm()
  639.                 ParseParameters = false
  640.                 exit function
  641.  
  642.         end select
  643.     end if
  644.  
  645.     if UBound(args) = 1 then
  646.         select case LCase( args(0) ) 
  647.             case "-input"
  648.             ' Print out info about file specified
  649.             g_strInput = ReadString( args, 0, 1 )
  650.             if g_strInput = ""  then
  651.                 ParseParameters = false
  652.                 exit function
  653.             end if
  654.  
  655.             PrintFileInfo()
  656.             ParseParameters = false
  657.             exit function
  658.         end select
  659.     end if
  660.  
  661.     ' Check all parameters.
  662.     for i=0 to UBound(args)
  663.     
  664.         select case LCase( args(i) )
  665.             ' Parse all input related stuff
  666.             case "-wme"
  667.                 ' Get the WME file name to be load.
  668.                 g_strWMEFile = ReadString( args, i, i+1 )
  669.                 if g_strWMEFile = "" then
  670.                     ParseParameters = false
  671.                     exit function
  672.                 end if
  673.         
  674.                 i = i + 1
  675.  
  676.             case "-input"                        
  677.                 ' Get input source file name.
  678.                 g_strInput = ReadString( args, i, i+1 )
  679.                 if g_strInput = ""  then
  680.                     ParseParameters = false
  681.                     exit function
  682.                 end if
  683.         
  684.                 i = i + 1
  685.  
  686.             case "-audioonly"
  687.                 g_blnAudioOnly = true
  688.  
  689.             case "-videoonly"
  690.                 g_blnVideoOnly = true
  691.  
  692.             case "-adevice"
  693.                 g_blnDevice = true
  694.                 ' Get audio device index.
  695.                 if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then
  696.                     g_intAudioDevice = ReadInteger( args, i, i+1 )
  697.                     if g_intAudioDevice = -1 then
  698.                         ParseParameters = false
  699.                         exit function
  700.                     end if
  701.                     
  702.                     i = i + 1
  703.                 else
  704.                     g_intAudioDevice = 0     ' default audio device
  705.                 end if
  706.  
  707.             case "-vdevice"
  708.                 g_blnDevice = true
  709.                 ' Get video device index.
  710.                 if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then
  711.                     g_intVideoDevice = ReadInteger( args, i, i+1 )
  712.                     if g_intVideoDevice = -1 then
  713.                         ParseParameters = false
  714.                         exit function
  715.                     end if
  716.                 
  717.                     i = i + 1
  718.                 else
  719.                     g_intVideoDevice = 0     ' default video device
  720.                 end if
  721.  
  722.             ' Parse all profile related stuff
  723.             case "-profile"
  724.                 ' Get input source file name.
  725.                 g_strProfile = ReadString( args, i, i+1 )
  726.                 if g_strProfile = ""  then
  727.                     ParseParameters = false
  728.                     exit function
  729.                 end if
  730.         
  731.                 i = i + 1
  732.  
  733.             ' Parse audio related stuff
  734.             case "-a_mode"
  735.                 g_intAudioVBRMode = ReadInteger( args, i, i+1 )
  736.                 if g_intAudioVBRMode = -1 then
  737.                     ParseParameters = false
  738.                     exit function
  739.                 end if
  740.         
  741.                 i = i + 1
  742.  
  743.             case "-a_codec"
  744.                 'Get audio codec name
  745.                 g_strAudioCodec = ReadString( args, i, i+1 )
  746.                 g_strAudioCodec = UCase( g_strAudioCodec )
  747.  
  748.                 if g_strAudioCodec <> WMA9STD and g_strAudioCodec <> WMA9PRO and g_strAudioCodec <> WMA9LSL and g_strAudioCodec <> WMSPEECH and g_strAudioCodec <> PCM then
  749.                     OutputInfo "Please enter correct audio codec index only"
  750.                     ParseParameters = false
  751.                     exit function
  752.                 end if
  753.  
  754.                 if g_strAudioCodec = ""  then
  755.                     ParseParameters = false
  756.                     exit function
  757.                 end if
  758.         
  759.                 i = i + 1
  760.  
  761.             case "-a_setting"
  762.                 'Get audio setting
  763.                 g_strAudioSetting = ReadString( args, i, i+1 )
  764.                 if g_strAudioSetting = ""  then
  765.                     ParseParameters = false
  766.                     exit function
  767.                 end if
  768.         
  769.                 i = i + 1
  770.  
  771.             case "-a_peakbitrate"
  772.                 'Get audio peakbitrate size
  773.                 g_intAudioPeakBitrate = ReadInteger( args, i, i+1 )
  774.                 if g_intAudioPeakBitrate = -1  then
  775.                     ParseParameters = false
  776.                     exit function
  777.                 end if
  778.         
  779.                 i = i + 1
  780.  
  781.             case "-a_peakbuffer"
  782.                 'Get audio peakbuffer size
  783.                 g_intAudioPeakBuffer = ReadInteger( args, i, i+1 )
  784.                 if g_intAudioPeakBuffer = -1  then
  785.                     ParseParameters = false
  786.                     exit function
  787.                 end if
  788.         
  789.                 i = i + 1
  790.  
  791.             case "-a_content"
  792.                 'Get content type for speech
  793.                 g_intAudioSpeechContent = ReadInteger( args, i, i+1 )
  794.                 if g_intAudioSpeechContent = -1 then
  795.                     ParseParameters = false
  796.                     exit function
  797.                 elseif g_intAudioSpeechContent < 0 or g_intAudioSpeechContent > 2 then
  798.                     OutputInfo "Invalid range for parameter " & args(i)
  799.                     ParseParameters = false
  800.                     exit function
  801.                 end if
  802.         
  803.                 i = i + 1
  804.  
  805.             case "-a_contentedl"
  806.                 'Get EDL file for speech content
  807.                 g_strAudioSpeechEdl = ReadString( args, i, i+1 )
  808.                 if g_strAudioSpeechEdl = ""  then
  809.                     ParseParameters = false
  810.                     exit function
  811.                 end if
  812.         
  813.                 i = i + 1
  814.  
  815.             case "-a_folddown6to2"
  816.                 'Get EDL file for speech content
  817.                 g_intAudioSurroundMix = ReadInteger( args, i, i+1 )
  818.                 if g_intAudioSurroundMix = -1  then
  819.                     ParseParameters = false
  820.                     exit function
  821.                 end if
  822.                 g_intAudioCenterMix = ReadInteger( args, i, i+1 )
  823.                 if g_intAudioCenterMix = -1  then
  824.                     ParseParameters = false
  825.                     exit function
  826.                 end if    
  827.                 g_intAudioLEFMix = ReadInteger( args, i, i+1 )
  828.                 if g_intAudioLEFMix = -1  then
  829.                     ParseParameters = false
  830.                     exit function
  831.                 end if
  832.         
  833.                 i = i + 3
  834.  
  835.             ' Parse video related stuff
  836.             case "-v_mode"
  837.                 g_intVideoVBRMode = ReadInteger( args, i, i+1 )
  838.                 if g_intVideoVBRMode = -1 then
  839.                     ParseParameters = false
  840.                     exit function
  841.                 end if
  842.         
  843.                 i = i + 1
  844.  
  845.             case "-v_codec"
  846.                 'Get video codec name
  847.                 g_strVideoCodec = ReadString( args, i, i+1 )
  848.                 g_strVideoCodec = UCase( g_strVideoCodec )
  849.                 if g_strVideoCodec <> WMV7 and g_strVideoCodec <> WMV8 and g_strVideoCodec <> WMV9 and g_strVideoCodec <> WMS9 and g_strVideoCodec <> MP41 and g_strVideoCodec <> UNCOMP then
  850.                     OutputInfo "Please enter correct video codec index only"
  851.                     ParseParameters = false
  852.                     exit function
  853.                 end if
  854.  
  855.                 if g_strVideoCodec = ""  then
  856.                     ParseParameters = false
  857.                     exit function
  858.                 end if
  859.         
  860.                 i = i + 1
  861.  
  862.             case "-v_bitrate"
  863.                 'Get video bitrate
  864.                 g_intVideoBitrate = ReadInteger( args, i, i+1 )
  865.                 if g_intVideoBitrate = -1  then
  866.                     ParseParameters = false
  867.                     exit function
  868.                 end if
  869.         
  870.                 i = i + 1
  871.  
  872.             case "-v_buffer"
  873.                 'Get video buffer
  874.                 g_intVideoBuffer = ReadInteger( args, i, i+1 )
  875.                 if g_intVideoBuffer = -1  then
  876.                     ParseParameters = false
  877.                     exit function
  878.                 end if
  879.         
  880.                 i = i + 1
  881.  
  882.             case "-v_width"
  883.                 'Get video width
  884.                 g_intVideoWidth = ReadInteger( args, i, i+1 )
  885.                 if g_intVideoWidth = -1  then
  886.                     ParseParameters = false
  887.                     exit function
  888.                 end if
  889.         
  890.                 i = i + 1
  891.  
  892.             case "-v_height"
  893.                 'Get video height
  894.                 g_intVideoHeight = ReadInteger( args, i, i+1 )
  895.                 if g_intVideoHeight = -1  then
  896.                     ParseParameters = false
  897.                     exit function
  898.                 end if
  899.         
  900.                 i = i + 1
  901.  
  902.             case "-v_framerate"
  903.                 'Get video framerate
  904.                 g_intVideoFramerate = ReadFloat( args, i, i+1 )
  905.                 if g_intVideoFramerate = -1  then
  906.                     ParseParameters = false
  907.                     exit function
  908.                 end if
  909.                 g_intVideoFramerate = 1000 * g_intVideoFramerate
  910.         
  911.                 i = i + 1
  912.  
  913.             case "-v_keydist"
  914.                 'Get video keyframe distance
  915.                 g_intVideoKeydist = ReadInteger( args, i, i+1 )
  916.                 if g_intVideoKeydist = -1  then
  917.                     ParseParameters = false
  918.                     exit function
  919.                 end if
  920.  
  921.                 g_intVideoKeydist = 1000 * g_intVideoKeydist
  922.         
  923.                 i = i + 1
  924.  
  925.             case "-v_quality"
  926.                 'Get video bufferwindow size
  927.                 g_intVideoQuality = ReadInteger( args, i, i+1 )
  928.                 if g_intVideoQuality = -1  then
  929.                     ParseParameters = false
  930.                     exit function
  931.                 end if
  932.         
  933.                 i = i + 1
  934.  
  935.             case "-v_peakbitrate"
  936.                 'Get video peakbitrate size
  937.                 g_intVideoPeakBitrate = ReadInteger( args, i, i+1 )
  938.                 if g_intVideoPeakBitrate = -1  then
  939.                     ParseParameters = false
  940.                     exit function
  941.                 end if
  942.         
  943.                 i = i + 1
  944.  
  945.             case "-v_peakbuffer"
  946.                 'Get video peakbuffer size
  947.                 g_intVideoPeakBuffer = ReadInteger( args, i, i+1 )
  948.                 if g_intVideoPeakBuffer = -1  then
  949.                     ParseParameters = false
  950.                     exit function
  951.                 end if
  952.         
  953.                 i = i + 1
  954.  
  955.             case "-v_performance"
  956.                 'Get video complexity setting
  957.                 g_intVideoPerformance = ReadInteger( args, i, i+1 )
  958.                 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
  959.                     ParseParameters = false
  960.                     exit function
  961.                 end if
  962.  
  963.                 i = i + 1
  964.  
  965.             case "-v_preproc"
  966.                 'Get video preprocess setting
  967.                 g_intVideoPreprocess = ReadInteger( args, i, i+1 )
  968.                 if g_intVideoPreprocess = -1  then
  969.                     ParseParameters = false
  970.                     exit function
  971.                 end if
  972.         
  973.                 i = i + 1
  974.  
  975.             case "-pixelformat"
  976.                 ' Get pixelformat.
  977.                 g_strPixelFormat = ReadString( args, i, i+1 )
  978.                 if g_strPixelFormat = "" then
  979.                     ParseParameters = false
  980.                     exit function
  981.                 end if
  982.         
  983.                 i = i + 1
  984.  
  985.             case "-pixelratio"
  986.                 ' Get pixelformat.
  987.                 g_intPixelAspectRatioX = ReadInteger( args, i, i+1 )
  988.                 g_intPixelAspectRatioY = ReadInteger( args, i, i+2 )
  989.  
  990.                 if g_intPixelAspectRatioX = -1 or g_intPixelAspectRatioY = -1 then
  991.                     ParseParameters = false
  992.                     exit function
  993.                 end if
  994.         
  995.                 i = i + 2
  996.  
  997.             case "-v_clip"
  998.                 ' Get clipping values.
  999.                 g_intClipLeft   = ReadInteger( args, i, i+1 )
  1000.                 g_intClipTop    = ReadInteger( args, i, i+2 )
  1001.                 g_intClipRight  = ReadInteger( args, i, i+3 )
  1002.                 g_intClipBottom = ReadInteger( args, i, i+4 )
  1003.  
  1004.                 if g_intClipLeft = -1 or g_intClipTop = -1 or g_intClipRight = -1 or g_intClipBottom = -1 then
  1005.                     ParseParameters = false
  1006.                     exit function
  1007.                 end if
  1008.  
  1009.                 i = i + 4
  1010.  
  1011.             case "-v_profile"
  1012.                 ' Get video device conformance value
  1013.                 g_strVideoDevConf = ReadString( args, i, i+1 )
  1014.                 g_strVideoDevConf = UCase( g_strVideoDevConf )
  1015.  
  1016.                 if g_strVideoDevConf = ""  then
  1017.                     ParseParameters = false
  1018.                     exit function
  1019.                 end if
  1020.         
  1021.                 i = i + 1
  1022.  
  1023.             ' Parse all output related stuff
  1024.             case "-output"                        
  1025.                 ' Get output file name.
  1026.                 g_strOutput = ReadString( args, i, i+1 )
  1027.                 if g_strOutput = "" then
  1028.                     ParseParameters = false
  1029.                     exit function
  1030.                 end if
  1031.         
  1032.                 i = i + 1
  1033.  
  1034.             case "-outputstring"
  1035.                 ' Read in the string that is to be appended to output file name
  1036.                 g_strOutputString = ReadString( args, i, i+1 )
  1037.                 if g_strOutputString = "" then
  1038.                     ParseParameters = false
  1039.                     exit function
  1040.                 end if
  1041.         
  1042.                 i = i + 1
  1043.  
  1044.             case "-broadcast"
  1045.                 ' Get broadcast port number.
  1046.                 if i+1 <= UBound(args) and Left( args(i+1), 1 ) <> "-" then
  1047.                     g_intBroadcast = ReadInteger( args, i, i+1 )
  1048.                     if g_intBroadcast = -1 then
  1049.                         ParseParameters = false
  1050.                         exit function
  1051.                     end if
  1052.         
  1053.                     i = i + 1
  1054.                 else
  1055.                     g_intBroadcast = 8080
  1056.                 end if
  1057.  
  1058.             case "-push"
  1059.                 ' Get push server, pub point and template name (optional)
  1060.                 g_strPushServer = ReadString( args, i, i+1 )
  1061.                 g_strPublishingPoint = ReadString( args, i, i+2 )
  1062.  
  1063.                 if g_strPushServer = "" or g_strPublishingPoint = "" then
  1064.                     ParseParameters = false
  1065.                     exit function
  1066.                 end if
  1067.  
  1068.                 ' Check if template name is specified
  1069.                 if i+1 <= UBound(args) and Left( args(i+3), 1 ) <> "-" then
  1070.                     g_strPushTemplate = ReadString( args, i, i+3 )
  1071.                     i = i + 3
  1072.                 else
  1073.                     i = i + 2
  1074.                 end if
  1075.  
  1076.             case "-time"
  1077.                 ' Get the mark in time of the source file.
  1078.                 g_intMarkInTime = ReadInteger( args, i, i+1 )
  1079.  
  1080.                 ' Get the markout time of the source file
  1081.                 strMarkOutTime = ReadString( args, i, i+2 )
  1082.                 if strMarkOutTime <> "end" then
  1083.                     g_intMarkOutTime = ConvertStringToInteger( strMarkOutTime )
  1084.                 else
  1085.                     g_intMarkOutTime = 0
  1086.                 end if
  1087.  
  1088.                 if g_intMarkInTime = -1 or g_intMarkOutTime = -1 then
  1089.                     ParseParameters = false
  1090.                     exit function
  1091.                 end if
  1092.         
  1093.         
  1094.                 i = i + 2
  1095.  
  1096.             case "-duration"
  1097.                 ' Get the duration of the encoding session.
  1098.                 g_intDuration = ReadInteger( args, i, i+1 )
  1099.                 if g_intDuration = -1 then
  1100.                     ParseParameters = false
  1101.                     exit function
  1102.                 end if
  1103.         
  1104.                 i = i + 1
  1105.  
  1106.             case "-silent"
  1107.                 g_blnSilent = true
  1108.  
  1109.             ' Parse all attributes
  1110.             case "-title"
  1111.                 ' Get the title of the output file.
  1112.                 g_strTitle = ReadString( args, i, i+1 )
  1113.                 if g_strTitle = "" then
  1114.                     ParseParameters = false
  1115.                     exit function
  1116.                 end if
  1117.  
  1118.                 i = i + 1
  1119.  
  1120.             case "-author"                        
  1121.                 ' Get the author of the output file.
  1122.                 g_strAuthor = ReadString( args, i, i+1 )
  1123.                 if g_strAuthor = "" then
  1124.                     ParseParameters = false
  1125.                     exit function
  1126.                 end if
  1127.         
  1128.                 i = i + 1
  1129.  
  1130.             case "-copyright"                        
  1131.                 ' Get the copyright information of the output file.
  1132.                 g_strCopyright = ReadString( args, i, i+1 )
  1133.                 if g_strCopyright = "" then
  1134.                     ParseParameters = false
  1135.                     exit function
  1136.                 end if
  1137.         
  1138.                 i = i + 1
  1139.  
  1140.             case "-description"
  1141.                 ' Get the descrption of the output file.
  1142.                 g_strDescription = ReadString( args, i, i+1 )
  1143.                 if g_strDescription = "" then
  1144.                     ParseParameters = false
  1145.                     exit function
  1146.                 end if
  1147.         
  1148.                 i = i + 1
  1149.  
  1150.             case "-rating"                        
  1151.                 ' Get the rating of the output file.
  1152.                 g_strRating = ReadString( args, i, i+1 )
  1153.                 if g_strRating = "" then
  1154.                     ParseParameters = false
  1155.                     exit function
  1156.                 end if
  1157.         
  1158.                 i = i + 1
  1159.  
  1160.             case "-saveprofile"                            
  1161.                 ' Get the profile file name to be save.
  1162.                 g_strProfileSave = ReadString( args, i, i+1 )
  1163.                 if g_strProfileSave = "" then
  1164.                     ParseParameters = false
  1165.                     exit function
  1166.                 end if
  1167.         
  1168.                 i = i + 1
  1169.  
  1170.             case "-verbose"
  1171.                 ' Get the verbose mode.
  1172.                 g_intVerbose = ReadInteger( args, i, i+1 )
  1173.                 if g_intVerbose = -1 then
  1174.                     ParseParameters = false
  1175.                     exit function
  1176.                 end if
  1177.  
  1178.                 i = i + 1
  1179.  
  1180.             case "-s_config"
  1181.                 ' Save the WEU configuration file
  1182.                 strSaveToCfgFile = ReadString( args, i, i+1 )
  1183.                 if strSaveToCfgFile = "" then
  1184.                     ParseParameters = false
  1185.                     exit function
  1186.                 end if
  1187.  
  1188.                 i = i + 1
  1189.             case "-config"
  1190.                 if strLoadFromCfgFile = "" then
  1191.                     ParseParameters = false
  1192.                     exit function
  1193.                 end if
  1194.         
  1195.                 i = i + 1
  1196.  
  1197.             case else
  1198.                 ' Show an error information for unrecognized parameter.
  1199.                 OutputInfo "Invalid parameter: " & args(i)
  1200.                 ParseParameters = false
  1201.                 exit function
  1202.         end select
  1203.     
  1204.     next
  1205.  
  1206.     if strSaveToCfgFile <> "" then
  1207.         strSaveToCfgFile = g_objFileSystem.GetAbsolutePathName( strSaveToCfgFile )
  1208.  
  1209.         ' Add extension if necessary
  1210.         if Right( LCase( strSaveToCfgFile ), 4 ) <>  ".weu" then
  1211.             strSaveToCfgFile = strSaveToCfgFile & ".weu"
  1212.         end if
  1213.  
  1214.         CreateOutputFolder( g_objFileSystem.GetParentFolderName( strSaveToCfgFile ) )    
  1215.         set objTextFile = g_objFileSystem.OpenTextFile( strSaveToCfgFile, 2, True )
  1216.         objTextFile.Write( strArguments )
  1217.         objTextFile.close
  1218.     end if
  1219.  
  1220.     ParseParameters = true
  1221. end function
  1222.  
  1223. ' Show help information of this program.
  1224. function ShowHelp()
  1225.     OutputInfo "Encode from files or devices to Windows Media files or streams. Supported"
  1226.     OutputInfo "source file formats are .wmv, .wma, .asf, .avi., .wav. .mpg, .mp3, .bmp,"
  1227.     OutputInfo ".jpg, and .vob."
  1228.     OutputInfo ""
  1229.     OutputInfo ""
  1230.     OutputInfo "Usage for I/O and statistics."
  1231.     OutputInfo ""
  1232.     OutputInfo "[-wme] <Windows Media Encoder session file>"
  1233.     OutputInfo "    Loads an existing Windows Media Encoder session file."
  1234.     OutputInfo "[-input] <file or directory name>"
  1235.     OutputInfo "    The file or directory to be encoded."
  1236.     OutputInfo "    Specify a file or directory name. If you specify a directory, supported"
  1237.     OutputInfo "    files in the directory will be encoded to the output directory, using"
  1238.     OutputInfo "    the same encoding settings. "
  1239.     OutputInfo "    Enclose file and directory names that have spaces in quotations."
  1240.     OutputInfo "    For example: -input ""c:\my sample.wmv"""
  1241.     OutputInfo "[-adevice] <audio device number>"
  1242.     OutputInfo "    The audio capture device to encode from."
  1243.     OutputInfo "    Use -devices to list all available capture devices."  
  1244.     OutputInfo "    When encoding from devices, you must specify a duration using -duration."      
  1245.     OutputInfo "[-vdevice] <video device number>"
  1246.     OutputInfo "    The video capture device to encode from."
  1247.     OutputInfo "    Use -devices to list all available capture devices."  
  1248.     OutputInfo "    When capturing from devices, you must specify a duration using -duration."      
  1249.     OutputInfo "[-output] <file or directory name>"
  1250.     OutputInfo "    The name of the output file or directory."
  1251.     OutputInfo "    If the input is a file, -output corresponds to a file name. If the input"
  1252.     OutputInfo "    is a directory, -output corresponds to a directory name."
  1253.     OutputInfo "    The output directory will be created if it doesn't already exist."
  1254.     OutputInfo "    An extension is automatically appended to output files."
  1255.     OutputInfo "    (.wma for audio-only Windows Media files, and .wmv for video-only or"
  1256.     OutputInfo "    audio and video Windows Media files.)"
  1257.     OutputInfo "[-outputstring] <string>"
  1258.     OutputInfo "    The string to be attached to every output file name for directory mode."
  1259.     OutputInfo "[-broadcast] <port>"
  1260.     OutputInfo "    Broadcasts via HTTP on the port specified. The default port is 8080."
  1261.     OutputInfo "[-time] <start time> <end time>"
  1262.     OutputInfo "    Specify the time segment (in msec) to be encoded."
  1263.     OutputInfo "    Use 'end' for <end time> if you want to encode to the end of the file."
  1264.     OutputInfo "[-silent]"
  1265.     OutputInfo "    Prevents statistics from being displayed after encoding is finished."
  1266.     OutputInfo "[-config] <input configuration file>"
  1267.     OutputInfo "    Inputs arguments from a configuration file. The default extension is .weu."
  1268.     OutputInfo "    Parameters in the file can be overridden by later arguments."
  1269.     OutputInfo "[-s_config] <output configuration file>"
  1270.     OutputInfo "    Creates a configuration file. The file name extension .weu is appended"
  1271.     OutputInfo "    automatically."
  1272.     OutputInfo ""
  1273.     OutputInfo ""
  1274.     OutputInfo "Usage for profiles."
  1275.     OutputInfo ""
  1276.     OutputInfo "[-profile] <profile code>"
  1277.     OutputInfo "    Parameters in the profile can be overridden by later arguments."
  1278.     OutputInfo ""
  1279.     OutputInfo "Profile codes and basic descriptions."
  1280.     OutputInfo "Audio/Video:"
  1281.     OutputInfo "    av20: Profile_AudioVideo_Modem_28K (actual rate: 20Kbps)"
  1282.     OutputInfo "    av32: Profile_AudioVideo_Modem_56K (32 Kbps)"
  1283.     OutputInfo "    av100: Profile_AudioVideo_LAN_100K (100 Kbps)"
  1284.     OutputInfo "    av225: Profile_AudioVideo_LAN_256K (225 Kbps)"
  1285.     OutputInfo "    av350: Profile_AudioVideo_LANDSL_384K (350 Kbps)"
  1286.     OutputInfo "    av450: Profile_AudioVideo_LANDSL_768K (450 Kbps)"
  1287.     OutputInfo "    av700: Profile_AudioVideo_NearBroadcast_700K (700 Kbps)"
  1288.     OutputInfo "    av1400: Profile_AudioVideo_NearBroadcast_1400K (1400 Kbps)"
  1289.     OutputInfo "    av350pal: Profile_AudioVideo_Broadband_PAL_384K (350 Kbps)"
  1290.     OutputInfo "    av700pal: Profile_AudioVideo_NearBroadcast_PAL_700K (700 Kbps)"
  1291.     OutputInfo "    av100_2p: Profile_AudioVideo_LAN_100K_2Pass (100 Kbps)"
  1292.     OutputInfo "    av350_2p: Profile_AudioVideo_LANDSL_384K_2Pass (350 Kbps)"
  1293.     OutputInfo "    av600vbr: Profile_AudioVideo_FilmVBR_600K (600 Kbps)"
  1294.     OutputInfo "    avq97vbr: Profile_AudioVideo_FilmVBR_Quality97 (Quality 97)"
  1295.     OutputInfo ""
  1296.     OutputInfo "Audio-only:"
  1297.     OutputInfo "    a20_1: Profile_AudioOnly_FMRadioMono_28K (20 Kbps)"
  1298.     OutputInfo "    a20_2: Profile_AudioOnly_FMRadioStereo_28K (20 Kbps)"
  1299.     OutputInfo "    a32: Profile_AudioOnly_Modem_56K (32 Kbps)"
  1300.     OutputInfo "    a48: Profile_AudioOnly_NearCDQuality_48K (48 Kbps)"
  1301.     OutputInfo "    a64: Profile_AudioOnly_CDQuality_64K (64 Kbps)"
  1302.     OutputInfo "    a96: Profile_AudioOnly_CDAudiophileQuality_96K (96 Kbps)"
  1303.     OutputInfo "    a128: Profile_AudioOnly_CDAudiophileQuality_128K (128 Kbps)"
  1304.     OutputInfo ""
  1305.     OutputInfo "Video-only:"
  1306.     OutputInfo "    v20: Profile_VideoOnly_Modem_28K (20 Kbps)"
  1307.     OutputInfo "    v32: Profile_VideoOnly_Modem_56K (32 Kbps)"
  1308.     OutputInfo ""
  1309.     OutputInfo ""
  1310.     OutputInfo "Usage for audio settings."
  1311.     OutputInfo ""
  1312.     OutputInfo "[-a_codec] <codec index>"
  1313.     OutputInfo "    Audio codec to be used. Use -a_codecs to list available codecs."
  1314.     OutputInfo "    Specify codec index:"
  1315.     OutputInfo "    WMA9STD: Windows Media Audio v9 Standard."
  1316.     OutputInfo "    WMA9PRO: Windows Media Audio v9 Professional."
  1317.     OutputInfo "    WMSP9:   Windows Media Audio v9 Voice."
  1318.     OutputInfo "    WMA9LSL:  Windows Media Audio v9 Lossless."
  1319.     OutputInfo "    Default: Windows Media Audio v9 Standard."
  1320.     OutputInfo "[-a_codecs]"
  1321.     OutputInfo "    Lists all audio codecs."
  1322.     OutputInfo "[-a_content] <mode>"
  1323.     OutputInfo "    Audio content mode for the Windows Media Audio v9 Voice codec."
  1324.     OutputInfo "    0 = No special mode for the audio content (default)"
  1325.     OutputInfo "    1 = Speech mode"
  1326.     OutputInfo "    2 = Mixed (speech and music) mode (also requires -a_contentedl)"
  1327.     OutputInfo "    You must also specify the Windows Media Audio v9 Voice codec."
  1328.     OutputInfo "[-a_contentedl] <file name>"
  1329.     OutputInfo "    Specifies the places in audio content where music starts and ends. To do"
  1330.     OutputInfo "    this, you must first create an optimization definition file, which is a"
  1331.     OutputInfo "    text file that identifies the places in your file where music starts and"
  1332.     OutputInfo "    ends. The unspecified portions in the file are treated as speech. In the"
  1333.     OutputInfo "    optimization definition file, first type the version number and the "
  1334.     OutputInfo "    number of music segments the file contains. Then type the start and end"
  1335.     OutputInfo "    times in milliseconds of each segment, and separate each start and end "
  1336.     OutputInfo "    time with a comma. For example, typing 1, 3, 0, 10000, 50000, 80000, "
  1337.     OutputInfo "    150000, 200000 indicates that there are three music segments; the codec"
  1338.     OutputInfo "    will switch to music mode at 0 to 10 seconds, 50 to 80 seconds, and 150"
  1339.     OutputInfo "    to 200 seconds. The version number should always be the number 1. "
  1340.     OutputInfo "    Finally, the optimization definition file must use Unicode encoding. You"
  1341.     OutputInfo "    must specify the Windows Media Audio Voice codec and -a_content 2 when"
  1342.     OutputInfo "    when you use the -a_contentedl option."
  1343.     OutputInfo "[-a_folddown6to2] <surround mix> <center mix> <LFE>"
  1344.     OutputInfo "    Mixdown coefficients for multi-channel audio. Use whole numbers only."
  1345.     OutputInfo "    Values will be converted to negative numbers. Valid numbers are 0 to 144."
  1346.     OutputInfo "    For example, -a_folddown6to2 10 3 3"
  1347.     OutputInfo "[-a_formats]"
  1348.     OutputInfo "    Lists all audio formats for each codec."
  1349.     OutputInfo "[-a_mode] <mode_number>"
  1350.     OutputInfo "    Audio encoding to be used."
  1351.     OutputInfo "    0: 1-pass CBR; -a_setting required."
  1352.     OutputInfo "    1: 2-pass CBR; -a_setting required."
  1353.     OutputInfo "    2: Quality-based VBR; -a_setting Q* required."
  1354.     OutputInfo "    3: Bit rate-based VBR (two-pass); -a_setting required."
  1355.     OutputInfo "    4: Bit rate-based peak VBR (two-pass); -a_setting required." 
  1356.     OutputInfo "    Default: 1-pass CBR"
  1357.     OutputInfo "[-a_peakbitrate] <peak bit rate>"
  1358.     OutputInfo "    Specifies the peak bit rate in bits per second for peak bit rate-based"
  1359.     OutputInfo "    VBR for audio. If not specified, the peak bit rate is 1.5 times the"
  1360.     OutputInfo "    audio bit rate."
  1361.     OutputInfo "[-a_peakbuffer] <peak buffer>"
  1362.     OutputInfo "    Buffer in msec for audio with peak bit rate-based VBR. If not specified,"
  1363.     OutputInfo "    the default of 3000 msec is used."
  1364.     OutputInfo "[-a_setting] <setting>"
  1365.     OutputInfo "    Specifies the formats for audio setting."
  1366.     OutputInfo "    Use -a_formats to list supported audio formats for each codec."
  1367.     OutputInfo ""
  1368.     OutputInfo "    -a_setting Bitrate_SamplingRate_Channels. For example, -a_setting 48_44_2"
  1369.     OutputInfo "    specifies 48 Kbps, 44 kHz, and two channels. The default is 64_44_2."
  1370.     OutputInfo ""
  1371.     OutputInfo "    If you use quality-based VBR: -a_setting Qxx_SamplingRate_Channels."
  1372.     OutputInfo "    For example, -a_setting Q90_44_2 specifies a quality level of 90, 44 kHz,"
  1373.     OutputInfo "    and 2 channels."
  1374.     OutputInfo ""
  1375.     OutputInfo "    If you use the Windows Media Audio Professional 9:" 
  1376.     OutputInfo "    -a_setting Bitrate_SamplingRate_Channels_BitDepth."
  1377.     OutputInfo "    For example, -a_setting 250_44_2_24 specifies 250 Kbps, 44 kHz, "
  1378.     OutputInfo "    two channels, and 24-bit encoding. Use either 16- or 24-bit encoding."
  1379.     OutputInfo "    24-bit is the default."
  1380.     OutputInfo ""
  1381.     OutputInfo "    If you use the Windows Media Audio 9 lossless format:"
  1382.     OutputInfo "    -a_setting Qxx_SamplingRate_Channels_BitDepth. For example,"
  1383.     OutputInfo "    -a_setting Q100_44_2_24 specifies VBR Quality 100, 44 kHz, two channel,"
  1384.     OutputInfo "    24-bit encoding. (Quality-based VBR and a quality level of 100 is"
  1385.     OutputInfo "    required with the lossless format.)"
  1386.     OutputInfo "[-audioonly]"
  1387.     OutputInfo "    Encodes the audio portion of the stream only."
  1388.     OutputInfo ""
  1389.     OutputInfo ""
  1390.     OutputInfo ""
  1391.     OutputInfo ""
  1392.     OutputInfo "Usage for video settings."
  1393.     OutputInfo ""
  1394.     OutputInfo "[-v_codec] <codec index>"
  1395.     OutputInfo "    Video codec to be used. Use -v_codecs to list available video codecs."
  1396.     OutputInfo "    Specify codec index:"
  1397.     OutputInfo "       WMV7: Windows Media Video V7."
  1398.     OutputInfo "       WMV8: Windows Media Video V8."
  1399.     OutputInfo "       WMV9: Windows Media Video V9."
  1400.     OutputInfo "       WMS9: Windows Media Video Screen V9."
  1401.     OutputInfo "       Default: Windows Media Video V9."
  1402.     OutputInfo "[-v_width] <width>"
  1403.     OutputInfo "    Video frame width in pixels to be encoded. Default: Source video width."
  1404.     OutputInfo "[-v_height] <height>"
  1405.     OutputInfo "    Video frame height in pixels to be encoded. Default: Source video height."
  1406.     OutputInfo "[-v_framerate] <rate>"
  1407.     OutputInfo "    Video frame rate in floating point to be encoded. Default: 30 fps."
  1408.     OutputInfo "[-v_keydist] <time>"
  1409.     OutputInfo "    Key frame distance in seconds for video. Default: 10 seconds."
  1410.     OutputInfo "[-v_preproc] <filter number>"
  1411.     OutputInfo "    Video preprocessing for certain input sources."
  1412.     OutputInfo "    0: None (for progressive video input)."
  1413.     OutputInfo "    1: Deinterlace but preserve the size."
  1414.     OutputInfo "       For example, 640x480x30 interlace to 640x480x30 progressive."
  1415.     OutputInfo "    2: Deinterlace but halve the size."
  1416.     OutputInfo "       For example, 640x480x30 interlace to 320x240x30 progressive."
  1417.     OutputInfo "    3: Deinterlace, halve the size, and double the frame rate."
  1418.     OutputInfo "       For example, 640x480x30 interlace to 320x240x60 progressive."
  1419.     OutputInfo "    4: Deinterlace, halve vertical size, and double frame rate."
  1420.     OutputInfo "       For example, 320x480x30 interlace to 320x240x60 progressive."
  1421.     OutputInfo "    5: Inverse telecine from 30fps to 24fps."
  1422.     OutputInfo "    6: Inverse telecine - First field is top field with AA telecine pattern."
  1423.     OutputInfo "    7: Inverse telecine - First field is top field with BB telecine pattern."
  1424.     OutputInfo "    8: Inverse telecine - First field is top field with BC telecine pattern."
  1425.     OutputInfo "    9: Inverse telecine - First field is top field with CD telecine pattern."
  1426.     OutputInfo "    10:Inverse telecine - First field is top field with DD telecine pattern."
  1427.     OutputInfo "    11:Inverse telecine - First field is bottom field with AA telecine "
  1428.     OutputInfo "       pattern."
  1429.     OutputInfo "    12:Inverse telecine - First field is bottom field with BB telecine"
  1430.     OutputInfo "       pattern."
  1431.     OutputInfo "    13:Inverse telecine - First field is bottom field with BC telecine"
  1432.     OutputInfo "       pattern."
  1433.     OutputInfo "    14:Inverse telecine - First field is bottom field with CD telecine"
  1434.     OutputInfo "      pattern."
  1435.     OutputInfo "    15:Inverse telecine - First field is bottom field with DD telecine"
  1436.     OutputInfo "       pattern."
  1437.     OutputInfo "    16:Interlaced encoding."
  1438.     OutputInfo "    17:Interlaced encoding - First field is top field."
  1439.     OutputInfo "    18:Interlaced encoding - First field is bottom field."
  1440.     OutputInfo "    Default: 0: None."
  1441.     OutputInfo "[-v_clip] <left> <top> <right> <bottom>"
  1442.     OutputInfo "    The region of the image (with respect to source) to be clipped/encoded."
  1443.     OutputInfo "    If the right is 0 or greater than width, it is ignored and re-assigned"
  1444.     OutputInfo "    to width. If the bottom is 0 or greater than height, it is ignored and"
  1445.     OutputInfo "    re-assigned to height."
  1446.     OutputInfo "[-v_mode] <mode number>"
  1447.     OutputInfo "    Video encoding to be used."
  1448.     OutputInfo "    0: 1-pass CBR; -v_bitrate, -v_buffer, and -v_quality required"
  1449.     OutputInfo "    1: 2-pass CBR; -v_bitrate, -v_buffer, and -v_quality required"
  1450.     OutputInfo "    2: Quality-based VBR; -v_quality required"
  1451.     OutputInfo "    3: Bit rate-based VBR (two-pass); -v_bitrate required"
  1452.     OutputInfo "    4: Peak bit rate-based VBR (two-pass); -v_bitrate required"
  1453.     OutputInfo "    Default: 1-pass CBR "
  1454.     OutputInfo "[-v_bitrate] <bit rate>"
  1455.     OutputInfo "    Video bit rate in bits per second to be encoded. Default: 250000 bps."
  1456.     OutputInfo "    Set this to 0 for audio-only coding."
  1457.     OutputInfo "[-v_buffer] <buffer>"
  1458.     OutputInfo "    Delay buffer in milliseconds for video. Default: 3000 msec."
  1459.     OutputInfo "[-v_quality] <quality>"
  1460.     OutputInfo "    CBR: Quality/smoothness tradeoff. 0 to 100, 0 being the smoothest."
  1461.     OutputInfo "    Default: 75."
  1462.     OutputInfo "    Quality-based VBR: Image quality for the video. Encode video to the"
  1463.     OutputInfo "    specified quality, regardless of bit rate. Default: 85"
  1464.     OutputInfo "[-v_peakbitrate] <peak bit rate>"
  1465.     OutputInfo "    Peak bit rate in bits per second for peak bit rate-based VBR for video."
  1466.     OutputInfo "    If not specified, the peak bit rate is 1.5 times the video bit rate."
  1467.     OutputInfo "[-v_peakbuffer] <peak buffer>"
  1468.     OutputInfo "    Buffer in msec for video, with peak bit rate-based VBR. If not specified,"
  1469.     OutputInfo "    the default of 3000 msec is used."
  1470.     OutputInfo "[-v_performance] <performance>"
  1471.     OutputInfo "    Use to adjust hardware performance settings. Possible values: 0, 20, 40, 60, 80,"
  1472.     OutputInfo "    and 100, with 100 representing the highest quality. By default, the values "
  1473.     OutputInfo "    specified in Windows Media Encoder (Tools/Options/Performance) are used."
  1474.     OutputInfo "[-v_profile] <device conformance>"
  1475.     OutputInfo "    SP/MP/CP (Simple, Main, Complex)"
  1476.     OutputInfo "[-duration] <seconds>"
  1477.     OutputInfo "    Amount of time in seconds to encode. Use when sourcing from devices."
  1478.     OutputInfo "[-saveprofile] <file name>"
  1479.     OutputInfo "    Saves current settings to a file for later reuse. Default file name"
  1480.     OutputInfo "    extension is .prx."
  1481.     OutputInfo "[-devices]"
  1482.     OutputInfo "    Lists audio and video capture devices."
  1483.     OutputInfo "[-v_codecs]"
  1484.     OutputInfo "    Lists all video codecs."
  1485.     OutputInfo "[-videoonly]"
  1486.     OutputInfo "    Encodes video stream only."
  1487.     OutputInfo "[-pixelratio] <x y>"
  1488.     OutputInfo "    Specifies the video pixel aspect ratio."
  1489.     OutputInfo "[-pixelformat] <format>"
  1490.     OutputInfo "    Specifies the video pixel format. Possible values:"
  1491.     OutputInfo "    AUTO (default)"
  1492.     OutputInfo "    I420"
  1493.     OutputInfo "    IYUV"
  1494.     OutputInfo "    RGB 1"
  1495.     OutputInfo "    RGB 24"
  1496.     OutputInfo "    RGB 32"
  1497.     OutputInfo "    RGB 4"
  1498.     OutputInfo "    RGB 555"
  1499.     OutputInfo "    RGB 565"
  1500.     OutputInfo "    RGB 8"
  1501.     OutputInfo "    UYVY"
  1502.     OutputInfo "    YUY2"
  1503.     OutputInfo "    YV12"
  1504.     OutputInfo "    YVU9"
  1505.     OutputInfo "    YVYU"
  1506.     OutputInfo ""
  1507.     OutputInfo "[-title] <string>"
  1508.     OutputInfo "    Title of the content. Enclose strings with spaces in quotations. For"
  1509.     OutputInfo "    example: -title ""Windows Media Sample"""
  1510.     OutputInfo "[-author] <string>"
  1511.     OutputInfo "[-copyright] <string>"
  1512.     OutputInfo "[-description] <string>    "
  1513.     OutputInfo "[-rating] <string>"
  1514.     OutputInfo "NOTE: The maximum string length for each one is 255.    "
  1515. end function
  1516.  
  1517. ' Brings up the encoder utility chm file
  1518. function ShowHelpChm()
  1519.     dim strChmFileName, strExeName, strCommandLine
  1520.     dim RetVal
  1521.     dim objShell, objDir
  1522.  
  1523.     'Create a shell object. we will use this to execute the command
  1524.     Set objShell = WScript.CreateObject("WScript.Shell")
  1525.  
  1526.     'Get the Windows directory object
  1527.     set objDir = g_objFileSystem.GetSpecialFolder( 0 )
  1528.  
  1529.     'make the executable name ( %windir%\hh.exe ) form the windows dir object
  1530.     strExeName = objDir.drive & "\" & objDir.name & "\"
  1531.     strExeName = strExeName & "hh.exe" 
  1532.  
  1533.     'make the full path name for the chm file to be shown
  1534.     strChmFileName = """" & ObjDir.drive & "\program files\windows media components\encoder\wmencutil.chm" & """"
  1535.  
  1536.     'make the command line
  1537.     strCommandLine = strExeName & " " & strChmFileName
  1538.  
  1539.     'run the command and dont wait for the app to finish
  1540.     RetVal = objShell.Run( strCommandLine, 4, FALSE )
  1541. end function
  1542.  
  1543. ' Print out info about the input file
  1544. function PrintFileInfo()
  1545.     dim strCommandLine
  1546.     dim RetVal
  1547.     dim objShell, objDir, oExec
  1548.  
  1549.     'Create a shell object. we will use this to execute the command
  1550.     Set objShell = WScript.CreateObject("WScript.Shell")
  1551.  
  1552.     'Get the Windows directory object
  1553.     set objDir = g_objFileSystem.GetSpecialFolder( 0 )
  1554.  
  1555.     'make the full path name for the exe file
  1556.     strCommandLine = "cmd /K """ & ObjDir.drive & "\program files\windows media components\encoder\FileInfo.exe" & """ " & g_strInput
  1557.  
  1558.     'run the command and dont wait for the app to finish
  1559.     RetVal = objShell.run( strCommandLine, 4, FALSE )
  1560. end function
  1561.  
  1562. ' List audio codecs.
  1563. function ListAudioCodecs()
  1564.     dim objProfile
  1565.     dim objName
  1566.     dim intFourCC
  1567.     dim intVBRMode
  1568.     dim strCodecId
  1569.     
  1570.     set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" )
  1571.  
  1572.     OutputInfo vbCrLf & "Audio Codecs: "
  1573.  
  1574.     ' For all VBR modes    
  1575.     for intVBRMode = 1 to 4
  1576.         objProfile.VBRMode(WMENC_AUDIO, 0) = intVBRMode
  1577.  
  1578.         select case intVBRMode
  1579.             case WMENC_PVM_NONE
  1580.                 OutputInfo "CBR Mode :"
  1581.  
  1582.             case WMENC_PVM_PEAK
  1583.                 OutputInfo "Peak Bit Rate-Based VBR Audio Mode :"
  1584.  
  1585.             case WMENC_PVM_UNCONSTRAINED
  1586.                 OutputInfo "Quality-Based VBR Audio Mode :"
  1587.  
  1588.             case WMENC_PVM_BITRATE_BASED
  1589.                 OutputInfo "Bit Rate-Based VBR Audio Mode :"
  1590.     
  1591.             case else
  1592.                 OutputInfo "Unknown Mode"
  1593.         end select
  1594.  
  1595.         ' Enum all audio codecs
  1596.         for i=0 to objProfile.AudioCodecCount-1
  1597.             objProfile.EnumAudioCodec i, objName
  1598.  
  1599.             'Check and display fourcc
  1600.             intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_AUDIO, i)
  1601.             select case intFourCC
  1602.                 case WMA9STD_FOURCC
  1603.                     strCodecId = WMA9STD
  1604.  
  1605.                 case WMA9PRO_FOURCC
  1606.                     strCodecId = WMA9PRO
  1607.  
  1608.                 case WMA9LSL_FOURCC
  1609.                     strCodecId = WMA9LSL
  1610.  
  1611.                 case WMSPEECH_FOURCC
  1612.                     strCodecId = WMSPEECH
  1613.  
  1614.                 case PCM_FOURCC
  1615.                     strCodecId = PCM
  1616.  
  1617.                 case else
  1618.                     strCodecId = ""
  1619.             end select
  1620.  
  1621.             if( strCodecId <> "" ) then  
  1622.                 OutputInfo vbTab &  "[" & i & "] "  & strCodecId & " : " & objName
  1623.             else
  1624.                 OutputInfo vbTab &  "[" & i & "] "  & objName
  1625.             end if
  1626.         next
  1627.  
  1628.         OutputInfo vbCrLf
  1629.     next
  1630.     
  1631. end function
  1632.  
  1633. ' List video codecs.
  1634. function ListVideoCodecs()
  1635.     dim objProfile
  1636.     dim objName
  1637.     dim intFourCC
  1638.     dim strCodecId
  1639.     
  1640.     set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" )
  1641.  
  1642.     OutputInfo vbCrLf & "Video Codecs: "
  1643.  
  1644.     ' Enum all audio codecs
  1645.     for i=0 to objProfile.VideoCodecCount-1
  1646.         objProfile.EnumVideoCodec i, objName
  1647.  
  1648.         'Check and display fourcc
  1649.         intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_VIDEO, i)
  1650.         select case intFourCC
  1651.             case WMV7_FOURCC
  1652.                 strCodecId = WMV7
  1653.  
  1654.             case WMV8_FOURCC
  1655.                 strCodecId = WMV8
  1656.  
  1657.             case WMV9_FOURCC
  1658.                 strCodecId = WMV9
  1659.  
  1660.             case WMS9_FOURCC
  1661.                 strCodecId = WMS9
  1662.  
  1663.             case MP41_FOURCC
  1664.                 strCodecId = MP41
  1665.  
  1666.             case UNCOMP_FOURCC
  1667.                 strCodecId = UNCOMP
  1668.  
  1669.             case else
  1670.                 strCodecId = ""
  1671.         end select
  1672.  
  1673.         if( strCodecId <> "" ) then  
  1674.             OutputInfo vbTab &  "[" & i & "] "  & strCodecId & " : " & objName
  1675.         else
  1676.             OutputInfo vbTab &  "[" & i & "] "  & objName
  1677.         end if
  1678.     next
  1679.  
  1680. end function
  1681.  
  1682. ' List audio formats.
  1683. function ListAudioFormats()
  1684.     dim objProfile
  1685.     dim objName
  1686.     dim intFourCC
  1687.     dim intVBRMode
  1688.     dim strCodecId, strAudFormatName, strSetting
  1689.     dim intAudioSampleRate, intAudioChannels, intAudioBitsPerSample, intAudioBitrate 
  1690.     dim intArgSpaceCount, intBitrateSpaceCount, intSamplingRateSpaceCount, intChannelSpaceCount
  1691.     
  1692.     intArgSpaceCount = 24
  1693.     intBitrateSpaceCount = 16
  1694.     intSamplingRateSpaceCount = 20
  1695.     intChannelSpaceCount = 10
  1696.  
  1697.     set objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" )
  1698.  
  1699.     OutputInfo vbCrLf & "Audio Codecs: "
  1700.  
  1701.     ' For all VBR modes    
  1702.     for intVBRMode = 1 to 4
  1703.         objProfile.VBRMode(WMENC_AUDIO, 0) = intVBRMode
  1704.  
  1705.         select case intVBRMode
  1706.             case WMENC_PVM_NONE
  1707.                 OutputInfo "CBR Mode :"
  1708.  
  1709.             case WMENC_PVM_PEAK
  1710.                 OutputInfo "Peak Bit Rate-Based VBR Audio Mode :"
  1711.  
  1712.             case WMENC_PVM_UNCONSTRAINED
  1713.                 OutputInfo "Quality-Based VBR Audio Mode :"
  1714.  
  1715.             case WMENC_PVM_BITRATE_BASED
  1716.                 OutputInfo "Bit Rate-Based VBR Audio Mode :"
  1717.     
  1718.             case else
  1719.                 OutputInfo "Unknown Mode"
  1720.         end select
  1721.  
  1722.         ' Enum all audio codecs
  1723.         for i=0 to objProfile.AudioCodecCount-1
  1724.             objProfile.EnumAudioCodec i, objName
  1725.  
  1726.             'Check and display fourcc
  1727.             intFourCC = objProfile.GetCodecFourCCFromIndex(WMENC_AUDIO, i)
  1728.             select case intFourCC
  1729.                 case WMA9STD_FOURCC
  1730.                     strCodecId = WMA9STD
  1731.  
  1732.                 case WMA9PRO_FOURCC
  1733.                     strCodecId = WMA9PRO
  1734.  
  1735.                 case WMA9LSL_FOURCC
  1736.                     strCodecId = WMA9LSL
  1737.  
  1738.                 case WMSPEECH_FOURCC
  1739.                     strCodecId = WMSPEECH
  1740.  
  1741.                 case PCM_FOURCC
  1742.                     strCodecId = PCM
  1743.             end select
  1744.  
  1745.             if( strCodecId <> "" ) then  
  1746.                 OutputInfo vbTab & strCodecId & " : " & objName & " (" & strCodecId & "):"
  1747.             else
  1748.                 OutputInfo vbTab & objName & ":"
  1749.             end if
  1750.  
  1751.             OutputInfo vbCrLf
  1752.  
  1753.             if intVBRMode = WMENC_PVM_UNCONSTRAINED then
  1754.                 if strCodecId <> WMA9PRO then
  1755.                     OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Quality", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & "Channel"
  1756.                 else
  1757.                     OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Quality", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & PadSpaces("Channel", intChannelSpaceCount) & "BitsPerSample"
  1758.                 end if
  1759.             else
  1760.                 if strCodecId <> WMA9PRO and strCodecId <> WMA9LSL then
  1761.                     OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Bitrate", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & "Channel"
  1762.                 else
  1763.                     OutputInfo vbTab & vbTab & PadSpaces("Argument", intArgSpaceCount) & PadSpaces("Bitrate", intBitrateSpaceCount) & PadSpaces("Sampling rate", intSamplingRateSpaceCount) & PadSpaces("Channel", intChannelSpaceCount) & "BitsPerSample"
  1764.                 end if
  1765.             end if
  1766.  
  1767.             OutputInfo vbTab & vbTab & "------------------------------------------------------------------------------------"
  1768.  
  1769.             For j=0 To objProfile.audioFormatCount(i) - 1
  1770.                 intAudioBitrate = objProfile.EnumAudioFormat(i, j, strAudFormatName, intAudioSampleRate, intAudioChannels, intAudioBitsPerSample)
  1771.  
  1772.                 if intVBRMode <> WMENC_PVM_UNCONSTRAINED then
  1773.                     intAudioBitrate = CLng(intAudioBitrate / 1000)
  1774.                 else
  1775.                     intAudioBitrate = "Q" & intAudioBitrate
  1776.                 end if
  1777.  
  1778.                 if intAudioSampleRate = 88200 then
  1779.                     intAudioSampleRate = 88
  1780.                 elseif intAudioSampleRate = 44100 then
  1781.                     intAudioSampleRate = 44
  1782.                 elseif intAudioSampleRate = 22050 then
  1783.                     intAudioSampleRate = 22
  1784.                 elseif intAudioSampleRate = 11025 then
  1785.                     intAudioSampleRate = 11
  1786.                 else
  1787.                     intAudioSampleRate = Clng(intAudioSampleRate / 1000)
  1788.                 end if
  1789.  
  1790.                 if strCodecId <> WMA9PRO and strCodecId <> WMA9LSL then
  1791.                     strSetting = intAudioBitrate & "_" & intAudioSampleRate & "_" & intAudioChannels
  1792.                     OutputInfo vbTab & vbTab & PadSpaces(strSetting, intArgSpaceCount) & PadSpaces(intAudioBitrate, intBitrateSpaceCount) & PadSpaces(intAudioSampleRate, intSamplingRateSpaceCount) & intAudioChannels
  1793.                 else 
  1794.                     strSetting = intAudioBitrate & "_" & intAudioSampleRate & "_" & intAudioChannels & "_" & intAudioBitsPerSample
  1795.                     OutputInfo vbTab & vbTab & PadSpaces(strSetting, intArgSpaceCount) & PadSpaces(intAudioBitrate, intBitrateSpaceCount) & PadSpaces(intAudioSampleRate, intSamplingRateSpaceCount) & PadSpaces(intAudioChannels, intChannelSpaceCount) & intAudioBitsPerSample
  1796.                 end if
  1797.  
  1798.             next 
  1799.     
  1800.             OutputInfo vbCrLf & vbCrLf
  1801.  
  1802.         next
  1803.         OutputInfo vbCrLf
  1804.     next
  1805.     
  1806. end function
  1807.  
  1808.  
  1809. ' Add spaces to the end of arg to create intCount characters string
  1810. function PadSpaces( arg, intCount )
  1811.  
  1812.     if Len(arg) >= intCount then
  1813.         PadSpaces = arg
  1814.         exit function
  1815.     end if
  1816.  
  1817.     PadSpaces = arg & Space( intCount - Len(arg) )
  1818. end function
  1819.  
  1820.  
  1821.  
  1822. ' List all audio and video devices.
  1823. function ListDevices()
  1824.     dim objManager, objPlugin, i
  1825.     
  1826.     set objManager = g_objEncoder.SourcePluginInfoManager
  1827.  
  1828.     for i=0 to objManager.Count-1
  1829.         set objPlugin = objManager.Item(i)
  1830.  
  1831.         if objPlugin.Resources = true then
  1832.             if objPlugin.MediaType = WMENC_AUDIO then
  1833.                 OutputInfo vbCrLf & "Audio Devices: "
  1834.  
  1835.                 ' Enum all devices in this type
  1836.                 for j=0 to objPlugin.Count-1
  1837.                     OutputInfo vbTab & j & " : " & objPlugin.Item(j)
  1838.                 next
  1839.             elseif objPlugin.MediaType = WMENC_VIDEO then
  1840.                 OutputInfo vbCrLf & "Video Devices: "
  1841.  
  1842.                 ' Enum all devices in this type
  1843.                 for j=0 to objPlugin.Count-1
  1844.                     OutputInfo vbTab &  j & " : " & objPlugin.Item(j)
  1845.                 next
  1846.             end if            
  1847.         end if
  1848.     next
  1849. end function
  1850.  
  1851. ' Setup encoder using the current settings.
  1852. function SetupEncoder( )
  1853.     
  1854.     if not CreateSourceGroup() then
  1855.         SetupEncoder = false
  1856.         exit function
  1857.     end if
  1858.  
  1859.     if not SetupInput() then
  1860.         SetupEncoder = false
  1861.         exit function
  1862.     end if
  1863.  
  1864.     if not SetupProfile() then
  1865.         SetupEncoder = false
  1866.         exit function
  1867.     end if
  1868.  
  1869.     if not SetupOutput()  then
  1870.         SetupEncoder = false
  1871.         exit function
  1872.     end if
  1873.  
  1874.     if not SetupTime() then
  1875.         SetupEncoder = false
  1876.         exit function
  1877.     end if
  1878.  
  1879.     if not SetupDisplayInfo() then
  1880.         SetupEncoder = false
  1881.         exit function
  1882.     end if
  1883.  
  1884.     g_objEncoder.AutoStop = true
  1885.  
  1886.     SetupEncoder = true
  1887. end function
  1888.  
  1889. ' Create Source group by loading from wme or adding a new one
  1890. function CreateSourceGroup()
  1891.  
  1892.     dim objProfile
  1893.     dim intCodecIndex
  1894.  
  1895.     ' If a WME file is provided, load the encoding configuration from this WME file.
  1896.     if g_strWMEFile <> "" then
  1897.         on error resume next
  1898.  
  1899.         ' Load enocder session from a WME file
  1900.         g_objEncoder.Load( g_objFileSystem.GetAbsolutePathName( g_strWMEFile ) )
  1901.  
  1902.         ' Add a new source group.
  1903.         set g_objSourceGroup = g_objEncoder.SourceGroupCollection.Item(0)
  1904.  
  1905.         set objProfile = g_objSourceGroup.Profile
  1906.         set g_objProfile = WScript.CreateObject( "WMENCENG.WMEncProfile2" )
  1907.         g_objProfile.LoadFromIWMProfile( objProfile )
  1908.  
  1909.         ' If source file has an auido stream, get the audio source.
  1910.         if g_objSourceGroup.SourceCount( WMENC_AUDIO ) > 0 then
  1911.             set g_objAudioSource = g_objSourceGroup.Source( WMENC_AUDIO, 0 )
  1912.             intCodecIndex = g_objProfile.Audience(0).AudioCodec( 0 )
  1913.             g_objProfile.EnumAudioCodec intCodecIndex, g_strAudioCodecName
  1914.         end if
  1915.  
  1916.         ' If source file has a video stream, get the video source.
  1917.         if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then
  1918.             set g_objVideoSource = g_objSourceGroup.Source( WMENC_VIDEO, 0 )
  1919.             intCodecIndex = g_objProfile.Audience(0).VideoCodec( 0 )
  1920.             g_objProfile.EnumVideoCodec intCodecIndex, g_strVideoCodecName
  1921.         end if
  1922.  
  1923.         g_blnCreateCustomProfile = false
  1924.  
  1925.         if err.number <> 0 then
  1926.             OutputInfo "Loading the session (.wme) file failed: " & g_strWMEFile
  1927.             err.Clear
  1928.             CreateSourceGroup = false
  1929.             exit function
  1930.         end if
  1931.     else
  1932.         ' Create a new source group for this session
  1933.         set g_objSourceGroup = g_objEncoder.SourceGroupCollection.Add( "SG_1" )
  1934.     end if
  1935.  
  1936.     CreateSourceGroup = true
  1937. end function
  1938.  
  1939. ' Setup profile configuration
  1940. function SetupProfile()
  1941.     'on error resume next
  1942.  
  1943.     dim objProfile
  1944.     dim objAudience
  1945.     dim blnRet
  1946.  
  1947.     if IsNull(g_objProfile) then
  1948.         Set g_objProfile = WScript.CreateObject( "WMENCEng.WMEncProfile2" )
  1949.         g_objProfile.ContentType = g_intSessionType
  1950.         g_objProfile.ProfileName = "WMCMDProfile"
  1951.  
  1952.         Set objAudience = g_objProfile.AddAudience( 10000000 )
  1953.     else
  1954.         Set objAudience = g_objProfile.Audience( 0 )
  1955.  
  1956.     end if
  1957.  
  1958.     ' if profile string is specified load it
  1959.     if g_strProfile <> "" then
  1960.         blnRet = SetupPredefinedProfile( objAudience )
  1961.  
  1962.         g_blnCreateCustomProfile = false
  1963.  
  1964.         if not blnRet then
  1965.             SetupProfile = false
  1966.             exit function
  1967.         end if
  1968.     end if
  1969.  
  1970.  
  1971.     ' First time: override the WME or predefined profile with custom values
  1972.     blnRet = SetupCustomProfile( objAudience )
  1973.  
  1974.     LoadProfileDefaults()
  1975.  
  1976.     if g_blnCreateCustomProfile then
  1977.         ' Second time: Update profile based on input specified and default values
  1978.         blnRet = SetupCustomProfile( objAudience )
  1979.  
  1980.         if not blnRet then
  1981.             SetupProfile = false
  1982.             exit function
  1983.         end if
  1984.     end if
  1985.  
  1986.     ' Invalid profile
  1987.     if err.number <> 0 then
  1988.         OutputInfo "Invalid profile: " & err.number
  1989.         err.Clear
  1990.         SetupProfile = false
  1991.         exit function
  1992.     end if
  1993.  
  1994.     ' Set a few more things like interlaced coding and pixel ratio
  1995.     if g_intPixelAspectRatioX <> 1 or g_intPixelAspectRatioY <> 1 then
  1996.         g_objProfile.NonSquarePixelMode(0) = true
  1997.     end if
  1998.  
  1999.     if g_intVideoPreprocess >= 16 and g_intVideoPreprocess <= 18 then
  2000.         g_objProfile.InterlaceMode(0) = true
  2001.     end if
  2002.  
  2003.     ' Set the profile in encoder.
  2004.     g_objSourceGroup.Profile = g_objProfile
  2005.     
  2006.     if g_strProfileSave <> "" then
  2007.         g_objProfile.SaveToFile g_strProfileSave
  2008.     end if
  2009.  
  2010.     SetupProfile = true
  2011. end function
  2012.  
  2013. ' Setup ouptut configuration.
  2014. function SetupOutput()
  2015.     ' Is an output file name provided?
  2016.     if g_strOutput <> "" then
  2017.         ' Is this output name a directory?
  2018.         if g_objFileSystem.FolderExists( g_strOutput ) then
  2019.             
  2020.             ' If the output name is a directory, create the real output file name.
  2021.             ' If the input is a file, use the file name of the input file (extension is not ussed).
  2022.             ' If the inputs are devices, use 'output' as the output name.            
  2023.             if g_strInput <> "" then
  2024.                 g_strOutput = g_strOutput & "\\" & g_objFileSystem.GetBaseName( g_strInput )
  2025.             else
  2026.                 g_strOutput = g_strOutput & "\\output"
  2027.             end if
  2028.         end if
  2029.  
  2030.         ' If the output file name doesn't have a extension, create a proper one.
  2031.         if g_objFileSystem.GetExtensionName( g_strOutput ) = "" then
  2032.             
  2033.             ' Does "." already exist in the output file name.
  2034.             ' If not, append "." to the output file name.
  2035.             if Right( g_strOutput, 1 ) <>  "." then
  2036.                 g_strOutput = g_strOutput & "."
  2037.             end if
  2038.  
  2039.             ' Does this session have a video source?
  2040.             ' If it has video stream, append wmv extension, otherwise wma extension is appended.
  2041.             if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then
  2042.                 g_strOutput = g_strOutput & "wmv"
  2043.             else
  2044.                 g_strOutput = g_strOutput & "wma"
  2045.             end if
  2046.         end if
  2047.  
  2048.         CreateOutputFolder( g_objFileSystem.GetParentFolderName( g_objFileSystem.GetAbsolutePathName( g_strOutput ) ) )
  2049.  
  2050.         g_objEncoder.File.LocalFileName = g_strOutput
  2051.     else
  2052.         ' Get the output file name from WME file.
  2053.         if not IsNull(g_objEncoder.File.LocalFileName) then
  2054.             g_strOutput = g_objEncoder.File.LocalFileName
  2055.         end if
  2056.     end if
  2057.  
  2058.     ' Enable HTTP broadcasting for the encoder if a broadcast port is provided.
  2059.     if g_intBroadcast <> -1 then
  2060.         g_objEncoder.Broadcast.PortNumber( WMENC_PROTOCOL_HTTP ) = g_intBroadcast
  2061.     end if
  2062.  
  2063.     ' Enable push if push server is specified
  2064.     if g_strPushServer <> "" then
  2065.         g_objEncoder.Broadcast.ServerName = g_strPushServer
  2066.         g_objEncoder.Broadcast.PublishingPoint = g_strPublishingPoint
  2067.         if g_strPushTemplate <> "" then
  2068.             g_objEncoder.Broadcast.Template = g_strPushTemplate
  2069.         end if
  2070.     end if
  2071.  
  2072.     SetupOutput = true
  2073. end function
  2074.  
  2075. ' Setup display configuration
  2076. function SetupDisplayInfo()
  2077.     dim objDisplayInfo
  2078.     dim objAttributes
  2079.     
  2080.     set objDisplayInfo = g_objEncoder.DisplayInfo
  2081.     set objAttributes = g_objEncoder.Attributes
  2082.  
  2083.     ' Is title set?
  2084.     if g_strTitle <> "" then
  2085.         objDisplayInfo.Title = g_strTitle
  2086.     end if
  2087.  
  2088.     ' Is author set?
  2089.     if g_strAuthor <> "" then
  2090.         objDisplayInfo.Author = g_strAuthor
  2091.     end if
  2092.  
  2093.     ' Is copyright set?
  2094.     if g_strCopyright <> "" then
  2095.         objDisplayInfo.Copyright = g_strCopyright
  2096.     end if
  2097.  
  2098.     ' Is description set?
  2099.     if g_strDescription <> "" then
  2100.         objDisplayInfo.Description = g_strDescription
  2101.     end if
  2102.  
  2103.     ' Is rating set?
  2104.     if g_strRating <> "" then
  2105.         objDisplayInfo.Rating = g_strRating
  2106.     end if
  2107.  
  2108.     ' Add folddown coefficients
  2109.     if g_intAudioSurroundMix <> -1 then
  2110.         objAttributes.Add "SurroundMix", -g_intAudioSurroundMix
  2111.         objAttributes.Add "CenterMix", -g_intAudioCenterMix
  2112.         objAttributes.Add "LFEMix", -g_intAudioLEFMix
  2113.     end if
  2114.  
  2115.     SetupDisplayInfo = true
  2116. end function
  2117.  
  2118. ' Setup a new profile based on predefined profiles
  2119. function SetupPredefinedProfile(objAudience)
  2120.     dim intAudioCodecIndex, intVideoCodecIndex
  2121.     
  2122.     select case LCase( g_strProfile )
  2123.         case "av20":
  2124.             SetupAudioAudience objAudience, "WMA9STD", 1, 8000, 5000, 16
  2125.             SetupVideoAudience objAudience, "WMV9", 15000, 160, 120, 15000, 5000, 75, 10000
  2126.  
  2127.         case "av32":
  2128.             SetupAudioAudience objAudience, "WMA9STD", 1, 11025, 10168, 16
  2129.             SetupVideoAudience objAudience, "WMV9", 22000, 176, 144, 15000, 5000, 75, 10000
  2130.  
  2131.         case "av100":
  2132.             SetupAudioAudience objAudience, "WMA9STD", 1, 16000, 16000, 16
  2133.             SetupVideoAudience objAudience, "WMV9", 84000, 320, 240, 15000, 5000, 75, 10000
  2134.  
  2135.         case "av225":
  2136.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 40000, 16
  2137.             SetupVideoAudience objAudience, "WMV9", 185000, 320, 240, 30000, 5000, 75, 10000
  2138.  
  2139.         case "av350":
  2140.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 48000, 16
  2141.             SetupVideoAudience objAudience, "WMV9", 302000, 320, 240, 30000, 5000, 75, 10000
  2142.  
  2143.         case "av450":
  2144.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2145.             SetupVideoAudience objAudience, "WMV9", 386000, 320, 240, 30000, 5000, 75, 10000
  2146.  
  2147.         case "av700":
  2148.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2149.             SetupVideoAudience objAudience, "WMV9", 636000, 320, 240, 30000, 5000, 75, 10000
  2150.  
  2151.         case "av1400":
  2152.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 128040, 16
  2153.             SetupVideoAudience objAudience, "WMV9", 1272000, 320, 240, 30000, 5000, 75, 10000
  2154.  
  2155.         case "av350pal":
  2156.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 48000, 16
  2157.             SetupVideoAudience objAudience, "WMV9", 302000, 352, 288, 25000, 5000, 75, 10000
  2158.  
  2159.         case "av700pal":
  2160.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2161.             SetupVideoAudience objAudience, "WMV9", 636000, 352, 288, 25000, 5000, 75, 10000
  2162.  
  2163.         case "av100_2p":
  2164.             SetupAudioAudience objAudience, "WMA9STD", 1, 16000, 16000, 16
  2165.             SetupVideoAudience objAudience, "WMV9", 84000, 320, 240, 15000, 5000, 75, 10000
  2166.             g_objAudioSource.PreProcessPass = 1
  2167.             g_objVideoSource.PreProcessPass = 1
  2168.  
  2169.         case "av350_2p"
  2170.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 48000, 16
  2171.             SetupVideoAudience objAudience, "WMV9", 302000, 320, 240, 30000, 5000, 75, 10000
  2172.             g_objAudioSource.PreProcessPass = 1
  2173.             g_objVideoSource.PreProcessPass = 1
  2174.  
  2175.         case "av600vbr":
  2176.             g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK
  2177.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2178.             SetupVideoAudience objAudience, "WMV9", 536000, 320, 240, 24000, 5000, 75, 10000
  2179.             
  2180.             objAudience.VideoPeakBitrate(0) = 1.5 * objAudience.VideoBitrate(0)
  2181.             objAudience.VideoBufferMax(0) = 5000
  2182.  
  2183.             ' Turn telecine and two pass video on
  2184.             g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE
  2185.             g_objVideoSource.PreProcessPass = 1    
  2186.  
  2187.         case "avq97vbr":
  2188.             g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED
  2189.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64040, 16
  2190.             SetupVideoAudience objAudience, "WMV9", 536000, 320, 240, 24000, 5000, 97, 10000
  2191.  
  2192.             ' Turn telecine on
  2193.             g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE
  2194.  
  2195.         case "a20_1":
  2196.             SetupAudioAudience objAudience, "WMA9STD", 1, 22050, 20008, 16
  2197.  
  2198.         case "a20_2":
  2199.             SetupAudioAudience objAudience, "WMA9STD", 2, 22050, 20008, 16
  2200.  
  2201.         case "a32":
  2202.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 32000, 16
  2203.  
  2204.         case "a48":
  2205.             SetupAudioAudience objAudience, "WMA9STD", 2, 32000, 48024, 16
  2206.  
  2207.         case "a64":
  2208.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 64016, 16
  2209.  
  2210.         case "a96":
  2211.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 96024, 16
  2212.  
  2213.         case "a128":
  2214.             SetupAudioAudience objAudience, "WMA9STD", 2, 44100, 128016, 16
  2215.  
  2216.         case "v20":
  2217.             SetupVideoAudience objAudience, "WMV9", 20000, 176, 144, 15000, 5000, 75, 10000
  2218.  
  2219.         case "v32":
  2220.             SetupVideoAudience objAudience, "WMV9", 20000, 240, 176, 15000, 5000, 75, 10000
  2221.  
  2222.         case else
  2223.             SetupPredefinedProfile = false
  2224.             exit function
  2225.  
  2226.     end select
  2227.  
  2228.     SetupPredefinedProfile = true
  2229. end function
  2230.  
  2231. ' Given audio parameters this will setup the audience
  2232. function SetupAudioAudience(objAudience, strAudioCodec, intChannels, intSampleRate, intBitrate, intBitsPerSample)
  2233.     dim intAudioCodecIndex
  2234.  
  2235.     intAudioCodecIndex = GetAudioCodecIndex(strAudioCodec)
  2236.     g_objProfile.EnumAudioCodec intAudioCodecIndex, g_strAudioCodecName
  2237.     
  2238.     objAudience.AudioCodec(0) = intAudioCodecIndex
  2239.     objAudience.SetAudioConfig 0, intChannels, intSampleRate, intBitrate, intBitsPerSample
  2240. end function
  2241.  
  2242. ' Given video parameters this will setup the audience
  2243. function SetupVideoAudience(objAudience, strVideoCodec, intBitrate, intWidth, intHeight, intFps, intBufferWindow, intSmoothness, intKeyFrame)
  2244.     dim intVideoCodecIndex
  2245.     
  2246.     intVideoCodecIndex = GetVideoCodecIndex(strVideoCodec)
  2247.     g_objProfile.EnumVideoCodec intVideoCodecIndex, g_strVideoCodecName
  2248.  
  2249.     objAudience.VideoCodec(0) = intVideoCodecIndex
  2250.     objAudience.VideoBitrate(0) = intBitrate
  2251.     objAudience.VideoWidth(0) = intWidth
  2252.     objAudience.VideoHeight(0) = intHeight
  2253.     objAudience.VideoFps(0) = intFps
  2254.     objAudience.VideoKeyFrameDistance(0) = intKeyFrame
  2255.     objAudience.VideoBufferSize(0) = intBufferWindow
  2256.  
  2257.     ' For quality vbr mode use intSmoothness as VBR quality
  2258.     if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED then
  2259.         objAudience.VideoCompressionQuality(0) = intSmoothness
  2260.     else
  2261.         objAudience.VideoImageSharpness(0) = intSmoothness
  2262.     end if
  2263.  
  2264. end function
  2265.  
  2266. ' Given audio string(eg WMA9STD) this returns the audio codec index
  2267. function GetAudioCodecIndex(strAudioCodec)
  2268.     dim intFourCC
  2269.  
  2270.     select case strAudioCodec
  2271.         case WMA9STD
  2272.             intFourCC = WMA9STD_FOURCC
  2273.  
  2274.         case WMA9PRO
  2275.             intFourCC = WMA9PRO_FOURCC
  2276.  
  2277.         case WMA9LSL
  2278.             intFourCC = WMA9LSL_FOURCC
  2279.  
  2280.         case WMSPEECH
  2281.             intFourCC = WMSPEECH_FOURCC
  2282.  
  2283.         case PCM
  2284.             intFourCC = PCM_FOURCC
  2285.  
  2286.         case else
  2287.             intFourCC = WMA9STD_FOURCC
  2288.     end select
  2289.  
  2290.     GetAudioCodecIndex = g_objProfile.GetCodecIndexFromFourCC(WMENC_AUDIO, intFourCC)
  2291.  
  2292. end function
  2293.  
  2294. ' Given the video string(eg WMV9) this returns the video codec index
  2295. function GetVideoCodecIndex(strVideoCodec)
  2296.     dim intFourCC
  2297.  
  2298.     select case strVideoCodec
  2299.         case WMV7
  2300.             intFourCC = WMV7_FOURCC
  2301.  
  2302.         case WMV8
  2303.             intFourCC = WMV8_FOURCC
  2304.  
  2305.         case WMV9
  2306.             intFourCC = WMV9_FOURCC
  2307.  
  2308.         case WMS9
  2309.             intFourCC = WMS9_FOURCC
  2310.  
  2311.         case MP41
  2312.             intFourCC = MP41_FOURCC
  2313.  
  2314.         case UNCOMP
  2315.             intFourCC = UNCOMP_FOURCC
  2316.  
  2317.         case else
  2318.             intFourCC = WMV9_FOURCC
  2319.     end select
  2320.     
  2321.     GetVideoCodecIndex = g_objProfile.GetCodecIndexFromFourCC(WMENC_VIDEO, intFourCC)
  2322.  
  2323. end function
  2324.  
  2325. ' Setup a new profile based on predefined profiles
  2326. function SetupCustomProfile(objAudience)
  2327.     dim intAudioCodecIndex, intVideoCodecIndex
  2328.     dim blnRet
  2329.  
  2330.     if not isnull( g_objAudioSource ) then
  2331.         blnRet = SetupCustomAudioProfile( objAudience )
  2332.         if not blnRet then
  2333.             SetupCustomProfile = false
  2334.             exit function
  2335.         end if
  2336.     end if
  2337.  
  2338.     if not isnull( g_objVideoSource ) then
  2339.         blnRet = SetupCustomVideoProfile( objAudience )
  2340.         if not blnRet then
  2341.             SetupCustomProfile = false
  2342.             exit function
  2343.         end if
  2344.     end if
  2345.  
  2346.     SetupCustomProfile = true
  2347.  
  2348. end function
  2349.  
  2350. ' Setup the audio part of the custom profile
  2351. function SetupCustomAudioProfile(objAudience)
  2352.     ' Setup audio
  2353.     dim intAudioCodecIndex, intAudioBitrate, intAudioSampleRate, intAudioChannels, intBitDepth, intFourCC
  2354.     dim strTemp
  2355.     dim intNextArgStart, intNextArgEnd
  2356.     dim blnAudioQuality, blnValidBitrate, blnValidSampleRate, blnValidChannels, blnValidBitDepth
  2357.  
  2358.  
  2359.     'Set audio vbr mode
  2360.     if g_intAudioVBRMode <> -1 then
  2361.         select case g_intAudioVBRMode
  2362.             case 0 ' 1 pass CBR
  2363.  
  2364.             case 1 ' 2 pass CBR
  2365.                 g_objAudioSource.PreProcessPass = 1
  2366.  
  2367.             case 2 ' Quality VBR mode
  2368.                 g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_UNCONSTRAINED
  2369.  
  2370.             case 3 ' 2 pass bitrate based VBR
  2371.                 g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_BITRATE_BASED
  2372.                 g_objAudioSource.PreProcessPass = 1
  2373.  
  2374.             case 4 ' 2 pass bitrate-based peak constrained VBR
  2375.                 g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_PEAK
  2376.                 g_objAudioSource.PreProcessPass = 1
  2377.  
  2378.             case else
  2379.                 OutputInfo "Invalid -a_mode <mode_number>"
  2380.                 SetupCustomAudioProfile = false
  2381.                 exit function
  2382.         end select
  2383.     end if
  2384.  
  2385.  
  2386.     ' Set audio codec
  2387.     if g_strAudioCodec <> "" then
  2388.         intAudioCodecIndex = GetAudioCodecIndex(g_strAudioCodec)
  2389.         intFourCC = g_objProfile.EnumAudioCodec(intAudioCodecIndex, g_strAudioCodecName)
  2390.  
  2391.         objAudience.AudioCodec(0) = intAudioCodecIndex
  2392.     end if
  2393.  
  2394.     'Parse the a_setting string to extract audio bitrate sample rate and stuff like that
  2395.     if g_strAudioSetting <> "" then
  2396.         intNextArgStart = instr(g_strAudioSetting, "_")
  2397.         strTemp = left(g_strAudioSetting, intNextArgStart-1)
  2398.     
  2399.         if left(strTemp, 1) = "Q" then
  2400.             blnAudioQuality = true
  2401.             intAudioBitrate = ConvertStringToInteger( mid(strTemp, 2 ) )
  2402.         else
  2403.             intAudioBitrate = ConvertStringToInteger( strTemp )
  2404.         end if
  2405.  
  2406.         'OutputInfo "****Audio bit rate is " & intAudioBitrate
  2407.  
  2408.         intNextArgEnd = instr(intNextArgStart+1, g_strAudioSetting, "_")
  2409.         strTemp = mid(g_strAudioSetting, intNextArgStart+1, intNextArgEnd-intNextArgStart-1)
  2410.         intAudioSampleRate = ConvertStringToInteger( strTemp )
  2411.         'OutputInfo "****Audio sample rate is " & intAudioSampleRate
  2412.     
  2413.         intNextArgStart = intNextArgEnd
  2414.         intNextArgEnd = instr(intNextArgStart+1, g_strAudioSetting, "_")
  2415.         if intNextArgEnd > 0 then
  2416.             strTemp = mid(g_strAudioSetting, intNextArgStart+1, intNextArgEnd-intNextArgStart-1)
  2417.         else
  2418.             strTemp = mid(g_strAudioSetting, intNextArgStart+1)
  2419.         end if
  2420.         intAudioChannels = ConvertStringToInteger( strTemp )
  2421.         'OutputInfo "****Audio channels are " & intAudioChannels
  2422.  
  2423.         if intNextArgEnd > 0 then
  2424.             strTemp = mid(g_strAudioSetting, intNextArgEnd+1)
  2425.             intBitDepth = ConvertStringToInteger( strTemp )
  2426.         else
  2427.             intBitDepth = 16
  2428.         end if
  2429.         'OutputInfo "****Audio bit depth is " & intBitDepth
  2430.  
  2431.         if intAudioBitrate = -1 or intAudioSampleRate = -1 or intAudioChannels = -1 or intBitDepth = -1 then
  2432.             SetupCustomAudioProfile = false
  2433.             err.Raise &H80070057
  2434.             exit function
  2435.         end if
  2436.  
  2437.         'Convert bitrate and samplerate to actual values
  2438.         if blnAudioQuality = false then
  2439.             if intAudioBitrate = 1411 then
  2440.                 intAudioBitrate = 1411200
  2441.             elseif intAudioBitrate = 705 then
  2442.                 intAudioBitrate = 705600
  2443.             elseif intAudioBitrate = 353 then
  2444.                 intAudioBitrate = 352800
  2445.             else
  2446.                 intAudioBitrate = 1000 * intAudioBitrate
  2447.             end if
  2448.         end if
  2449.  
  2450.         ' For peak vbr mode set peakbitrate and peak buffer
  2451.         if g_objProfile.VBRMode(WMENC_AUDIO, 0) = WMENC_PVM_PEAK then
  2452.             if g_intAudioPeakBuffer <> -1 then
  2453.                 objAudience.AudioBufferMax(0) = g_intAudioPeakBuffer
  2454.             end if
  2455.  
  2456.             if g_intAudioPeakBitrate = -1 then
  2457.                 objAudience.AudioPeakBitrate(0) = 1.5 * intAudioBitrate
  2458.             else
  2459.                 objAudience.AudioPeakBitrate(0) = g_intAudioPeakBitrate
  2460.             end if
  2461.             'OutputInfo "****Audio peak bit rate is " & objAudience.AudioPeakbitrate(0)
  2462.             'OutputInfo "****Audio peak buffer is " & objAudience.AudioBufferMax(0)
  2463.         end if
  2464.  
  2465.         if intAudioSampleRate = 88 then
  2466.             intAudioSampleRate = 88200
  2467.         elseif intAudioSampleRate = 44 then
  2468.             intAudioSampleRate = 44100
  2469.         elseif intAudioSampleRate = 22 then
  2470.             intAudioSampleRate = 22050
  2471.         elseif intAudioSampleRate = 11 then
  2472.             intAudioSampleRate = 11025
  2473.         else
  2474.             intAudioSampleRate = 1000 * intAudioSampleRate
  2475.         end if
  2476.  
  2477.         ' Validate values for bitrate, samplerate, channels and depth 
  2478.         if blnAudioQuality = false then
  2479.             blnValidBitrate = CheckForValidAudioBitRates( intAudioBitrate )
  2480.             if blnValidBitrate = false then 
  2481.                 OutputInfo "Invalid audio bit rate " & intAudioBitrate
  2482.                 SetupCustomAudioProfile = false
  2483.                 exit function
  2484.             end if
  2485.         end if
  2486.  
  2487.         blnValidSampleRate = CheckForValidAudioSamplingRates( intAudioSampleRate )
  2488.         if blnValidSampleRate = false then 
  2489.             OutputInfo "Invalid audio sample rate " & intAudioSampleRate
  2490.             SetupCustomAudioProfile = false
  2491.             exit function
  2492.         end if
  2493.  
  2494.         blnValidChannels = CheckForValidAudioChannel( intAudioChannels )
  2495.         if blnValidChannels = false then 
  2496.             OutputInfo "Invalid audio channels " & intAudioChannels
  2497.             SetupCustomAudioProfile = false
  2498.             exit function
  2499.         end if
  2500.  
  2501.         blnValidBitDepth = CheckForValidDepth( intBitDepth )
  2502.         if blnValidBitDepth = false then 
  2503.             OutputInfo "Invalid bits per sample " & intBitDepth
  2504.             SetupCustomAudioProfile = false
  2505.             exit function
  2506.         end if
  2507.  
  2508.         objAudience.SetAudioConfig 0, intAudioChannels, intAudioSampleRate, intAudioBitrate, intBitDepth
  2509.     end if
  2510.  
  2511.     SetupCustomAudioProfile = true
  2512.  
  2513. end function
  2514.  
  2515. ' Setup the video part of the custom profile
  2516. function SetupCustomVideoProfile(objAudience)
  2517.     ' Setup audio
  2518.     dim intVideoCodecIndex, intFourCC
  2519.  
  2520.     'Set video vbr mode
  2521.     if g_intVideoVBRMode <> -1 then
  2522.         select case g_intVideoVBRMode
  2523.             case 0 ' 1 pass CBR
  2524.  
  2525.             case 1 ' 2 pass CBR
  2526.                 g_objVideoSource.PreProcessPass = 1
  2527.  
  2528.             case 2 ' Quality VBR mode
  2529.                 g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED
  2530.  
  2531.             case 3 ' 2 pass bitrate based VBR
  2532.                 g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_BITRATE_BASED
  2533.                 g_objVideoSource.PreProcessPass = 1
  2534.  
  2535.             case 4 ' 2 pass bitrate-based peak constrained VBR
  2536.                 g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK            
  2537.                 g_objVideoSource.PreProcessPass = 1
  2538.  
  2539.             case else
  2540.                 OutputInfo "Invalid -v_mode <mode_number>"
  2541.                 SetupCustomVideoProfile = false
  2542.                 exit function
  2543.  
  2544.         end select
  2545.     end if
  2546.  
  2547.     ' Set video codec
  2548.     if g_strVideoCodec <> "" then
  2549.         intVideoCodecIndex = GetVideoCodecIndex(g_strVideoCodec)
  2550.         intFourCC = g_objProfile.EnumVideoCodec(intVideoCodecIndex, g_strVideoCodecName)
  2551.  
  2552.         objAudience.VideoCodec(0) = intVideoCodecIndex
  2553.     end if
  2554.  
  2555.     if g_intVideoBitrate <> -1 then
  2556.         objAudience.VideoBitrate(0) = g_intVideoBitrate
  2557.     end if
  2558.  
  2559.     if g_intVideoWidth <> -1 then
  2560.         objAudience.VideoWidth(0) = g_intVideoWidth
  2561.     end if
  2562.  
  2563.     if g_intVideoHeight <> -1 then
  2564.         objAudience.VideoHeight(0) = g_intVideoHeight
  2565.     end if
  2566.  
  2567.     if g_intVideoFramerate <> -1 then
  2568.         objAudience.VideoFPS(0) = g_intVideoFramerate
  2569.     end if
  2570.  
  2571.     if g_intVideoKeydist <> -1 then
  2572.         objAudience.VideoKeyFrameDistance(0) = g_intVideoKeydist
  2573.     end if
  2574.  
  2575.     if g_intVideoBuffer <> -1 then
  2576.         objAudience.VideoBufferSize(0) = g_intVideoBuffer
  2577.     end if
  2578.  
  2579.     ' For quality vbr mode use intSmoothness as VBR quality
  2580.     if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_UNCONSTRAINED then
  2581.         if g_intVideoQuality <> -1 then
  2582.             objAudience.VideoCompressionQuality(0) = g_intVideoQuality
  2583.         end if
  2584.     else
  2585.         if g_intVideoQuality <> -1 then
  2586.             objAudience.VideoImageSharpness(0) = g_intVideoQuality
  2587.         end if
  2588.     end if
  2589.  
  2590.     ' For peak vbr mode set peakbitrate and peak buffer
  2591.     if g_objProfile.VBRMode(WMENC_VIDEO, 0) = WMENC_PVM_PEAK then
  2592.         if g_intVideoPeakBuffer <> -1 then
  2593.             objAudience.VideoBufferMax(0) = g_intVideoPeakBuffer
  2594.         end if
  2595.  
  2596.         if g_intVideoPeakBitrate <> -1 then
  2597.             if objAudience.VideoBitrate(0) > g_intVideoPeakBitrate then
  2598.                 objAudience.VideoBitrate(0) = g_intVideoPeakBitrate
  2599.             end if
  2600.             objAudience.VideoPeakBitrate(0) = g_intVideoPeakBitrate
  2601.         end if
  2602.     end if
  2603.  
  2604.     ' Setup video device conformance
  2605.     if g_strVideoDevConf <> "" then
  2606.         objAudience.Property( WMENC_VIDEO, 0, "DeviceConformanceTarget") = g_strVideoDevConf
  2607.     end if
  2608.  
  2609.     SetupCustomVideoProfile = true
  2610. end function
  2611.  
  2612. ' Load the default profile settings
  2613. function LoadProfileDefaults()
  2614.     dim argsArray
  2615.  
  2616.     ' Audio profile settings
  2617.     ' Set default codec and/or VBR mode when appropriate
  2618.     if g_strAudioSetting <> "" then
  2619.         if left(g_strAudioSetting, 1) = "Q" then
  2620.             g_intAudioVBRMode = 2
  2621.         end if
  2622.  
  2623.         argsArray = Split ( g_strAudioSetting, "_" )
  2624.         if UBound( argsArray ) = 3 and left(g_strAudioSetting, 4) <> "Q100" then
  2625.             g_strAudioCodec = WMA9PRO
  2626.         end if
  2627.     end if
  2628.  
  2629.     if g_intAudioVBRMode = -1 then
  2630.         g_intAudioVBRMode = 0
  2631.     end if
  2632.  
  2633.     if g_strAudioCodec = "" then
  2634.         g_strAudioCodec = "WMA9STD"
  2635.     end if
  2636.  
  2637.     if g_intAudioPeakBuffer = -1 then
  2638.         g_intAudioPeakBuffer = 3000
  2639.     end if
  2640.  
  2641.     ' Set default -a_setting based on format and mode
  2642.     if g_strAudioSetting = "" then
  2643.         if g_intAudioVBRMode = 2 and g_strAudioCodec = WMA9PRO then
  2644.             g_strAudioSetting = "Q75_44_2_24"
  2645.         elseif g_intAudioVBRMode = 2 and g_strAudioCodec = WMA9LSL then
  2646.             g_strAudioSetting = "Q100_44_2_16"
  2647.         elseif g_intAudioVBRMode = 2 then
  2648.             g_strAudioSetting = "Q75_44_2"
  2649.         elseif g_intAudioVBRMode = 0 and g_strAudioCodec = WMSPEECH then
  2650.             g_strAudioSetting = "12_16_1"
  2651.         elseif g_intAudioVBRMode = 0 and g_strAudioCodec = PCM then
  2652.             g_strAudioSetting = "705_22_2"
  2653.         elseif g_strAudioCodec = WMA9PRO then
  2654.             g_strAudioSetting = "128_44_2_24"
  2655.         else
  2656.             g_strAudioSetting = "64_44_2"
  2657.         end if
  2658.     end if
  2659.  
  2660.  
  2661.     ' Video profile settings
  2662.     if g_intVideoVBRMode = -1 then
  2663.         g_intVideoVBRMode = 0
  2664.     end if
  2665.  
  2666.     if g_strVideoCodec = "" then
  2667.         g_strVideoCodec = "WMV9"
  2668.     end if
  2669.  
  2670.     if g_intVideoBitrate = -1 then
  2671.         g_intVideoBitrate = 250000
  2672.     end if
  2673.  
  2674.     if g_intVideoWidth = -1 then
  2675.         g_intVideoWidth = 0
  2676.     end if
  2677.  
  2678.     if g_intVideoHeight = -1 then
  2679.         g_intVideoHeight = 0
  2680.     end if
  2681.  
  2682.     if g_intVideoFramerate = -1 then
  2683.         g_intVideoFramerate = 30000
  2684.     end if
  2685.  
  2686.     if g_intVideoKeydist = -1 then
  2687.         g_intVideoKeydist = 10000
  2688.     end if
  2689.  
  2690.     if g_intVideoBuffer = -1 then 
  2691.         g_intVideoBuffer = 3000
  2692.     end if
  2693.  
  2694.     if g_intVideoPeakBuffer = -1 then
  2695.         g_intVideoPeakBuffer = 3000
  2696.     end if
  2697.  
  2698.  
  2699.     if g_intVideoPeakBitrate = -1 then
  2700.         g_intVideoPeakBitrate = 1.5 * g_intVideoBitrate
  2701.     end if
  2702.  
  2703.     if g_intVideoQuality = -1 then
  2704.         if g_intVideoVBRMode = 2 then
  2705.             g_intVideoQuality = 85
  2706.         else
  2707.             g_intVideoQuality = 75
  2708.         end if
  2709.     end if
  2710. end function
  2711.  
  2712. ' Setup time configuration
  2713. function SetupTime()
  2714.     if g_blnDevice then
  2715.         ' Duration must be specified when capture from a live device.
  2716.         if g_intDuration = -1 then
  2717.             OutputInfo "Duration must be specified when capturing from devices."
  2718.             SetupTime = false
  2719.             exit function
  2720.         end if
  2721.     end if
  2722.  
  2723.     ' Setup markin and markout
  2724.     if g_intMarkInTime <> -1 then
  2725.         
  2726.         ' Set start time for audio source (mark in) if it has a audio stream.
  2727.         if not IsNull(g_objAudioSource) then
  2728.             g_objAudioSource.MarkIn = g_intMarkInTime
  2729.         end if
  2730.     
  2731.         ' Set start time for video source (mark in) if it has a video stream.
  2732.         if not IsNull(g_objVideoSource) then
  2733.             g_objVideoSource.MarkIn = g_intMarkInTime
  2734.         end if
  2735.     end if
  2736.  
  2737.     ' Is a mark out time provided?
  2738.     if g_intMarkOutTime <> -1 then
  2739.         
  2740.         ' Set end time for audio source (mark out) if it has a audio stream.
  2741.         if not IsNull(g_objAudioSource) then
  2742.             g_objAudioSource.MarkOut = g_intMarkOutTime
  2743.         end if
  2744.         
  2745.         ' Set end time for video source (mark out) if it has a video stream.
  2746.         if not IsNull(g_objVideoSource) then
  2747.             g_objVideoSource.MarkOut = g_intMarkOutTime
  2748.         end if
  2749.     end if
  2750.  
  2751.     SetupTime = true
  2752. end function
  2753.  
  2754. ' Transcode 
  2755. function Transcode()
  2756.     on error resume next
  2757.     
  2758.     ' Prepare to encode
  2759.     g_objEncoder.PrepareToEncode( true )
  2760.  
  2761.     ' Check if we got an error saying markout is greater that end of file. If so set markout to end of file
  2762.     if err.number = -1072882855 then
  2763.         err.Clear
  2764.  
  2765.         if not IsNull(g_objAudioSource) then
  2766.             g_objAudioSource.MarkOut = 0
  2767.         end if
  2768.         
  2769.         if not IsNull(g_objVideoSource) then
  2770.             g_objVideoSource.MarkOut = 0
  2771.         end if
  2772.  
  2773.         g_objEncoder.PrepareToEncode( true )
  2774.     elseif err.number <> 0 then
  2775.         Transcode = false
  2776.         OutputInfo "Prepare to encode failed with error " & err.Number & " " & err.Description
  2777.         exit function
  2778.     end if
  2779.  
  2780.     ' Start encoder
  2781.     g_objEncoder.Start()
  2782.     if err.number <> 0 then
  2783.         Transcode = false
  2784.         OutputInfo "Start encoder failed with error " & err.Number & " " & err.Description
  2785.         exit function
  2786.     end if
  2787.  
  2788.     g_tStartTime = Now()
  2789.     
  2790.     ' Wait for start event
  2791.     while not g_blnEncoderStarted and g_intErrorCode = 0
  2792.         WScript.Sleep( 1000 )
  2793.     wend
  2794.  
  2795.     on error goto 0
  2796.     
  2797.     if g_intDuration >= 0 then
  2798.         ' Wait for time
  2799.         OutputInfo "Wait for " & g_intDuration & " seconds to stop encoder..."
  2800.  
  2801.         dim t1, t2
  2802.         
  2803.         t1 = Now()
  2804.  
  2805.         ' Wait until an error code is received
  2806.         do while g_intErrorCode = 0
  2807.             WScript.Sleep( 1000 )
  2808.  
  2809.             t2 = Now()
  2810.  
  2811.             if DateDiff( "s", t1, t2 ) >= g_intDuration then
  2812.                 OutputInfo "Duration time is reached. Stop encoder..."
  2813.                 g_objEncoder.Stop()
  2814.                 exit do
  2815.             end if
  2816.  
  2817.             if g_objEncoder.RunState = WMENC_ENCODER_STOPPED then
  2818.                 OutputInfo "Encoding completed before duration time is reached."
  2819.                 exit do
  2820.             end if
  2821.         loop
  2822.     else
  2823.         ShowProgress
  2824.     end if
  2825.  
  2826.     while not g_blnEncoderStopped and g_intErrorCode = 0
  2827.         WScript.Sleep( 1000 )
  2828.     wend
  2829.  
  2830.     ' Check error event
  2831.     if g_intErrorCode = 0 then
  2832.         OutputInfo "======== Encoding Completed ========"
  2833.         Transcode = true
  2834.     else
  2835.         OutputInfo "Error occurred in transcoding: Error Code =" & g_intErrorCode
  2836.         Transcode = false
  2837.     end if
  2838.  
  2839. end function
  2840.  
  2841. ' Show statistics information of output
  2842. function ShowStatistics()
  2843.     dim objProfile
  2844.  
  2845.     ' Output statistics for audio stream
  2846.     if not IsNull(g_objAudioSource) then
  2847.         dim objAudioStats
  2848.         
  2849.         set objAudioStats = g_objEncoder.Statistics.StreamOutputStats( WMENC_AUDIO, 0, 0 )
  2850.  
  2851.         OutputInfo ""
  2852.         OutputInfo "Audio :"
  2853.         OutputInfo vbTab & "Codec: " & g_strAudioCodecName
  2854.         OutputInfo vbTab & "Expected bit rate: " & vbTab & objAudioStats.ExpectedBitrate & " bps"
  2855.         OutputInfo vbTab & "Average bit rate: " & vbTab & objAudioStats.AverageBitrate & " bps"
  2856.         OutputInfo vbTab & "Expected sample rate: " & vbTab & objAudioStats.ExpectedSampleRate
  2857.         OutputInfo vbTab & "Average sample rate: " & vbTab & objAudioStats.AverageSampleRate & ""
  2858.         OutputInfo vbTab & "Dropped byte count: " & vbTab & objAudioStats.DroppedByteCount*10000 & " bytes"
  2859.         OutputInfo vbTab & "Dropped sample rate: " & vbTab & objAudioStats.DroppedSampleCount*10000 & ""
  2860.         OutputInfo vbTab & "Total bytes: " & vbTab & vbTab & objAudioStats.ByteCount*10000 & " bytes"
  2861.     end if
  2862.  
  2863.     if not IsNull(g_objVideoSource) then
  2864.         dim objVideoStats
  2865.         
  2866.         set objVideoStats = g_objEncoder.Statistics.StreamOutputStats( WMENC_VIDEO, 0, 0 )
  2867.  
  2868.         OutputInfo ""
  2869.         OutputInfo "Video :"
  2870.         OutputInfo vbTab & "Codec: " & g_strVideoCodecName
  2871.         if g_intVideoVBRMode <> 2 then
  2872.             OutputInfo vbTab & "Expected bit rate: " & vbTab & objVideoStats.ExpectedBitrate & " bps"
  2873.         end if
  2874.         OutputInfo vbTab & "Average bit rate: " & vbTab & objVideoStats.AverageBitrate & " bps"
  2875.         OutputInfo vbTab & "Expected fps: " & vbTab & vbTab & objVideoStats.ExpectedSampleRate / 1000
  2876.         OutputInfo vbTab & "Dropped frame count: " & vbTab & objVideoStats.DroppedSampleCount*10000 & ""
  2877.         OutputInfo vbTab & "Total coded frames: " & vbTab & objVideoStats.SampleCount*10000 & ""
  2878.         OutputInfo vbTab & "Average sample rate: " & vbTab & objVideoStats.AverageSampleRate / 1000 & ""
  2879.         OutputInfo vbTab & "Dropped bytes: " & vbTab & vbTab & objVideoStats.DroppedByteCount*10000 & " bytes"
  2880.         OutputInfo vbTab & "Total bytes: " & vbTab & vbTab & objVideoStats.ByteCount*10000 & " bytes"
  2881.     end if
  2882.  
  2883.     ' Output statistics information of output stream
  2884.     OutputInfo ""
  2885.     OutputInfo "Overall:"
  2886.     OutputInfo vbTab & "Encoding time: " & vbTab & vbTab & DateDiff( "s", g_tStartTime, g_tStopTime ) & " seconds"
  2887.     OutputInfo vbTab & "Average bit rate: " & vbTab & g_objEncoder.Statistics.WMFOutputStats.AverageBitrate & " bps"
  2888.     
  2889.     if g_strOutput <> "" then
  2890.         dim objFileStats
  2891.         
  2892.         set objFileStats = g_objEncoder.Statistics.FileArchiveStats
  2893.     
  2894.         OutputInfo vbTab & "File size: " & vbTab & vbTab & objFileStats.FileSize*10000 & " bytes "
  2895.         OutputInfo vbTab & "File duration: " & vbTab & vbTab & objFileStats.FileDuration*10 & " seconds "
  2896.     end if
  2897.  
  2898. end function
  2899.  
  2900. ' Setup input configuration
  2901. function SetupInput()
  2902.     dim strDeviceName
  2903.  
  2904.     ' The input file name is used if it is not empty, otherwise device index is used.
  2905.     if g_strInput <> "" then
  2906.         dim strInput2
  2907.         
  2908.         strInput2 = g_objFileSystem.GetAbsolutePathName( g_strInput )
  2909.  
  2910.         on error resume next
  2911.  
  2912.         if g_strProfile <> "" then
  2913.             dim strProfileName
  2914.  
  2915.             strProfileName = LCase( g_strProfile )
  2916.             if Left( strProfileName, 1) = "a" and Mid( strProfileName, 2, 1 ) <> "v"  then
  2917.                  g_blnAudioOnly = true
  2918.             elseif Left( strProfileName, 1) = "v" then
  2919.                 g_blnVideoOnly = true
  2920.             end if
  2921.         end if
  2922.  
  2923.         ' Add this file into the source group.
  2924.         if g_blnAudioOnly then
  2925.             set g_objAudioSource = g_objSourceGroup.AddSource( WMENC_AUDIO )
  2926.             g_objAudioSource.SetInput( g_strInput )
  2927.         elseif g_blnVideoOnly then
  2928.             set g_objVideoSource = g_objSourceGroup.AddSource( WMENC_VIDEO )
  2929.             g_objVideoSource.SetInput( g_strInput )
  2930.         else
  2931.             g_objSourceGroup.AutoSetFileSource( strInput2 )
  2932.  
  2933.             ' If source file has an auido stream, get the audio source.
  2934.             if g_objSourceGroup.SourceCount( WMENC_AUDIO ) > 0 then
  2935.                 set g_objAudioSource = g_objSourceGroup.Source( WMENC_AUDIO, 0 )
  2936.             end if
  2937.  
  2938.             ' If source file has a video stream, get the video source.
  2939.             if g_objSourceGroup.SourceCount( WMENC_VIDEO ) > 0 then
  2940.                 set g_objVideoSource = g_objSourceGroup.Source( WMENC_VIDEO, 0 )
  2941.             end if
  2942.  
  2943.         end if
  2944.     elseif g_intAudioDevice <> -1 or g_intVideoDevice <> -1 then
  2945.         if g_intAudioDevice <> -1 then
  2946.             strDeviceName = GetDeviceNameFromIndex( WMENC_AUDIO, g_intAudioDevice )
  2947.             if strDeviceName = "" then
  2948.                 OutputInfo "Error: Invalid audio device number specified" 
  2949.                 SetupInput = false
  2950.                 exit function
  2951.             end if
  2952.             set g_objAudioSource = g_objSourceGroup.AddSource( WMENC_AUDIO )
  2953.             g_objAudioSource.SetInput strDeviceName, "device"
  2954.         end if
  2955.  
  2956.         if g_intVideoDevice <> -1 then
  2957.             strDeviceName = GetDeviceNameFromIndex( WMENC_VIDEO, g_intVideoDevice )
  2958.             if strDeviceName = "" then
  2959.                 OutputInfo "Error: Invalid video device number specified" 
  2960.                 SetupInput = false
  2961.                 exit function
  2962.             end if
  2963.             
  2964.             set g_objVideoSource = g_objSourceGroup.AddSource( WMENC_VIDEO )
  2965.             g_objVideoSource.SetInput strDeviceName, "device"
  2966.         end if
  2967.         
  2968.     end if
  2969.  
  2970.     if g_objSourceGroup.SourceCount( WMENC_AUDIO ) and g_objSourceGroup.SourceCount( WMENC_VIDEO ) then
  2971.         g_intSessionType = WMENC_CONTENT_ONE_AUDIO_ONE_VIDEO
  2972.     elseif g_objSourceGroup.SourceCount( WMENC_AUDIO ) then
  2973.         g_intSessionType = WMENC_CONTENT_ONE_AUDIO
  2974.     elseif g_objSourceGroup.SourceCount( WMENC_VIDEO ) then
  2975.         g_intSessionType = WMENC_CONTENT_ONE_VIDEO
  2976.     end if
  2977.  
  2978.     ' Set audio setting for speech
  2979.     if not IsNull(g_objAudioSource) then
  2980.         SetupAudioSource()
  2981.     end if
  2982.  
  2983.     ' Set video settings
  2984.     if not IsNull(g_objVideoSource) then
  2985.         SetupVideoSource()
  2986.     end if
  2987.    
  2988.     if err.number <> 0 then
  2989.         OutputInfo "Media Source Invalid: " & err.number
  2990.         err.Clear
  2991.         SetupInput = false
  2992.         exit function
  2993.     end if
  2994.  
  2995.     SetupInput = true
  2996. end function
  2997.  
  2998. 'Set speech related settings on audio source
  2999. function SetupAudioSource()
  3000.     if g_intAudioSpeechContent <> -1 then
  3001.         g_objAudioSource.contentmode = g_intAudioSpeechContent
  3002.     end if
  3003.     if g_strAudioSpeechEdl <> "" then
  3004.         g_objAudioSource.contentedl = g_strAudioSpeechEdl
  3005.     end if
  3006. end function
  3007.  
  3008. 'Set settings on video source
  3009. function SetupVideoSource()
  3010.     ' Set video preprocess
  3011.     select case g_intVideoPreprocess
  3012.         case 0 
  3013.             g_objVideoSource.Optimization = WMENC_VIDEO_STANDARD
  3014.         case 1
  3015.             g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE
  3016.         case 2
  3017.             g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE
  3018.             OutputInfo "Preprocessing mode not supported. Use -height and -width to adjust video size."
  3019.         case 3
  3020.             g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE
  3021.             OutputInfo "Preprocessing mode not supported. Use -height and -width to adjust video size."
  3022.         case 4
  3023.             g_objVideoSource.Optimization = WMENC_VIDEO_DEINTERLACE
  3024.             OutputInfo "Preprocessing mode not supported. Use -height and -width to adjust video size."
  3025.         case 5
  3026.             g_objVideoSource.Optimization = WMENC_VIDEO_INVERSETELECINE
  3027.         case 6
  3028.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_AA_TOP
  3029.         case 7
  3030.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BB_TOP
  3031.         case 8
  3032.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BC_TOP
  3033.         case 9
  3034.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_CD_TOP
  3035.         case 10
  3036.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_DD_TOP
  3037.         case 11
  3038.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_AA_BOTTOM
  3039.         case 12
  3040.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BB_BOTTOM
  3041.         case 13
  3042.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_BC_BOTTOM
  3043.         case 14
  3044.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_CD_BOTTOM
  3045.         case 15
  3046.             g_objVideoSource.Optimization = WMENC_VIDEO_TELECINE_DD_BOTTOM
  3047.         case 16
  3048.             g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_AUTO
  3049.         case 17
  3050.             g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_TOP_FIRST
  3051.         case 18
  3052.             g_objVideoSource.Optimization = WMENC_VIDEO_INTERLACED_BOTTOM_FIRST
  3053.     end select
  3054.  
  3055.     'Set pixelformat
  3056.     select case ucase( g_strPixelFormat )
  3057.         case "I420"
  3058.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_I420
  3059.         case "IYUV"
  3060.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_IYUV
  3061.         case "RGB 24"
  3062.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB24
  3063.         case "RGB 32"
  3064.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB32 
  3065.         case "RGB 555"
  3066.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB555 
  3067.         case "RGB 565"
  3068.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB565
  3069.         case "RGB 8"
  3070.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_RGB8
  3071.         case "UYVY"
  3072.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_UYVY
  3073.         case "YUY2"
  3074.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YUY2
  3075.         case "YV12"
  3076.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YV12 
  3077.         case "YVU9"
  3078.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YVU9 
  3079.         case "YVYU"
  3080.             g_objVideoSource.PixelFormat = WMENC_PIXELFORMAT_YVYU 
  3081.     end select
  3082.  
  3083.     'Set pixel aspect ratio
  3084.     g_objVideoSource.PixelAspectRatioX = g_intPixelAspectRatioX
  3085.     g_objVideoSource.PixelAspectRatioY = g_intPixelAspectRatioY
  3086.  
  3087.  
  3088.     'Set performance
  3089.     g_objEncoder.VideoComplexity = g_intVideoPerformance
  3090.  
  3091.     'Set clipping margins
  3092.     g_objVideoSource.CroppingLeftMargin   = g_intClipLeft
  3093.     g_objVideoSource.CroppingRightMargin  = g_intClipRight
  3094.     g_objVideoSource.CroppingTopMargin    = g_intClipTop
  3095.     g_objVideoSource.CroppingBottomMargin = g_intClipBottom
  3096.  
  3097. end function
  3098.  
  3099. 'This function is used to check if the bit rate specified for the a_setting param is valid
  3100. function CheckForValidAudioBitRates( intBitRate )
  3101.  
  3102.     select case intBitRate
  3103.  
  3104.         case 1411200,768000,705600,640000,440000,384000,352800,320000,256000,192000,160000,128000,96000,80000,_
  3105.              64000,48000,40000,32000,22000,20000,17000,16000,12000,10000,8000,6000,5000,4000,0
  3106.             CheckForValidAudioBitRates = True
  3107.  
  3108.         case else
  3109.             CheckForValidAudioBitRates = False
  3110.  
  3111.     end select
  3112. end function
  3113.  
  3114. 'This function is used to check if the sampling rate specified for the a_setting param is valid
  3115. function CheckForValidAudioSamplingRates( intSamplingRate )
  3116.  
  3117.     select case intSamplingRate
  3118.  
  3119.         case 96000,88200,48000,44100,32000,22050,16000,11025,8000
  3120.             CheckForValidAudioSamplingRates = True
  3121.  
  3122.         case else
  3123.             CheckForValidAudioSamplingRates = False
  3124.  
  3125.     end select
  3126. end function
  3127.  
  3128. 'This function is used to check if the channel specified for the a_setting param is valid
  3129. function CheckForValidAudioChannel( intChannel )
  3130.  
  3131.     select case intChannel
  3132.  
  3133.         case 1,2,6,8
  3134.             CheckForValidAudioChannel = True
  3135.  
  3136.         case else
  3137.             CheckForValidAudioChannel = False
  3138.  
  3139.    end select
  3140. end function
  3141.  
  3142. 'This function is used to check if the depth specified for the a_setting param is valid
  3143. function CheckForValidDepth( intAudioDepth )
  3144.  
  3145.     select Case intAudioDepth
  3146.  
  3147.         case 16,20,24
  3148.             CheckForValidDepth = True 
  3149.  
  3150.         case else
  3151.             CheckForValidDepth = False
  3152.  
  3153.    end select 
  3154. end function
  3155.  
  3156. 'This function is the top level function for directory based encoding
  3157. function DoDirectoryModeEncoding()
  3158.     dim strInputFull
  3159.     dim strOutputFull
  3160.  
  3161.     if g_strOutput = "" then
  3162.         OutputInfo "Error: No output directory specified" 
  3163.         DoDirectoryModeEncoding = false
  3164.         exit function
  3165.     end if
  3166.  
  3167.     strInputFull = g_objFileSystem.GetAbsolutePathName(g_strInput)
  3168.     strOutputFull = g_objFileSystem.GetAbsolutePathName(g_strOutput)
  3169.  
  3170.     EncodeFilesInFolder strInputFull, strOutputFull
  3171.  
  3172. end function
  3173.  
  3174. 'This function will create all folders down to the strFolderName level
  3175. function CreateOutputFolder( strFolderName )
  3176.     if g_objFileSystem.FolderExists(strFolderName) = false then
  3177.         CreateOutputFolder( g_objFileSystem.GetParentFolderName( strFolderName ) )
  3178.         g_objFileSystem.CreateFolder( strFolderName )
  3179.         end if
  3180. end function
  3181.  
  3182. 'This function will encode all files in the input directory and generate output files in output directory
  3183. function EncodeFilesInFolder( strInputFolderName, strOutputFolderName )
  3184.     dim objSubFoldersCollection
  3185.     dim objInputSubFolder
  3186.     dim strOutputSubFolderName, strFileType
  3187.     dim objFile, objFolder, objFileCollection
  3188.  
  3189.     OutputInfo "============== Encoding Files in Folder ============== " & strInputFolderName
  3190.  
  3191.     set objFolder = g_objFileSystem.GetFolder( strInputFolderName )
  3192.     
  3193.     ' First encode all the files contained in the input folder
  3194.     set objFileCollection = objFolder.Files
  3195.  
  3196.     for each objFile in objFileCollection
  3197.  
  3198.         strFileType = right(objFile.name, len(objFile.name) - instrrev(objFile.name,".") )  
  3199.  
  3200.         select case lcase(strFileType)
  3201.             case "avi", "wav", "mpg", "mpeg", "vob" , "wmv" , "wma", "mp3", "asf"
  3202.                 g_strInput = strInputFolderName & "\" & objFile.name
  3203.                 g_strOutput = strOutputFolderName & "\" & Left(objFile.name, len(objFile.Name)-(len(objFile.name) - instrrev(objFile.name,".") + 1)) & g_strOutputString
  3204.             
  3205.                 OutputInfo "============== Input " & g_strInput & " " & g_strOutput
  3206.  
  3207.                 ' Encode files
  3208.                 if SetupEncoder() then
  3209.                     if Transcode() and not g_blnSilent then 
  3210.                         ShowStatistics()
  3211.                     end if 
  3212.                 end if
  3213.  
  3214.                 ' reset encoder states for next file 
  3215.                 g_objEncoder.PrepareToEncode( false )
  3216.                 g_objEncoder.SourceGroupCollection.Remove( "SG_1" )
  3217.                 g_objSourceGroup = Null
  3218.                 g_objAudioSource = Null
  3219.                 g_objVideoSource = Null
  3220.  
  3221.             case else
  3222.                 OutputInfo "Skipping: " & objFile.name
  3223.         end select
  3224.     next
  3225.  
  3226.     ' Then recurse into subfolders and encode all files there
  3227.     set objSubFoldersCollection = objFolder.SubFolders
  3228.  
  3229.     for each objInputSubFolder in objSubFoldersCollection
  3230.         strOutputSubFolderName = strOutputFolderName & "\" & objInputSubFolder.name
  3231.  
  3232.         EncodeFilesInFolder objInputSubFolder, strOutputSubFolderName
  3233.     Next
  3234.  
  3235. end function
  3236.  
  3237. ' Get device name from index
  3238. function GetDeviceNameFromIndex(enumMediaType, intDeviceIndex)
  3239.     dim intLastDevice
  3240.     dim objSourceInfo, objSourcePluginManager
  3241.  
  3242.     intLastDevice = 0
  3243.     set objSourcePlugInManager = g_objEncoder.SourcePlugInInfoManager
  3244.  
  3245.     for i = 0 to objSourcePlugInManager.count -1
  3246.         set objSourceInfo = objSourcePlugInManager(i)
  3247.         
  3248.         if enumMediaType = WMENC_AUDIO then ' Audio
  3249.             ' For audio search audio and audio | video
  3250.             if objSourceInfo.MediaType = 1 or objSourceInfo.MediaType = 3 then
  3251.                 if intDeviceIndex < intLastDevice + objSourceInfo.Count then
  3252.                     GetDeviceNameFromIndex = objSourceInfo( intDeviceIndex - intLastDevice )
  3253.                     exit function
  3254.                 else 
  3255.                     intLastDevice = intLastDevice + objSourceInfo.Count
  3256.                 end if
  3257.             end if
  3258.         else ' Video
  3259.             ' For video search video, audio | video and video | script
  3260.             if objSourceInfo.MediaType = 2 or objSourceInfo.MediaType = 3 or objSourceInfo.MediaType = 6 then
  3261.                 if intDeviceIndex < intLastDevice + objSourceInfo.Count Then
  3262.                     GetDeviceNameFromIndex = objSourceInfo( intDeviceIndex - intLastDevice )
  3263.                     exit function
  3264.                 else 
  3265.                     intLastDevice = intLastDevice + objSourceInfo.Count
  3266.                 end if
  3267.             end if
  3268.         end if
  3269.     next
  3270.  
  3271.     GetDeviceNameFromIndex = ""
  3272.  
  3273. end function
  3274.  
  3275. function ShowProgress()
  3276.     dim intSleepDuration, intPercent, intADuration, intVDuration, intDuration
  3277.     dim intPasses, intLimit
  3278.  
  3279.     intPasses = 1
  3280.  
  3281.     ' Compute number of passes required
  3282.     if not IsNull(g_objAudioSource) then
  3283.         if g_objAudioSource.PreProcessPass = 1 then
  3284.             intPasses = 2
  3285.         end if
  3286.     end if
  3287.  
  3288.     if not IsNull(g_objVideoSource) then
  3289.         if g_objVideoSource.PreProcessPass = 1 then
  3290.             intPasses = 2
  3291.         end if
  3292.     end if
  3293.  
  3294.     ' Compute file duration
  3295.     if not IsNull(g_objAudioSource) then
  3296.         if g_objAudioSource.MarkOut <> 0 then
  3297.             intADuration = g_objAudioSource.MarkOut - g_objAudioSource.MarkIn
  3298.         else
  3299.             intADuration = g_objAudioSource.Duration - g_objAudioSource.MarkIn
  3300.         end if
  3301.     end if
  3302.     if not IsNull(g_objVideoSource) then
  3303.         if g_objVideoSource.MarkOut <> 0 then
  3304.             intVDuration = g_objVideoSource.MarkOut - g_objVideoSource.MarkIn
  3305.         else
  3306.             intVDuration = g_objVideoSource.Duration - g_objVideoSource.MarkIn
  3307.         end if
  3308.     end if
  3309.  
  3310.     if intADuration > intVDuration then
  3311.         intDuration = intADuration
  3312.     else
  3313.         intDuration = intVDuration
  3314.     end if
  3315.  
  3316.     intSleepDuration = 2000
  3317.     
  3318.     ' For all passes show progress from 0 to 100
  3319.     for j=0 to intPasses-1
  3320.         intPercent = 0
  3321.  
  3322.         if intPasses = 2 and j = 0 then
  3323.             OutputInfo "======== Begin Pass1 ========"
  3324.         elseif intPasses = 2 and j = 1 then
  3325.             OutputInfo "======== Begin Pass2 ========"
  3326.         end if
  3327.     
  3328.         for i=1 to 4
  3329.             intLimit = 25 * i
  3330.             do while g_objEncoder.RunState <> WMENC_ENCODER_STOPPED and g_intErrorCode = 0 and intPercent < intLimit
  3331.                 WScript.stdout.Write "."
  3332.                 WScript.Sleep intSleepDuration
  3333.                 if intDuration <> 0 then
  3334.                     intPercent = CInt( g_objEncoder.Statistics.EncodingTime * 1000000 / intDuration )
  3335.                 end if
  3336.                 if intPasses = 2 and j = 0 and intLimit = 100 and intPercent < 75 then
  3337.                     ' second pass has already started
  3338.                     exit Do
  3339.                 end if
  3340.             loop
  3341.         
  3342.             ' Only show progress if we know the duration of source files
  3343.             if intDuration <> 0 then
  3344.                 WScript.stdout.Write intLimit &"%."
  3345.             end if
  3346.         next
  3347.         OutputInfo ""
  3348.     next
  3349.  
  3350. end function
  3351.