Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VC9.0

Easy AVI

4.82/5 (11 votes)
5 Dec 2012CPOL 37.5K   1.9K  
A class to aid in creation of AVI files

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

C++
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:

C++
CAVI Avi;

Get it ready for recording by opening it and setting the desired FPS.

C++
Avi.Open(15);

Add a frame by using AddFrame that takes a bitmap created from a DIB section.

C++
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.

C++
CString csFile = Avi.Close();

History

  • 11/23/2012 - Article submission.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)