Recompressing AVI Data Using Arrays Example for Visual Basic
The following code demonstrates the process of recompressing from a source array, preloaded with AVI media data, to a target array:
' source file name
Const SourceFile = "c:\source.avi"
' source array
Dim arrSource() As Byte
' target array
Dim arrTarget() As Byte
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()
' preload array with file and assign it to control
Dim fl As Long
fl = FileLen(SourceFile)
ReDim arrSource(fl)
Open SourceFile For Binary Access Read As #1
Get #1, , arrSource
Close #1
ltmmConvertCtrl1.SourceArray = arrSource
' set output array
ReDim arrTarget(0)
ltmmConvertCtrl1.TargetArray = arrTarget
' 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
' start the conversion
ltmmConvertCtrl1.StartConvert
Exit Sub
StartConvertError:
txtStatus = Err.Description & "... Error " & CStr(Err.Number)
cmdAbort.Caption = "Exit"
End Sub
Private Sub Form_Unload(Cancel As Integer)
ltmmConvertCtrl1.StopConvert
ltmmConvertCtrl1.ResetSource
ltmmConvertCtrl1.ResetTarget
End Sub