Capture Video to RAM

Hello!

I must capture full framerate PAL video data through a capturing
device which is working properly with it's Video For Windows driver.
The idea is to continously capture the last 3 seconds of video to some
buffer in RAM (since the data rate doesn't allow data to be written to
disk. On a given signal I want to interrupt the capture process and
save the video as a compressed AVI file.

To start off I thought that it would be a good idea to use the
VideoStreamCallback functionality of AVICAP32.DLL. This seems to be
working fine and after 3 seconds I have about 75 frames worth of video
data in a TMemoryStream. The question now, how do I create a
compressed AVI file from the data. Any guidance in this matter would
be appreciated greatly. I have no clue about what things that need to
be done with AVIFIL32.DLL or in what order these things should be
done. Is it a good idea to use the VideoStreamCallback at all? Is
there any other way to do this?

Thank you!

/Erik