Click here to Skip to main content
15,879,065 members
Articles / Programming Languages / Visual C++ 9.0

Easy AVI

Rate me:
Please Sign up or sign in to vote.
4.82/5 (11 votes)
5 Dec 2012CPOL 36K   1.9K   35   11
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)


Written By
Founder
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA14-Dec-12 6:12
professionalȘtefan-Mihai MOGA14-Dec-12 6:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.