home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 November / Chip_2002-11_cd1.bin / zkuste / vbasic / Data / Utils / WME71SDK.exe / RCDATA / CABINET / towm_encoder.cls < prev    next >
Text File  |  2001-03-02  |  6KB  |  249 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "TOWM_ENCODER"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Dim WithEvents Encoder As WMEncoder
  16. Attribute Encoder.VB_VarHelpID = -1
  17. Dim EncRunning As Boolean
  18. Function GetCommandArgs(InCommand As String, InputFile As String, OutputFile As String, ProfileName As String) As Boolean
  19.   Dim i As Integer
  20.   Dim Arg As String
  21.   Dim Err As Boolean
  22.  
  23.   ' Initialize variables
  24.  
  25.   i = 1
  26.   Err = False
  27.   
  28.   ' Loop through all arguments
  29.  
  30.   Do While True
  31.   
  32.     ' Get next argument
  33.     
  34.     Arg = GetArgument(InCommand, i)
  35.     
  36.     ' Process the argument (and any argument following switch)
  37.     
  38.     If LCase(Arg) = "-in" Then
  39.       i = i + 1
  40.       InputFile = GetArgument(InCommand, i)
  41.     ElseIf LCase(Arg) = "-out" Then
  42.       i = i + 1
  43.       OutputFile = GetArgument(InCommand, i)
  44.     ElseIf LCase(Arg) = "-p" Then
  45.       i = i + 1
  46.       ProfileName = GetArgument(InCommand, i)
  47.     ElseIf Arg = "" Then
  48.       Exit Do
  49.     Else
  50.       Err = True
  51.       Exit Do
  52.     End If
  53.   
  54.     ' Point to next argument
  55.   
  56.     i = i + 1
  57.   Loop
  58.  
  59.   ' Check for argument errors
  60.  
  61.   If InputFile = "" Then Err = True
  62.   If ProfileName = "" Then Err = True
  63.   
  64.   ' Set up our return value
  65.   
  66.   GetCommandArgs = Not Err
  67.  
  68. End Function
  69. Function GetArgument(InCommand As String, Index As Integer) As String
  70.   Dim ArgStart As Integer
  71.   Dim ArgEnd As Integer
  72.   Dim InArg As Boolean
  73.   Dim InQuotes As Boolean
  74.   Dim i As Integer
  75.   Dim CurrentIndex As Integer
  76.   Dim Argument As String
  77.  
  78.   ' Initialize variables
  79.   
  80.   ArgStart = 1
  81.   ArgEnd = 0
  82.   InArg = False
  83.   InQuotes = False
  84.   i = 1
  85.   CurrentIndex = 0
  86.  
  87.   ' Loop through command string to find start and end of Index-th argument
  88.  
  89.   While i <= Len(InCommand)
  90.   
  91.     ' Check for start of argument
  92.     
  93.     If Mid(InCommand, i, 1) <> " " And Not InArg Then
  94.       If Mid(InCommand, i, 1) = """" Then InQuotes = True
  95.       InArg = True
  96.       CurrentIndex = CurrentIndex + 1
  97.       If CurrentIndex = Index Then
  98.         ArgStart = i
  99.       End If
  100.       
  101.     ' Check for end of argument
  102.       
  103.     ElseIf (Mid(InCommand, i, 1) = " " Or Mid(InCommand, i, 1) = """") And InArg And Not InQuotes Then
  104.       InQuotes = False
  105.       InArg = False
  106.       If CurrentIndex = Index Then
  107.         ArgEnd = i - 1
  108.       End If
  109.     End If
  110.   
  111.     ' Point to next character
  112.   
  113.     i = i + 1
  114.     
  115.   Wend
  116.  
  117.   ' Check if last argument was in quotes and not terminated correctly
  118.  
  119.   If InArg And CurrentIndex = Index Then
  120.     ArgEnd = Len(InCommand)
  121.   End If
  122.  
  123.   ' Strip argument out of command string
  124.  
  125.   Argument = Mid(InCommand, ArgStart, ArgEnd - ArgStart + 1)
  126.  
  127.   ' Strip off quotes, if necessary
  128.  
  129.   If Left(Argument, 1) = """" Then Argument = Right(Argument, Len(Argument) - 1)
  130.   If Right(Argument, 1) = """" Then Argument = Left(Argument, Len(Argument) - 1)
  131.  
  132.   GetArgument = Argument
  133.   
  134. End Function
  135. Function ConfigEncoder(InputFile As String, OutputFile As String, ProfileName As String) As Boolean
  136.   Dim PeriodPos As Integer
  137.   Dim AudCnt As Integer
  138.   Dim VidCnt As Integer
  139.   Dim Success As Boolean
  140.  
  141.   Dim SrcGpCol As IWMEncSourceGroupCollection
  142.   Dim SrcGp As IWMEncSourceGroup
  143.   Dim Prf As IWMEncProfile
  144.  
  145.   On Error GoTo err_handler
  146.  
  147.   ' Create a new encoder
  148.  
  149.   Set Encoder = New WMEncoder
  150.   
  151.   ' Add a source group
  152.   
  153.   Set SrcGpCol = Encoder.SourceGroupCollection
  154.   Set SrcGp = SrcGpCol.Add("TOWM")
  155.  
  156.   ' Set the source group to our input file
  157.  
  158.   SrcGp.AutoSetFileSource (InputFile)
  159.  
  160.   ' Get the profile from the Profile Collection using its name
  161.  
  162.   Success = GetProfile(ProfileName, Encoder.ProfileCollection, Prf)
  163.   If Not Success Then GoTo err_handler
  164.  
  165.   ' Set the profile into the source group
  166.  
  167.   SrcGp.Profile = Prf
  168.  
  169.   ' If no output file specified, make it same as input file with correct extension
  170.  
  171.   If OutputFile = "" Then
  172.     OutputFile = InputFile
  173.     PeriodPos = InStrRev(InputFile, ".")
  174.     If PeriodPos > 0 Then OutputFile = Left(OutputFile, PeriodPos)
  175.         
  176.     AudCnt = SrcGp.SourceCount(WMENC_AUDIO)
  177.     VidCnt = SrcGp.SourceCount(WMENC_VIDEO)
  178.         
  179.     If AudCnt > 0 And VidCnt = 0 Then
  180.       OutputFile = OutputFile & ".wma"
  181.     Else
  182.       OutputFile = OutputFile & ".wmv"
  183.     End If
  184.   End If
  185.   
  186.   ' Set output file
  187.   
  188.   Encoder.File.LocalFileName = OutputFile
  189.   MsgBox "TOWM Starting Encoder To Create  " & OutputFile, vbInformation
  190.   
  191.   ConfigEncoder = True
  192.   Exit Function
  193.  
  194. err_handler:
  195.   ConfigEncoder = False
  196.  
  197. End Function
  198. Function GetProfile(ProfileName As String, PrfCol As IWMEncProfileCollection, Prf As IWMEncProfile) As Boolean
  199.   Dim Err As Boolean
  200.   On Error GoTo err_handler
  201.  
  202.   ' Initialize variable
  203.  
  204.   Err = True
  205.  
  206.   ' Run through the profile collection looking for a name that matches
  207.  
  208.   For Each Prf In PrfCol
  209.     If UCase(Prf.Name) = UCase(ProfileName) Then
  210.       Err = False
  211.       Exit For
  212.     End If
  213.   Next
  214.  
  215.   GetProfile = Not Err
  216.  
  217.   Exit Function
  218.  
  219. err_handler:
  220.   GetProfile = False
  221.  
  222. End Function
  223. Sub RunEncoder()
  224.  
  225.   ' Initialize variable
  226.  
  227.   EncRunning = True
  228.   
  229.   ' Start encoder
  230.   
  231.   Encoder.Start
  232.     
  233.   ' Spin our wheels while the encoder runs
  234.     
  235.   While EncRunning = True
  236.     DoEvents
  237.   Wend
  238.     
  239. End Sub
  240. Private Sub Encoder_OnStateChange(ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE)
  241.  
  242.   ' If the encoder has stopped flag RunEncoder to end
  243.  
  244.   If enumState = WMENC_ENCODER_STOPPED Then
  245.     EncRunning = False
  246.   End If
  247.   
  248. End Sub
  249.