Click here to Skip to main content
Licence 
First Posted 14 May 2006
Views 30,661
Bookmarked 28 times

A Codecless Monochrome AVI Reader

By | 14 May 2006 | Article
The way of reading AVI files without installing codec drivers.

Sample Image - CodeclessAviReader.jpg

Introduction

When I was working with monochrome AVI files in my C++ project, I noticed that for certain machines, I needed adminitrator privilegies to install codec drivers.

As I was working in my school computer lab where those privilegies are very hard to get, I chose the way of working around the matter by using the DLL driver immediately, instead of using it via the operating system.

Background

This article uses the code of the lossless Win32 video codec Huffyuv developed by Ben Rudiak-Gould under GPL licence.

It also uses the Open Source Computer Vision Library OPENCV for viewing the frames.

Using the code

The AVI reader is wrapped in a class called CMonochromeAviReader.

The reader uses the codec library compiled from the original Huffyuv code. The modification made to Ben's code is the key word __declspec(dllexport) added to the codec main struct CodeInst.

    struct __declspec(dllexport) CodecInst {
      ...
    };

Two instances were created: the first CodecInst m_codec is for the codec, and the other one ICDECOMPRESS m_icinfo has to hold the tracks of both the compressed and uncompressed data for a frame.

    typedef struct { 
        DWORD              dwFlags; 
        LPBITMAPINFOHEADER lpbiInput; 
        LPVOID             lpInput; 
        LPBITMAPINFOHEADER lpbiOutput; 
        LPVOID             lpOutput; 
        DWORD              ckid; 
    } ICDECOMPRESS;

The field lpInput is used to extract the data from uncompressed data while lpOutput is used for the compressed one.

IplImage* CMonochromeAviReader::ReadFrame(unsigned int index)
{
    AVIStreamRead(m_pAviStream, index, 1, m_icinfo.lpInput, 
                  m_frameStreamLength, NULL, NULL);
    if(... compressed data ...)
    {
        m_codec.Decompress(&m_icinfo, 0);
        m_codec.DecompressEnd();
            
        cvSetImageData(m_pFrameRGB,m_icinfo.lpOutput,m_width*3);
        ...
        return m_pFrame;
    }
    else if(... uncompressed data ...)
    {
        cvSetImageData(m_pFrame,m_icinfo.lpInput,m_width*1);
        return m_pFrame;
    }
    else 
    {
        return NULL;
    }
}

Note that the OPENCV function cvSetImageData( IplImage* image, void* data, width) can also be replaced by memcpy(IplImage* image->imageData,void *data, width*height), but cvSetImageData is better because it is optimized to run on Intel processors and it doesn't copy all the data; it's a matter of pointing while memcopy has to copy the memory in the newly allocated space.

Revision History

16-05-2006

  • Bug in the Close method fixed.

15-05-2006

  • Original article.

That's all folks!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Frederic Ntawiniga

Engineer

Canada Canada

Member

Just programming

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWhy monochrome? Pinmember_Stilgar_22:53 14 May '06  
AnswerRe: Why monochrome? PinmemberFrédéric Ntawiniga7:31 15 May '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 15 May 2006
Article Copyright 2006 by Frederic Ntawiniga
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid