Click here to Skip to main content
15,867,594 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 35.9K   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 missing vote Pin
imagiro11-Jun-14 21:43
imagiro11-Jun-14 21:43 
GeneralMy vote of 5 Pin
Michael Haephrati3-Mar-13 5:32
professionalMichael Haephrati3-Mar-13 5:32 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA14-Dec-12 6:12
professionalȘtefan-Mihai MOGA14-Dec-12 6:12 
GeneralMy vote of 5 Pin
Michael Haephrati6-Dec-12 2:20
professionalMichael Haephrati6-Dec-12 2:20 
GeneralRe: My vote of 5 Pin
Andy Bantly6-Dec-12 5:25
Andy Bantly6-Dec-12 5:25 
QuestionAwesome Pin
DeepCodeTech28-Nov-12 21:38
DeepCodeTech28-Nov-12 21:38 
Questiongreat article Pin
jamseyang24-Nov-12 4:38
jamseyang24-Nov-12 4:38 
AnswerRe: great article Pin
Andy Bantly24-Nov-12 5:56
Andy Bantly24-Nov-12 5:56 
GeneralRe: great article Pin
Pushpraj Barick24-Nov-12 15:34
Pushpraj Barick24-Nov-12 15:34 
GeneralRe: great article Pin
Andy Bantly24-Nov-12 16:13
Andy Bantly24-Nov-12 16:13 
QuestionDIVX Pin
Andy Bantly24-Nov-12 3:38
Andy Bantly24-Nov-12 3:38 

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.