'***********************************************************
'* This sample will do a memory conversion by reading *
'* a file content into a stream object, connecting the *
'* stream to the convert object using SourceStream *
'* property, and then reading the result of the conversion *
'* from the Stream object again using the TargetStream *
'* property of the convert object *
'***********************************************************
' source file name
Const SourceFile = "c:\source.avi"
' target file name
Const TargetFile = "c:\target.avi"
Private Sub cmdAbort_Click()
' if running then abort, else exit program
If convert.State = ltmmConvert_State_Running Then
convert.StopConvert
Else
Unload Me
End If
End Sub
Private Sub convert_Complete()
Dim target As ltmmMemory
Dim cbwrite As Long
Dim cbleft As Long
Dim fl As Long
Dim arr() As Byte
' write the target memory object to file
Set target = convert.TargetStream
‘ To manipulate the buffer bytes directly without a buffer pointer
‘ use the SetByte method, for example to change the first two
‘ bytes in the buffer :
‘ target.SetByte (0, &H10);
‘ target.SetByte (1, &H13);
Open TargetFile For Binary Access Write As #1
fl = target.BufferSize
pos = 0
Do While (pos < fl)
cbwrite = 2048
cbleft = fl - pos
If (cbleft < cbwrite) Then
cbwrite = cbleft
End If
ReDim Preserve arr(cbwrite - 1)
' To lock the buffer for synchronization, use the following
' line instead of the line below :
' arr = target.LockBuffer ();
' or
' arr = target.LockRegion (0, fl);
' You may also use the GetData() function
' To get the data without allocating array :
' target.GetData (0, fl);
‘Remember to call Unlock () however for every lock you do :
‘ target.Unlock ()
target.CopyData pos, cbwrite, arr
Put #1, , arr
pos = pos + cbwrite
Loop
Close #1
' indicate that the conversion has completed
txtStatus.Caption = "Conversion completed."
cmdAbort.Caption = "Exit"
End Sub
Private Sub convert_ErrorAbort(ByVal ErrorCode As Long)
' indicate that a conversion error has occurred
txtStatus.Caption = "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
txtStatus.Caption = "Recompressing from memory to memory"
End Sub
Private Sub convert_UserAbort()
' indicate that the user aborted
txtStatus.Caption = "Conversion Aborted."
cmdAbort.Caption = "Exit"
End Sub
Private Sub Form_Load()
Dim source As ltmmMemory
Dim cbread As Long
Dim cbleft As Long
Dim fl As Long
Dim arr() As Byte
' preload memory object with file and assign it to control
Set source = New ltmmMemory
fl = FileLen(SourceFile)
source.BufferSize = fl
Open SourceFile For Binary Access Read As #1
pos = 0
Do While (pos < fl)
cbread = 2048
cbleft = fl - pos
If (cbleft < cbread) Then
cbread = cbleft
End If
ReDim Preserve arr(cbread - 1)
Get #1, , arr
source.SetData pos, cbread, arr
pos = pos + cbread
Loop
Close #1
convert.SourceStream = source
' set output memory object
convert.TargetStream = New ltmmMemory
' set the video compressor to the LEAD compressor
convert.VideoCompressors.Selection = convert.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
convert.AudioCompressors.Selection = convert.AudioCompressors.Find("@device:cm:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\85MPEG Layer-3")
' set the output format to AVI
convert.TargetFormat = ltmmConvert_TargetFormat_Avi
' invoke the video compressor property dialog, if available
If convert.HasDialog (ltmmConvert_Dlg_VideoCompressor) Then
convert.ShowDialog ltmmConvert_Dlg_VideoCompressor, hWnd
End If
' invoke the audio compressor property dialog, if available
If convert.HasDialog (ltmmConvert_Dlg_AudioCompressor) Then
convert.ShowDialog ltmmConvert_Dlg_AudioCompressor, hWnd
End If
cmdAbort.Caption = "Abort"
On Error GoTo StartConvertError
' start the conversion
convert.StartConvert
Exit Sub
StartConvertError:
txtStatus.Caption = Err.Description & "... Error " & CStr(Err.Number)
cmdAbort.Caption = "Exit"
End Sub
Private Sub Form_Unload(Cancel As Integer)
convert.StopConvert
convert.ResetSource
convert.ResetTarget
End Sub
‘Routine to output data to text box from memory object
Private Sub PlotData(MemObj As ltmmMemory)
Dim iData As Integer
Dim lSize As Long
Dim Count As Long
lSize = MemObj.BufferSize
txtPlot.Text = ""
For Count = 1 To lSize
iData = MemObj.GetByte (i)
txtPlot.Text = txtPlot.Text + CStr(iData)
Next Count
End Sub