Recompressing an AVI File Selection Example for Visual Basic

The following code demonstrates recompressing an AVI file selection:

Private Sub cmdAbort_Click()
    ' if running then abort, else exit program
    If ltmmConvertCtrl1.State = ltmmConvert_State_Running Then
        ltmmConvertCtrl1.StopConvert
    Else
' enable to dump current state
'        MsgBox "State = " & CStr(ltmmConvertCtrl1.State) & ", Error = " & CStr(ltmmConvertCtrl1.ConvertError) & ", Progress = " & CStr(ltmmConvertCtrl1.PercentComplete) & "%"
        Unload Me
    End If
End Sub

Private Sub convert_Complete ()
    ' indicate that the conversion has completed
    txtStatus = "Conversion completed."
    cmdAbort.Caption = "Exit"
End Sub

Private Sub convert_ErrorAbort (ByVal ErrorCode As Long)
    ' indicate that a conversion error has occurred

    txtStatus = "Error " & CStr(ErrorCode) & ". Conversion aborted."
    cmdAbort.Caption = "Exit"
End Sub

Private Sub convert_Progress (ByVal Percent As Long)

    ' update the percentage text
    txtProgress = CStr(Percent) & "%"
End Sub

Private Sub convert_Started ()
    ' indicate that the conversion has started
    Dim Source As String
    Dim Target As String

    If ltmmConvertCtrl1.SourceType = ltmmConvert_Source_File Then
        Source = ltmmConvertCtrl1.SourceFile
    ElseIf ltmmConvertCtrl1.SourceType = ltmmConvert_Source_Array Then
        Source = "[array]"
    ElseIf ltmmConvertCtrl1.SourceType = ltmmConvert_Source_HGlobal Then
        Source = "[hglobal]"
    End If

    If ltmmConvertCtrl1.TargetType = ltmmConvert_Target_File Then
        Target = ltmmConvertCtrl1.TargetFile
    ElseIf ltmmConvertCtrl1.TargetType = ltmmConvert_Target_Array Then
        Target = "[array]"
    End If

    txtStatus = "Recompressing " & Source & " to " & Target

End Sub

Private Sub convert_UserAbort ()
    ' indicate that the user aborted
    txtStatus = "Conversion Aborted."
    cmdAbort.Caption = "Exit"
End Sub

Private Sub Form_Load()
    ' assign the input file
    ltmmConvertCtrl1.SourceFile = "c:\source.avi"
    ' assign the output file
    ltmmConvertCtrl1.TargetFile = "c:\target.avi"
    ' set the video compressor to the LEAD compressor
    ltmmConvertCtrl1.VideoCompressors.Selection = ltmmConvertCtrl1.VideoCompressors.Find ("@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\LEAD MCMP/MJPEG Codec A COmpressor Also known as an encoder, this is a module or algorithm to compress data. Playing that data back requires a decompressor, or decoder. combined with a DECompressor, or encoder Also known as compressor, this is a module or algorithm to compress data. Playing that data back requires a decompressor, or decoder. and a decoder Also known as a decompressor, this is a module or algorithm to decompress data., which allows you to both compress and decompress that same data. (2.0)")
    ' set the audio compressor to the MP3 compressor
    ltmmConvertCtrl1.AudioCompressors.Selection = ltmmConvertCtrl1.AudioCompressors.Find ("@device:cm:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\85MPEG Layer-3")
    ' set the output format to AVI
    ltmmConvertCtrl1.TargetFormat = ltmmConvert_TargetFormat_Avi
    ' invoke the video compressor property dialog, if available
    If ltmmConvertCtrl1.HasDialog (ltmmConvert_Dlg_VideoCompressor) Then
        ltmmConvertCtrl1.ShowDialog ltmmConvert_Dlg_VideoCompressor, hWnd
    End If
    ' invoke the audio compressor property dialog, if available
    If ltmmConvertCtrl1.HasDialog(ltmmConvert_Dlg_AudioCompressor) Then
        ltmmConvertCtrl1.ShowDialog ltmmConvert_Dlg_AudioCompressor, hWnd
    End If
    cmdAbort.Caption = "Abort"
    On Error GoTo StartConvertError

    ' select from 30% to 60% of the source media
    ltmmConvertCtrl1.SelectionStart = 0.3 * ltmmConvertCtrl1.Duration
    ltmmConvertCtrl1.SelectionEnd = 0.6 * ltmmConvertCtrl1.Duration

' uncomment the following line to view the graph with DirectShow GraphEdit
' ltmmConvertCtrl1.EditGraph

    ' start the conversion
    ltmmConvertCtrl1.StartConvert
    Exit Sub
StartConvertError:
    txtStatus = Err.Description & "... Error " & CStr(Err.Number)
    cmdAbort.Caption = "Exit"
End Sub