• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

Convert an MPEG file to an array of DIBs in C++/MFC?

I want to create code that will let me do this (forgive any minor syntax errors):


     HRESULT hr(E_FAIL);
     LPBITMAPHEADERINFO pDibArray[] = NULL;
     CString sMpegPathname("c:\\Madonna.mpg");

     hr = ConvertMpegToDibArray(sMpegPathname, pDibArray);

     if (SUCCEEDED(hr)) {
          // ... do stuff with pDibArray, including
          // releasing it somehow when I'm done...
     }


For 50 points, what technology would allow me to do this?  OpenGL?  DirectX?  I've been searching for a while and not having much luck.

For 100 points, where is there some C++/MFC source code that does this (*not* something only vaguely related)?  (Add a comment that you want to answer this and I'll increase the points.)

For 800 points, write the function ConvertMpegToDibArray( ) for me (okay, a class would be better, but you get the drift).    (Add a comment that you want to answer this and I'll increase the points.)

TIA.
0
LarryLeonard
Asked:
LarryLeonard
  • 8
  • 7
  • 4
1 Solution
 
jhanceCommented:
Yawn....
0
 
LarryLeonardAuthor Commented:
Grow up, jhance.
0
 
LarryLeonardAuthor Commented:
Grow up, jhance.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jhanceCommented:
What's with you?  

I just wanted to "subscribe" to this Q to keep track of it....
0
 
LarryLeonardAuthor Commented:
Oh.  I thought you were being sarcastic.  Especially given your self-description in your profile.  Sorry.

You might try something a little less likely to be mistaken, like, "Subscribing", so that people don't get annoyed for no reason.

I'm a little touchy because posting a question on EE is generally seen as an invitation to trade insults about your mother, for some reason.  In fact about two years ago I swore I'd never be back.  Guess I'm desperate.

0
 
jhanceCommented:
The comments are "tongue in cheek" in response to specific criticism from an out-of-control user...  Since he said such things about me, I thought I might as well admit it....
0
 
jhanceCommented:
I think the real problem here is that this is a really hard problem.  MPEG decoding is extremely complex and there are no royalty free implementations out there.  In fact, I believe that the MPEG scheme is patented as with MP3, so no royalty/license free implementation is even possible.

So my suggestion would be to start with a 3rd party MPEG decoder engine that has the hooks you need to extract frame-by-frame images.  License it for your intended use.  Then it would be a relatively simple matter to convert those images, in whatever form they exist from the MPEG decoder, into your DIB format.

0
 
DanRollinsCommented:
Thanks for an interesting challenge; I've never delved into these interfaces before.  

This code leaves only one minor of task as an excercise of the student.. You'll need to create an array of CBitmaps (it just throws them away after it displays them)

I made a dialog-based app, and added a Static named
  IDST_ViewRect
and one named
  IDC_BmpDisplay
(this one I set as a "picture" with type BITMAP)

And two buttons -- one to start playing and the next to single-step, capturing each frame as a DIB (you will of course want to do it all programmatically, but that will be easy for you)

I found the sample code at (the DirectX 8.0 C++ SDK (45 MB) partial load, or you can get the whole thing,  It's full of very kool stuff.

http://msdn.microsoft.com/downloads/sample.asp?url=/msdn-files/027/001/551/msdncompositedoc.xml&frame=true

=-=-=-=-=-=-=-=-=-=-=-


// dlgMain.cpp : implementation file
//
#include "stdafx.h"
#include "MpgDecode.h"
#include "dlgMain.h"

//#include "dshow.h"    // i only needed these [DR]
#include <strmif.h>     // Generated IDL header file for streams interfaces
#include <control.h>    // generated from control.odl
#include <uuids.h>      // declaration of type GUIDs and well-known clsids

#pragma comment( lib, "strmiids.lib" ) // and this lib [DR]

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define JIF(x) if (FAILED(hr=(x))) {Msg(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n"), hr); return hr;}
#define LIF(x) if (FAILED(hr=(x))) {Msg(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n"), hr);}

CString   gsFile;

// DirectShow interfaces
IGraphBuilder *pGB = NULL;
IMediaControl *pMC = NULL;
IVideoWindow  *pVW = NULL;
IBasicVideo   *pBV = NULL;
IMediaSeeking *pMS = NULL;  // this one is kinda hard to work with (lol)

/////////////////////////////////////////////////////////////////////////////
// CDlgMpgDecode dialog

CDlgMpgDecode::CDlgMpgDecode(CWnd* pParent /*=NULL*/)
      : CDialog(CDlgMpgDecode::IDD, pParent)
{
      //{{AFX_DATA_INIT(CDlgMpgDecode)
      //}}AFX_DATA_INIT
      // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
      m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDlgMpgDecode::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CDlgMpgDecode)
      DDX_Control(pDX, IDST_ViewRect, m_cstViewRect);
      DDX_Control(pDX, IDC_BmpDisplay, m_cstShowBmp);
      //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDlgMpgDecode, CDialog)
      //{{AFX_MSG_MAP(CDlgMpgDecode)
      ON_WM_QUERYDRAGICON()
      ON_BN_CLICKED(IDC_LoadMpg, OnLoadMpg)
      ON_BN_CLICKED(IDC_SingleStep, OnSingleStep)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgMpgDecode message handlers

BOOL CDlgMpgDecode::OnInitDialog()
{
      CDialog::OnInitDialog();
      SetIcon(m_hIcon, TRUE);                  // Set big icon
      SetIcon(m_hIcon, FALSE);            // Set small icon

      return TRUE;  // return TRUE  unless you set the focus to a control
}

HCURSOR CDlgMpgDecode::OnQueryDragIcon() {      return (HCURSOR) m_hIcon; }


//===============================================================
void CDlgMpgDecode::OnLoadMpg()
{
    gsFile= "c:\\temp\\mpg\\amm_2_03.mpg";
    HRESULT hr= PlayTheMovie( gsFile, &m_cstViewRect );      
}


CBitmap* GetNextFrame()
{
    HRESULT  hr;
    VOID*    pvBits=0;
    long     nBufSize= 0;
    CBitmap* pcBmpRet= 0;

    LIF( pBV->GetCurrentImage( &nBufSize, 0) ); // get size
    if ( FAILED(hr) ) return pcBmpRet;

    BYTE* pBuf= new BYTE[nBufSize];
    LIF( pBV->GetCurrentImage( &nBufSize, (long*)pBuf) ); // get data
    if ( FAILED(hr) ) { delete pBuf; return pcBmpRet; }

    BITMAPINFO* pBI= (BITMAPINFO*)pBuf;

    CWindowDC dc(NULL);
    HBITMAP hBmp;
    hBmp= CreateDIBSection( dc.m_hDC, pBI, DIB_RGB_COLORS, &pvBits,  NULL, 0);

    pcBmpRet= new CBitmap;
    pcBmpRet->Attach( hBmp );
    int nRet= SetDIBits( dc, hBmp, 0, pBI->bmiHeader.biHeight, &pBuf[0x28+12], pBI, DIB_RGB_COLORS );
    delete pBuf;

    return( pcBmpRet );
}

//===============================================================
void CDlgMpgDecode::OnSingleStep()
{
    HRESULT  hr;
    LIF( pMC->Pause() );
    if ( FAILED(hr) ) return;
   
    CBitmap* pBmp= GetNextFrame();
    m_cstShowBmp.SetBitmap( *pBmp );  // display it for fun

    // advance to the next frame
    LONGLONG nPos;
    LIF( pMS->GetCurrentPosition( &nPos ) );
    nPos++;
    LIF( pMS->SetPositions( &nPos,AM_SEEKING_AbsolutePositioning,0,0 ) );
}


//---------------------------------------------------------------
// modified from PlayWnd.cpp in DirectX SDK
//
HRESULT CDlgMpgDecode::PlayTheMovie(LPCSTR szFile, CWnd* pWnd)
{
    HRESULT hr;
    WCHAR wFile[MAX_PATH];
    MultiByteToWideChar(CP_ACP, 0, szFile, -1, wFile, MAX_PATH);

    // Get the interface for DirectShow's GraphBuilder
    JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGB));

    if( !SUCCEEDED(hr) ) {
        return(hr);
    }
    JIF(pGB->RenderFile(wFile, NULL));

    JIF(pGB->QueryInterface(IID_IMediaControl, (void **)&pMC));
    JIF(pGB->QueryInterface(IID_IMediaSeeking, (void **)&pMS));

    JIF(pGB->QueryInterface(IID_IVideoWindow, (void **)&pVW));
    JIF(pGB->QueryInterface(IID_IBasicVideo, (void **)&pBV));

    JIF(pVW->put_Owner((OAHWND)m_cstViewRect.m_hWnd));
    JIF(pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN));

    CRect rcVid;
    pWnd->GetWindowRect( &rcVid );
    JIF(pVW->SetWindowPosition(0, 0, rcVid.Width(),  rcVid.Height() ) );

    // set to seek by frames [DR]
    GUID guidFmt= TIME_FORMAT_FRAME;
    JIF(pMS->SetTimeFormat( &guidFmt) ); // no change

    // Run the graph to play the media file
    JIF( pMC->Run() );

    return hr;
}

//----------------------------------------------------
void Msg(char *szFormat, ...)
{
    char szBuffer[512];  // Large buffer for very long filenames (like with HTTP)
    va_list pArgs;
    va_start(pArgs, szFormat);
    vsprintf(szBuffer, szFormat, pArgs);
    va_end(pArgs);

    MessageBox(NULL, szBuffer, "DanRollins says this...", MB_OK);
}

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
According to your initial comment, this is 800 points worth of work.

If you need me to actually generate the array, just say so.


-- Dan

0
 
DanRollinsCommented:
OoPs, I forgot to add that this code is in the app cpp file...

if( FAILED(CoInitialize(NULL)) ) {
    Msg(TEXT("CoInitialize Failed!\r\n"));
}
CDlgMpgDecode dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();

CoUninitialize();
}
0
 
LarryLeonardAuthor Commented:
Dan - Just a quick note to let you know I'm still out here, but it will be a day or two before I can respond in full... looks good though...
0
 
LarryLeonardAuthor Commented:
Dan - I've spent 30 mins trying to recreate your project, and there's just too much stuff - it'll take forever for me to get your dialog, control, meesages, etc. set up.  Please ZIP up your project and email it to me at Spam@DefinitiveSolutions.com.  Thanks.
0
 
DanRollinsCommented:
If I send an email to Spam@DefinitiveSolutions.com I will undoubtedly have my IP banned from your server.  If that is your real email address, I suggest that you change it.

But I will go ahead and post the zip file on my website.  Pick it up at:

http://home.earthlink.net/~danrollins/ee/MpgDecode.zip

-- Dan
0
 
DanRollinsCommented:
hi LarryLeonard,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 
LarryLeonardAuthor Commented:
Hi Dan - Looks good so far, but the first thing I notice are these error messages when the program exits (and I have clicked only the "Load MPG" button):

Direct3D8: (ERROR) :Memory still allocated!  Alloc count = 16
Direct3D8: (ERROR) :Current Process (pid) = 00000558
Direct3D8: (ERROR) :Memory Address: 011923ec lAllocID=16 dwSize=00000b6c, ReturnAddr=51031d23 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 0119305c lAllocID=20 dwSize=0000001c, ReturnAddr=5102ea04 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 011930ac lAllocID=21 dwSize=00000018, ReturnAddr=5102ea35 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 011930fc lAllocID=22 dwSize=00000024, ReturnAddr=51032711 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 01193154 lAllocID=23 dwSize=00000008, ReturnAddr=510329cc (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 01193194 lAllocID=25 dwSize=0000000c, ReturnAddr=51032c7d (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 011931d4 lAllocID=26 dwSize=00000024, ReturnAddr=5102fb65 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 0119322c lAllocID=27 dwSize=00000024, ReturnAddr=5102fbba (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 01193284 lAllocID=28 dwSize=00000024, ReturnAddr=5102fc14 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 011932dc lAllocID=30 dwSize=0000042c, ReturnAddr=510214c3 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 0119373c lAllocID=31 dwSize=0000042c, ReturnAddr=510214d8 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 01193b9c lAllocID=32 dwSize=000000c4, ReturnAddr=51030109 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 01192f8c lAllocID=33 dwSize=00000018, ReturnAddr=5103013c (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 01193c94 lAllocID=35 dwSize=00000174, ReturnAddr=5103d65e (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 01192fdc lAllocID=36 dwSize=00000018, ReturnAddr=5103d6d2 (pid=00000558)
Direct3D8: (ERROR) :Memory Address: 01193e3c lAllocID=37 dwSize=00000a00, ReturnAddr=5102231e (pid=00000558)
Direct3D8: (ERROR) :Total Memory Unfreed From Current Process = 8452 bytes
devenum.dll(tid 308)     5474 : devenum object leak
quartz.dll(tid 308)     6179 :
quartz.dll(tid 308)     6191 :    ID             Object Description
quartz.dll(tid 308)     6191 :
quartz.dll(tid 308)     6192 :   876 (  12f76c)                      List node
quartz.dll(tid 308)     6193 :   875 (  12f76c)                      List node
quartz.dll(tid 308)     6193 :   871 (  12f76c)                      List node
quartz.dll(tid 308)     6194 :   870 (  12f76c)                      List node
quartz.dll(tid 308)     6194 :   869 (  12f76c)                      List node
quartz.dll(tid 308)     6195 :   868 (  12f76c)                      List node
quartz.dll(tid 308)     6195 :   867 (  12f76c)                      List node
quartz.dll(tid 308)     6196 :   866 (  12f76c)                      List node
quartz.dll(tid 308)     6196 :   865 (  12f76c)                      List node
quartz.dll(tid 308)     6197 :   864 (  12f76c)                      List node
quartz.dll(tid 308)     6197 :   863 (  12f76c)                      List node
quartz.dll(tid 308)     6198 :   861 (  12f76c)              DirectDrawSurface
quartz.dll(tid 308)     6198 :   860 (  12f76c)                     DirectDraw
quartz.dll(tid 308)     6199 :   859 (  12f76c)                      List node
quartz.dll(tid 308)     6200 :   858 (  12f76c)                      List node
quartz.dll(tid 308)     6200 :   857 (  12f76c)                      List node
quartz.dll(tid 308)     6201 :   856 (  12f76c)                      List node
quartz.dll(tid 308)     6201 :   855 (  12f76c)                      List node
quartz.dll(tid 308)     6202 :   854 (  12f76c)                      List node
quartz.dll(tid 308)     6202 :   853 (  12f76c)                      List node
quartz.dll(tid 308)     6203 :   852 (  12f76c)                      List node
quartz.dll(tid 308)     6203 :   851 (  12f76c)                      List node
quartz.dll(tid 308)     6204 :   850 (  12f76c)                      List node
quartz.dll(tid 308)     6204 :   849 (  12f76c)                      List node
quartz.dll(tid 308)     6205 :   848 (  12f76c)                      List node
quartz.dll(tid 308)     6205 :   847 (  12f76c)                      List node
quartz.dll(tid 308)     6206 :   846 (  12f76c)                      List node
quartz.dll(tid 308)     6206 :   845 (  12f76c)                      List node
quartz.dll(tid 308)     6207 :   844 (  12f76c)                      List node
quartz.dll(tid 308)     6207 :   843 (  12f76c)                      List node
quartz.dll(tid 308)     6209 :   842 (  12f76c)                      List node
quartz.dll(tid 308)     6210 :   841 (  12f76c)                      List node
quartz.dll(tid 308)     6211 :   840 (  12f76c)                      List node
quartz.dll(tid 308)     6212 :   839 (  12f76c)                      List node
quartz.dll(tid 308)     6213 :   838 (  12f76c)                      List node
quartz.dll(tid 308)     6214 :   837 (  12f76c)                      List node
quartz.dll(tid 308)     6215 :   836 (  12f76c)                      List node
quartz.dll(tid 308)     6216 :   835 (  12f76c)                      List node
quartz.dll(tid 308)     6233 :   834 (  12f76c)                      List node
quartz.dll(tid 308)     6234 :   833 (  12f76c)                      List node
quartz.dll(tid 308)     6263 :   832 (  12f76c)                      List node
quartz.dll(tid 308)     6264 :   831 (  12f76c)                      List node
quartz.dll(tid 308)     6265 :   830 (  12f76c)                      List node
quartz.dll(tid 308)     6265 :   829 (  12f76c)                      List node
quartz.dll(tid 308)     6266 :   828 (  12f76c)                      List node
quartz.dll(tid 308)     6266 :   827 (  12f76c)                      List node
quartz.dll(tid 308)     6267 :   826 (  12f76c)                      List node
quartz.dll(tid 308)     6267 :   825 (  12f76c)                      List node
quartz.dll(tid 308)     6269 :   821 (  12f76c)                    CAMSchedule
quartz.dll(tid 308)     6269 :   820 (  12f76c)         System reference clock
quartz.dll(tid 308)     6270 :   814 (  12f76c)                      List node
quartz.dll(tid 308)     6270 :   813 (  12f76c)                      List node
quartz.dll(tid 308)     6271 :   809 (  12f76c)         per stream CImplSelect
quartz.dll(tid 308)     6271 :   808 (  12f76c)      Render Seeking COM object
quartz.dll(tid 308)     6272 :   807 (  12f76c)            Silly Seeking Thing
quartz.dll(tid 308)     6273 :   805 (  12f76c)          Renderer CPosPassThru
quartz.dll(tid 308)     6273 :   723 (  12f76c)                      List node
quartz.dll(tid 308)     6274 :   691 (  12f76c)           Transform output pin
quartz.dll(tid 308)     6274 :   690 (  12f76c)            Transform input pin
quartz.dll(tid 308)     6275 :   687 (  12f76c)       VFW decompression filter
quartz.dll(tid 308)     6275 :   672 (  12f76c)                      List node
quartz.dll(tid 308)     6276 :   671 (  12f76c)              DirectDraw object
quartz.dll(tid 308)     6276 :   670 (  12f76c)                   Renderer pin
quartz.dll(tid 308)     6277 :   669 (  12f76c)                 Overlay object
quartz.dll(tid 308)     6277 :   668 (  12f76c)                Video Allocator
quartz.dll(tid 308)     6278 :   667 (  12f76c)                  Window object
quartz.dll(tid 308)     6278 :   666 (  12f76c)                  Window object
quartz.dll(tid 308)     6279 :   665 (  12f76c)                 Video renderer
quartz.dll(tid 308)     6279 :   645 (  12f76c)                      List node
quartz.dll(tid 308)     6280 :   644 (  12f76c)     rec buffer sample req list
quartz.dll(tid 308)     6281 :   643 (  12f76c)                      List node
quartz.dll(tid 308)     6281 :   642 (  12f76c)     rec buffer sample req list
quartz.dll(tid 308)     6282 :   641 (  12f76c)     rec buffer sample req list
quartz.dll(tid 308)     6282 :   637 (  12f76c)                      List node
quartz.dll(tid 308)     6283 :   633 (  12f76c)                      List node
quartz.dll(tid 308)     6283 :   629 (  12f76c)                      List node
quartz.dll(tid 308)     6284 :   625 (  12f76c)                      List node
quartz.dll(tid 308)     6284 :   621 (  12f76c)                      List node
quartz.dll(tid 308)     6285 :   617 (  12f76c)                      List node
quartz.dll(tid 308)     6285 :   613 (  12f76c)                      List node
quartz.dll(tid 308)     6286 :   609 (  12f76c)                      List node
quartz.dll(tid 308)     6286 :   605 (  12f76c)                      List node
quartz.dll(tid 308)     6287 :   601 (  12f76c)                      List node
quartz.dll(tid 308)     6287 :   597 (  12f76c)                      List node
quartz.dll(tid 308)     6288 :   593 (  12f76c)                      List node
quartz.dll(tid 308)     6289 :   589 (  12f76c)                      List node
quartz.dll(tid 308)     6290 :   585 (  12f76c)                      List node
quartz.dll(tid 308)     6290 :   581 (  12f76c)                      List node
quartz.dll(tid 308)     6291 :   577 (  12f76c)                      List node
quartz.dll(tid 308)     6291 :   573 (  12f76c)                      List node
quartz.dll(tid 308)     6292 :   569 (  12f76c)                      List node
quartz.dll(tid 308)     6293 :   565 (  12f76c)                      List node
quartz.dll(tid 308)     6293 :   561 (  12f76c)                      List node
quartz.dll(tid 308)     6294 :   557 (  12f76c)                      List node
quartz.dll(tid 308)     6294 :   553 (  12f76c)                      List node
quartz.dll(tid 308)     6295 :   549 (  12f76c)                      List node
quartz.dll(tid 308)     6295 :   545 (  12f76c)                      List node
quartz.dll(tid 308)     6296 :   541 (  12f76c)                      List node
quartz.dll(tid 308)     6296 :   537 (  12f76c)                      List node
quartz.dll(tid 308)     6297 :   533 (  12f76c)                      List node
quartz.dll(tid 308)     6297 :   529 (  12f76c)                      List node
quartz.dll(tid 308)     6298 :   525 (  12f76c)                      List node
quartz.dll(tid 308)     6298 :   521 (  12f76c)                      List node
quartz.dll(tid 308)     6299 :   517 (  12f76c)                      List node
quartz.dll(tid 308)     6299 :   513 (  12f76c)                      List node
quartz.dll(tid 308)     6300 :   509 (  12f76c)                      List node
quartz.dll(tid 308)     6301 :   505 (  12f76c)                      List node
quartz.dll(tid 308)     6301 :   501 (  12f76c)                      List node
quartz.dll(tid 308)     6302 :   497 (  12f76c)                      List node
quartz.dll(tid 308)     6302 :   493 (  12f76c)                      List node
quartz.dll(tid 308)     6303 :   489 (  12f76c)                      List node
quartz.dll(tid 308)     6303 :   485 (  12f76c)                      List node
quartz.dll(tid 308)     6304 :   481 (  12f76c)                      List node
quartz.dll(tid 308)     6304 :   477 (  12f76c)                      List node
quartz.dll(tid 308)     6305 :   473 (  12f76c)                      List node
quartz.dll(tid 308)     6305 :   469 (  12f76c)                      List node
quartz.dll(tid 308)     6306 :   465 (  12f76c)                      List node
quartz.dll(tid 308)     6306 :   461 (  12f76c)                      List node
quartz.dll(tid 308)     6307 :   457 (  12f76c)                      List node
quartz.dll(tid 308)     6307 :   453 (  12f76c)                      List node
quartz.dll(tid 308)     6308 :   449 (  12f76c)                      List node
quartz.dll(tid 308)     6309 :   445 (  12f76c)                      List node
quartz.dll(tid 308)     6309 :   441 (  12f76c)                      List node
quartz.dll(tid 308)     6310 :   437 (  12f76c)                      List node
quartz.dll(tid 308)     6311 :   433 (  12f76c)                      List node
quartz.dll(tid 308)     6311 :   429 (  12f76c)                      List node
quartz.dll(tid 308)     6312 :   425 (  12f76c)                      List node
quartz.dll(tid 308)     6312 :   421 (  12f76c)                      List node
quartz.dll(tid 308)     6313 :   417 (  12f76c)                      List node
quartz.dll(tid 308)     6313 :   413 (  12f76c)                      List node
quartz.dll(tid 308)     6314 :   409 (  12f76c)                      List node
quartz.dll(tid 308)     6314 :   405 (  12f76c)                      List node
quartz.dll(tid 308)     6315 :   401 (  12f76c)                      List node
quartz.dll(tid 308)     6315 :   397 (  12f76c)                      List node
quartz.dll(tid 308)     6316 :   393 (  12f76c)                      List node
quartz.dll(tid 308)     6317 :   389 (  12f76c)                      List node
quartz.dll(tid 308)     6317 :   385 (  12f76c)                      List node
quartz.dll(tid 308)     6318 :   384 (  12f76c)           parser complete list
quartz.dll(tid 308)     6318 :   383 (  12f76c)             parser issued list
quartz.dll(tid 308)     6319 :   382 (  12f76c)            parser pending list
quartz.dll(tid 308)     6320 :   381 (  12f76c)               parser free list
quartz.dll(tid 308)     6321 :   380 (  12f76c)             Sorted buffer list
quartz.dll(tid 308)     6321 :   379 (  12f76c)               free buffer list
quartz.dll(tid 308)     6322 :   378 (  12f76c)                cache allocator
quartz.dll(tid 308)     6322 :   377 (  12f76c)       CBaseMSROutPin allocator
quartz.dll(tid 308)     6323 :   376 (  12f76c)                     source pin
quartz.dll(tid 308)     6323 :   367 (  12f76c)                      List node
quartz.dll(tid 308)     6351 :   366 (  12f76c)                         in pin
quartz.dll(tid 308)     6352 :   365 (  12f76c)                AVI File Reader
quartz.dll(tid 308)     6352 :   363 (  12f76c)                      List node
quartz.dll(tid 308)     6353 :   362 (  12f76c)                      List node
quartz.dll(tid 308)     6353 :   361 (  12f76c)                      List node
quartz.dll(tid 308)     6354 :   360 (  12f76c)                      List node
quartz.dll(tid 308)     6354 :   359 (  12f76c)                      List node
quartz.dll(tid 308)     6355 :   358 (  12f76c)                      List node
quartz.dll(tid 308)     6355 :   357 (  12f76c)                      List node
quartz.dll(tid 308)     6356 :   356 (  12f76c)                      List node
quartz.dll(tid 308)     6356 :   355 (  12f76c)                      List node
quartz.dll(tid 308)     6357 :   354 (  12f76c)                      List node
quartz.dll(tid 308)     6357 :   353 (  12f76c)                      List node
quartz.dll(tid 308)     6358 :   352 (  12f76c)                      List node
quartz.dll(tid 308)     6359 :   351 (  12f76c)                      List node
quartz.dll(tid 308)     6359 :   350 (  12f76c)                      List node
quartz.dll(tid 308)     6360 :   349 (  12f76c)                      List node
quartz.dll(tid 308)     6361 :   348 (  12f76c)                      List node
quartz.dll(tid 308)     6362 :   347 (  12f76c)                      List node
quartz.dll(tid 308)     6362 :   346 (  12f76c)                      List node
quartz.dll(tid 308)     6363 :   345 (  12f76c)                      List node
quartz.dll(tid 308)     6363 :   344 (  12f76c)                      List node
quartz.dll(tid 308)     6364 :   343 (  12f76c)                      List node
quartz.dll(tid 308)     6365 :   342 (  12f76c)                      List node
quartz.dll(tid 308)     6365 :   341 (  12f76c)                      List node
quartz.dll(tid 308)     6366 :   340 (  12f76c)                      List node
quartz.dll(tid 308)     6366 :   339 (  12f76c)                      List node
quartz.dll(tid 308)     6367 :   338 (  12f76c)                      List node
quartz.dll(tid 308)     6367 :   337 (  12f76c)                      List node
quartz.dll(tid 308)     6368 :   336 (  12f76c)                      List node
quartz.dll(tid 308)     6369 :   335 (  12f76c)                      List node
quartz.dll(tid 308)     6369 :   334 (  12f76c)                      List node
quartz.dll(tid 308)     6370 :   333 (  12f76c)                      List node
quartz.dll(tid 308)     6371 :   332 (  12f76c)                      List node
quartz.dll(tid 308)     6371 :   331 (  12f76c)                      List node
quartz.dll(tid 308)     6372 :   330 (  12f76c)                      List node
quartz.dll(tid 308)     6372 :   329 (  12f76c)                      List node
quartz.dll(tid 308)     6373 :   328 (  12f76c)                      List node
quartz.dll(tid 308)     6373 :   327 (  12f76c)                      List node
quartz.dll(tid 308)     6374 :   326 (  12f76c)                      List node
quartz.dll(tid 308)     6374 :   325 (  12f76c)                      List node
quartz.dll(tid 308)     6375 :   324 (  12f76c)                      List node
quartz.dll(tid 308)     6375 :   323 (  12f76c)                      List node
quartz.dll(tid 308)     6376 :   322 (  12f76c)                      List node
quartz.dll(tid 308)     6376 :   321 (  12f76c)                      List node
quartz.dll(tid 308)     6377 :   320 (  12f76c)                      List node
quartz.dll(tid 308)     6377 :   299 (  12f76c)                      List node
quartz.dll(tid 308)     6378 :   298 (  12f76c)                      List node
quartz.dll(tid 308)     6379 :   297 (  12f76c)                      List node
quartz.dll(tid 308)     6379 :   296 (  12f76c)                      List node
quartz.dll(tid 308)     6380 :   295 (  12f76c)                      List node
quartz.dll(tid 308)     6380 :   294 (  12f76c)                      List node
quartz.dll(tid 308)     6381 :   293 (  12f76c)                      List node
quartz.dll(tid 308)     6382 :   292 (  12f76c)                      List node
quartz.dll(tid 308)     6382 :   291 (  12f76c)                      List node
quartz.dll(tid 308)     6383 :   290 (  12f76c)                      List node
quartz.dll(tid 308)     6383 :   289 (  12f76c)                      List node
quartz.dll(tid 308)     6384 :   288 (  12f76c)                      List node
quartz.dll(tid 308)     6384 :   287 (  12f76c)                      List node
quartz.dll(tid 308)     6385 :   286 (  12f76c)                      List node
quartz.dll(tid 308)     6385 :   272 (  12f76c)                      List node
quartz.dll(tid 308)     6386 :   266 (  12f76c)                      List node
quartz.dll(tid 308)     6386 :   265 (  12f76c)                      List node
quartz.dll(tid 308)     6387 :   264 (  12f76c)                      List node
quartz.dll(tid 308)     6387 :   263 (  12f76c)                      List node
quartz.dll(tid 308)     6388 :   262 (  12f76c)                      List node
quartz.dll(tid 308)     6389 :   261 (  12f76c)                      List node
quartz.dll(tid 308)     6389 :   240 (  12f76c)                      List node
quartz.dll(tid 308)     6390 :   233 (  12f76c)                      List node
quartz.dll(tid 308)     6390 :   197 (  12f76c)                      List node
quartz.dll(tid 308)     6391 :   132 (  12f76c)                      List node
quartz.dll(tid 308)     6391 :   131 (  12f76c)                      List node
quartz.dll(tid 308)     6392 :   130 (  12f76c)                      List node
quartz.dll(tid 308)     6392 :   116 (  12f76c)                      List node
quartz.dll(tid 308)     6393 :    67 (  12f76c)                      List node
quartz.dll(tid 308)     6394 :    60 (  12f76c)                    Filter list
quartz.dll(tid 308)     6394 :    34 (  12f76c)                      List node
quartz.dll(tid 308)     6395 :    33 (  12f76c)               Async output pin
quartz.dll(tid 308)     6395 :    32 (  12f76c)                      Done list
quartz.dll(tid 308)     6396 :    31 (  12f76c)                      Work list
quartz.dll(tid 308)     6396 :    30 (  12f76c)                   Async Reader
quartz.dll(tid 308)     6398 :    28 (  12f76c)       Stream time command list
quartz.dll(tid 308)     6398 :    27 (  12f76c) Presentation time command list
quartz.dll(tid 308)     6399 :    26 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6400 :    25 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6400 :    24 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6401 :    23 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6401 :    22 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6402 :    21 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6402 :    20 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6403 :    19 (  12f76c)                     Event list
quartz.dll(tid 308)     6403 :    18 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6404 :    17 (  12f76c)                     CFGControl
quartz.dll(tid 308)     6404 :    16 (  12f76c)                   resource mgr
quartz.dll(tid 308)     6405 :    15 (  12f76c) Renderers Finished Renderering List
quartz.dll(tid 308)     6405 :    14 (  12f76c)                     listWindow
quartz.dll(tid 308)     6406 :    13 (  12f76c)                      listAudio
quartz.dll(tid 308)     6407 :    12 (  12f76c)                    listSeeking
quartz.dll(tid 308)     6407 :    11 (  12f76c)                 m_lLostDevices
quartz.dll(tid 308)     6408 :    10 (  12f76c)                 filter mapper2
quartz.dll(tid 308)     6410 :     8 (  12f76c)                   Filter Chain
quartz.dll(tid 308)     6410 :     7 (  12f76c)              Filter Cache List
quartz.dll(tid 308)     6411 :     6 (  12f76c)                   CGraphConfig
quartz.dll(tid 308)     6412 :     5 (  12f76c) List of filters supporting IAMOpenProgress
quartz.dll(tid 308)     6412 :     4 (  12f76c) List of outstanding connections for graph
quartz.dll(tid 308)     6413 :     3 (  12f76c)       List of filters in graph
quartz.dll(tid 308)     6413 :     2 (  12f76c)              Core filter graph
quartz.dll(tid 308)     6414 :
quartz.dll(tid 308)     6414 : Total object count   254

I've tried a few things and nothing seems to work.  I can't see where any memory is being allocated that isn't being released.  Any ideas?
0
 
LarryLeonardAuthor Commented:
Doh!  I just realized that, although I added Release()'s for each of the five interfaces, I put them in the WM_CLOSE handler instead of the WM_DESTROY one.  Problem solved.

Next problem... in this call, what does the magic number "52" represent?

   SetDIBits(dc, hBmp, 0, pBI->bmiHeader.biHeight,
     &pBuf[0x28+12], pBI, DIB_RGB_COLORS);

The 40 is for the size of the BITMAPHEADERINFO structure, and the 12 is for, uh, what?  I want to say it's the three DWORDs for the color table, but that's only for 32-bit color, right?  I tried it for a variety of MPG files, and sometimes the BITMAPINFOHEADER's biBitCount value was 8, and sometimes it was 24, but the bitmap displayed was always correct.  Don't we have to account for color table differences among the various color depths possible?  What I mean is, we can't always just offset by 52, can we?  It seems to work, but I don't get why it does...

0
 
DanRollinsCommented:
I'm pragmatic about these things.  I got that by trial and error.  In the image view rectangle, the bitmap was shifted until I put in the "fudge factor" of 12.  

Now that I know that you are following up, I'll research it.  Of course, one can't consider it to be production-quality code until that is ascertained.

Other than that, does it look like the code is what you need?

-- Dan


0
 
DanRollinsCommented:
I found it.  The relevant issue is that these MPEG snapshots use BI_BITFIELDS in the biCompression field.  

BI_BITFIELDS
Specifies that the bitmap is not compressed and that the color table consists of three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. This is valid when used with 16- and 32-bpp bitmaps.

"...the color table consists of three DWORD color masks..."

So just add code like:
int iNumColors= 0;
if ( pBIH->biBitCount <= 8) iNumColors= (1 << pBIH->biBitCount);
if (pBIH->biClrUsed > 0) iNumColors= pBIH->biClrUsed;  // Use biClrUsed
int nColorTableLen= sizeof(RGBQUAD) * iNumColors;
if (pBIH->biCompression == BI_BITFIELDS)  {
   nColorTableLen= 3*sizeof(DWORD);// colormask is DWORD
}
void* pBits= &pBuf[ sizeof(BITMAPINFOHEADER)+ nColorTableLen ];
int nRet= SetDIBits( dc, hBmp, 0, pBI->bmiHeader.biHeight, pBits, pBI, DIB_RGB_COLORS );

-- Dan
0
 
LarryLeonardAuthor Commented:
Code looks great, thanks!  There is a slight EE issue though.  I tried to increase the points to 800, and it said the maximum is 300.  Since you have a couple of hundred thousand points, I bet you know the best workaround for this!  Let me know what to do...
0
 
DanRollinsCommented:
I just happen to know the trick!   First, increase this Q to 300 pts and accept my comment as an answer.

Now, you must post a new question, titled "Points for DanRollins" in it, paste this:

In appreciation for your help on:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=20173682

You will need to do that twice.  On the first one, set the points to 300 on the second, set the points to 200.

300 + 300 + 200 = 800

I'll also continue listening here in case you need additional help.

-- Dan

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 8
  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now