AVI Low-Level Functions

Fastgraph's low-level AVI functions provide the ability to play AVI files one frame at a time. This is desirable when your program must perform other tasks between frames, or for playing two or more AVI files at the same time. To use the low-level AVI functions, call fg_aviopen() for each AVI file. The first fg_aviopen() parameter is the AVI file name. The second parameter is a 48-byte array that will receive a context descriptor for the AVI file. You must create a context descriptor with fg_aviopen() for each AVI file you'll access with the low-level AVI file functions. The context descriptor is then passed to other functions when accessing the AVI file. If successful, fg_aviopen() fills the context descriptor, positions the AVI file at the first frame, and returns zero. The possible error return values are the same as for fg_showavi().

The fg_aviplay() function plays one or more frames from an AVI file and leaves the file positioned at the beginning of the next frame. Its three parameters are the same as for fg_showavi() except the first parameter is a context descriptor instead of an AVI file name. The fg_aviskip() function advances over AVI file frames. Its first parameter is the AVI file's context descriptor, and its second parameter is the number of frames to skip (if the frame count is negative, the file position is reset to the first frame). Both functions return the number of frames played (or skipped), which may be less than the number of frames requested if the end-of-file is reached. The last low-level AVI function, fg_avidone(), closes an AVI file previously opened with fg_aviopen(). Its only parameter is the AVI file's context descriptor.

The following code shows how to play the AVI file SEARCH.AVI one frame at a time using the low-level AVI functions. We first open the AVI file with fg_aviopen(), which returns a 48-byte context descriptor for the file. If the file was opened successfully, we play each frame by calling fg_aviplay() in a loop. This itself does not actually display the frames but plays them in the active virtual buffer, so after each frame we call fg_vbscale() to display it in the client area. Eventually we'll reach the end-of-file, indicated by an fg_aviplay() return value of zero. When this occurs, we call fg_avidone().


int Frames, Status;
char Context[48];
Status = fg_aviopen("SEARCH.AVI",Context);
if (Status == 0)
      Frames = fg_aviplay(Context,1,0);
      if (Frames > 0)
   while (Frames > 0);


Frames, Status : integer;
Context : array [1..48] of byte;
Status := fg_aviopen('SEARCH.AVI'+chr(0),Context);
if Status = 0 then
    Frames := fg_aviplay(Context,1,0);
    if Frames > 0 then
until Frames = 0;

Visual Basic:

Dim Frames As Long, Status As Long
Dim Context(48) As Byte
Status = fg_aviopen("SEARCH.AVI", Context(0))
If Status = 0 Then
      Frames = fg_aviplay(Context(0), 1, 0)
      If Frames > 0 Then
         Call fg_vbscale(0, fg_getmaxx(), 0, fg_getmaxy(),
                         0, cxClient - 1, 0, cyClient - 1)
      End If
   Loop While Frames > 0
   Call fg_avidone(Context(0))
End If

<< Prev

Next >>

Fastgraph Home Page


copyright 2001 Ted Gruber Software, Inc.