procedure GetAVIFrame;
var
Frame : Integer;
AVIElapsedTime : DWord;
BMP : ^TBITMAPINFOHEADER;
begin
// Get the elapsed time. If the elapsed time is longer than the
// video clip, then reset the elapsed time and video start
AVIElapsedTime :=GetTickCount() - AVIStart;
if AVIElapsedTime > AVILength
then
begin
AVIStart :=GetTickCount();
AVIElapsedTime :=0;
end;
// Get the next frame based on the elaped time
Frame :=AVIStreamTimeToSample(AVIStream, AVIElapsedTime);
if Frame <> ActiveFrame
then
begin
ActiveFrame :=Frame;
{ // use this for uncompressed video ONLY
AVIStreamRead(AviStream, Frame, 1, FrameData, AviInfo.dwWidth*AviInfo.dwHeight*3, nil, nil);
}
// use this for compressed video
BMP := AVIStreamGetFrame(GetFramePointer, frame);
FrameData := Pointer(Cardinal(BMP) + BMP.biSize + BMP.biClrUsed*sizeof(RGBQUAD));
// the drawdib function will uncompress the framedata as it tries to copy the BMP
DrawDibDraw(0, H_DC, 0, 0, AviInfo.dwWidth, AviInfo.dwHeight, @BMP, FrameData, 0, 0, AVIInfo.dwWidth, AVIInfo.dwHeight, 0);
SwapRGB(FrameData, AviInfo.dwWidth * AviInfo.dwHeight);
// Swap the BGR image to a RGB image
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, AviInfo.dwWidth, AviInfo.dwHeight, GL_RGB, GL_UNSIGNED_BYTE, FrameData);
end;
end;