Click here to Skip to main content
14,920,935 members
Articles / Programming Languages / Visual C++ 9.0
Article
Posted 23 Nov 2012

Tagged as

Stats

31.4K views
1.8K downloads
34 bookmarked

Easy AVI

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

Share

About the Author

Andy Bantly
Founder
United States United States
No Biography provided

Comments and Discussions

 
GeneralMy missing vote Pin
imagiro11-Jun-14 21:43
Memberimagiro11-Jun-14 21:43 
The other votes here suggest that this is a great article. I can imagine it is great code, but unfortunately I don't see a lot, nor do I see explanations. For voting I would need a bit more to read.

I think codeproject is great for sharing knowledge via articles, not just via downloadable code. In the current state I would have to vote very low because of "not an article". Sorry.
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
MemberAndy Bantly6-Dec-12 5:25 
QuestionAwesome Pin
DeepCodeTech28-Nov-12 21:38
MemberDeepCodeTech28-Nov-12 21:38 
Questiongreat article Pin
jamseyang24-Nov-12 4:38
Memberjamseyang24-Nov-12 4:38 
AnswerRe: great article Pin
Andy Bantly24-Nov-12 5:56
MemberAndy Bantly24-Nov-12 5:56 
GeneralRe: great article Pin
Pushpraj Barick24-Nov-12 15:34
MemberPushpraj Barick24-Nov-12 15:34 
GeneralRe: great article Pin
Andy Bantly24-Nov-12 16:13
MemberAndy Bantly24-Nov-12 16:13 
QuestionDIVX Pin
Andy Bantly24-Nov-12 3:38
MemberAndy 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.