Recompressing an AVI File Example for Visual Basic
The following code demonstrates recompressing an AVI file:
Private Sub cmdAbort_Click()
' if running then abort, else exit program
If ltmmConvertCtrl1.State = ltmmConvert_State_Running Then
ltmmConvertCtrl1.StopConvert
Else
' enable the current state to be dumped
' MsgBox "State = " & CStr(ltmmConvertCtrl1.State) & ", Error = " & CStr(ltmmConvertCtrl1.ConvertError) & ", Progress = " & CStr(ltmmConvertCtrl1.PercentComplete) & "%"
Unload Me
End If
End Sub
Private Sub convert_MediaEvent
(ByVal EventCode As Long, ByVal Param1 As Long, ByVal Param2 As Long)
Select
Case EventCode
Case
ltmmEC_DVD_DOMAIN_CHANGE
txtStatus.Text
= "The DVD domain is changed"
Case
ltmmEC_DVD_TITLE_CHANGE
txtStatus.Text
= "The DVD current title The name for a group of related video files (called "Chapters") on your DVD. For example, for a DVD called "My Summer Vacation," you might have the titles "Water Skiing," "New Friends," and "Hiking." For each of those titles, you might have one or more different video files. number is changed"
End Select
Private Sub convert_Complete ()
' indicate that the conversion is
complete
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
If ((ltmmConvertCtrl1.RenderedStreams And ltmmConvert_Stream_Audio) <> 0 And (ltmmConvertCtrl1.RenderedStreams And ltmmConvert_Stream_Video) = 0) Then
txtStatus = "Recompressing audio from " & Source & " to " & Target
ElseIf ((ltmmConvertCtrl1.RenderedStreams And ltmmConvert_Stream_Audio) = 0 And (ltmmConvertCtrl1.RenderedStreams And ltmmConvert_Stream_Video) <> 0) Then
txtStatus = "Recompressing video from " & Source & " to " & Target
Else
txtStatus = "Recompressing " & Source & " to " & Target
End If
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
If ltmmConvertCtrl1.UnrenderedStreams <> 0 Then
MsgBox "Not all of the available streams could be rendered"
End If
' Assign the preview window handle to the Convert
Ctrl property VideoWindowFrame
ltmmConvertCtrl1.VideoWindowFrame
= PreviewWnd.hWnd
' Set Preview Property to True
ltmmConvertCtrl1.Preview
= True
' now the convert object is ready to Preview the
conversion process
' the user may be able to enable or disable preview
during conversion
' this is done using ltmmConvertCtrl1.PreviewVisible
bPreviewVisible = ltmmConvert.PreviewVisible
If bPreviewVisible = True Then
chkPreview.Value = 1
Else
chkPreview.Value = 0
End If
' 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
' Check box control to enable or disable the preview during conversion
Private Sub chkPreview_Click()
If chkPreview.Value = 1 Then
ltmmConvertCtrl1.PreviewVisible
= True
Else
ltmmConvertCtrl1.PreviewVisible
= False
' set the preview window
back color to black if Preview is disabled.
PreviewWnd.BackColor =
4 'black
End If
End Sub
Private Sub btnPauseConvert_Click()
' Pause conversion
ltmmConvertCtrl1.PauseConvert
End Sub
Private Sub btnRunConvert_Click()
' Run a Paused conversion
ltmmConvertCtrl1.RunConvert
End Sub