|
|
STEP 2 - Working with streams in existing AVI filesHERE ARE THE PROJECT FILES FOR STEP 2 AVITutr2.zip
'Stream types for use in VB (translated from C macros) Theoretically, AVI files can contain multiple streams of the same type. However most players assume only one video and one audio stream per file. The first step in using streams in the AVIFile API is to get a PAVISTREAM handle to the existing stream. Since we already have a PAVIFILE handle from the previous step, all we need to do is pass that to the AVIFileGetStream function along with the type of stream we are looking for. First, dimension a new Long variable to hold the stream interface pointer: Dim pAVIStream As Long 'pointer to AVI stream interface (PAVISTREAM handle) Then add this code right after the call to AVIFileOpen in the sample program you created in the previous step: 'Get the first available video stream (PAVISTREAM) When the call to AVIFileGetStream returns, the pAVIStream variable will contain a PAVISTREAM handle that we can pass to other functions. There is one other important thing to remember. When you are done using the handle you need to free it by calling AVIStreamRelease. Add this call right after the ErrorOut tag so that it will be called even if there is an error: If pAVIStream <> 0 Then Once we have the handle we can get the first frame and the length of the stream by adding a couple of lines of code. First, dim two variables to hold the start frame and length of the file: Dim numFrames As Long 'number of frames in video stream And then add these lines right after the call to AVIFileGetStream: 'get the starting position of the stream (some streams may not start simultaneously) In order to make the sample program do something interesting let's show the results in a message box again. We will also print out the members of the AVI_FILE_INFO and AVI_STREAM_INFO UDTs in the debug window so let's inform the user of that fact in the same message. Add this line to show the message: MsgBox "PAVISTREAM handle is " & pAVIStream & vbCrLf & _ You can call AVIFileInfo and AVIStreamInfo to get information about the AVI file and the video stream you have open. While you are working in the IDE you can also use the Immediate window to print out this information. This is extremely useful, since you can immediately see whether you have opened a valid file and whether the API is returning valid information. I included a couple of utility functions in the mAVIDecs.bas file as an example of how to do this. You can call these Subs by first dimensioning a couple of UDT variables to hold the information: Dim fileInfo As AVI_FILE_INFO 'file info struct And then put these lines of code after the MsgBox call: 'get file info struct (UDT) If you copied all this code properly, you will now have a useful sample program that can open any AVI file and obtain an interface pointer to its video stream. It should also show the length of the file in frames in a pop-up msgbox window and record more detailed file and stream information in the immediate window of the IDE. You can download the full project for this step from here (AVITutr2.zip) Go back to the Table of Contents
|