Introduction
This article presents a class that encapsulates the creation of AVI files. It also presents a small sample demonstrating
how to use it to record the desktop at 15 FPS.
Currently it doesn't support audio.
Using the code
The AVI object is very minimal and simple to use. One limitation is that the frames must all be the same size and the palette can't change. The sample code records
the desktop using a 32 BPP DIB section and thus stays within the requirements.
The AVI class
class CAVI
{
public:
CAVI();
~CAVI();
BOOL Open(DWORD FPS = 30);
CString Close();
BOOL AddFrame(CDIBFrame & DIBFrame);
BOOL IsOpen() const {return m_bOpen;}
protected:
void Init();
void Term();
BOOL CreateStream(CDIBFrame & DIBFrame);
void ReleaseStream();
protected:
BOOL m_bInit,m_bOpen,m_bStream;
CString m_csFileName;
DWORD m_dwFPS,m_dwFrame;
PAVIFILE m_pAVIFile;
PAVISTREAM m_pAVIStream,m_pAVICompressedStream;
};
Instantiate the class by declaring a CAVI
object:
CAVI Avi;
Get it ready for recording by opening it and setting the desired FPS.
Avi.Open(15);
Add a frame by using AddFrame
that takes a bitmap created from a DIB section.
Avi.AddFrame(DIB);
Finish up recording by calling Close
. This gives back the location of the temporary AVI file in the user's temp directory.
CString csFile = Avi.Close();
History
- 11/23/2012 - Article submission.