How to display video from memory buffer efficiently? 
Author Message
 How to display video from memory buffer efficiently?

I got video buffer in memory and I can display the video using
CClinetDC, like this:
Void myClass::display(BYTE * buffer)
 {
   CClientDC dc(m_dialog); //m_dialog is a MFC dialog
   for(int i=0;i<width; i++)
    for(int j=0; j<height; j++)
     dc.SetPixel(j,i,*buffer++);
 }
I know this is very inefficient. can anyone tell me what is the
efficient way to display video in my case?

Thanks,
Jin



Thu, 16 Jun 2005 23:07:26 GMT  
 How to display video from memory buffer efficiently?

You can create HBITMAP (that you can later drow it into DC using):
HBITMAP CreateDIBitmap(
  HDC hdc,                        // handle to DC
  CONST BITMAPINFOHEADER *lpbmih, // bitmap data
  DWORD fdwInit,                  // initialization option
  CONST VOID *lpbInit,            // initialization data
  CONST BITMAPINFO *lpbmi,        // color-format data
  UINT fuUsage                    // color-data usage
);The actural data (what you did setPixel) is stored in the  lpbInit
array...


Quote:
> I got video buffer in memory and I can display the video using
> CClinetDC, like this:
> Void myClass::display(BYTE * buffer)
>  {
>    CClientDC dc(m_dialog); //m_dialog is a MFC dialog
>    for(int i=0;i<width; i++)
>     for(int j=0; j<height; j++)
>      dc.SetPixel(j,i,*buffer++);
>  }
> I know this is very inefficient. can anyone tell me what is the
> efficient way to display video in my case?

> Thanks,
> Jin



Fri, 17 Jun 2005 04:53:50 GMT  
 How to display video from memory buffer efficiently?
In the order from lowest to highest performance and complexity:

SetDIBitsToDevice (and other related GDI APIs)
DrawDib
DirectDraw

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> I got video buffer in memory and I can display the video using
> CClinetDC, like this:
> Void myClass::display(BYTE * buffer)
>  {
>    CClientDC dc(m_dialog); //m_dialog is a MFC dialog
>    for(int i=0;i<width; i++)
>     for(int j=0; j<height; j++)
>      dc.SetPixel(j,i,*buffer++);
>  }
> I know this is very inefficient. can anyone tell me what is the
> efficient way to display video in my case?



Sat, 18 Jun 2005 04:45:23 GMT  
 How to display video from memory buffer efficiently?
hi,

is your Video playing within the context of a OCX or
COM object like MMplayer ?

if so, send a message to the player to paint itself into your memory
DIB. In other words, lets say you have a DC, a DIB and OCX player...

(pseudo code below)
...
HDC memDC = CreateCompatibleDC(player->GetSafeHdc()  /* or NULL */);
BITMAP bmp = CreateDIBSection( memDC  ... );
HBITMAP old = (HBITMAP)SelectObject(memDC , bmp);
...

later, you can subclass the player or use a timer and call this :

...
SendMessage( player->GetSafeHwnd(), WM_PAINT, (WPARAM)memDC , 0);
(or use the call described by Igor)
...

and then copy the "memDC " to where ever you need to see the result.
(hint : use BitBlit etc...)

I hope this gives you ideas :)

...



Sat, 18 Jun 2005 13:45:06 GMT  
 How to display video from memory buffer efficiently?
Thanks for the help.

Actually, I am writing a light client viewer where it request a real
time video stream from  video server based on H323 connection. As a
client viewer, Netmeeting works OK but it is bi-directional and not
firewall friendly.  I have to write my own viewer which can be embeded
in webpage as an  activeX control. currently, I am testing it in MFC
dialog application.
The data buffer I recieved is in YUV 411 format, what is the best way
to handle it in Bitmap/Bitblt solution?
I tried:
---------------------
HBITMAP hBmp=CreateDIBitmap(memDC,NULL,CBM_INIT,buffer,NULL,DIB_RGB_COLORS);
testBitmap.CreateComaptibleBitmap(&dc,176,144);
pOldBitmap=memDC.SelectObject(&testBitmap);
dc.Bitblt(0,0,176,144,&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBitmap);
--------------------------
I got a black video Window! how to use  hBmp correctly here?
when I changed to:
testBitmap.CreateBitmap(176,144,4,4,buffer);
pOldBitmap=memDC.SelectObject(&testBitmap);
dc.Bitblt(0,0,176,144,&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBitmap);
I got 4 44x36 small video window inside 176x144 frame, poor quality,
how does that work out?

My video quality is not more than 256kbps, so for:
->SetDIBitsToDevice (and other related GDI APIs)
->DrawDib
->DirectDraw
which suit most?

Thanks for your kind help.



Sun, 19 Jun 2005 04:08:31 GMT  
 How to display video from memory buffer efficiently?
HI,   and HApPy NeW YeAR !!   ;]

well, that was a good question, and i have to say , i was left with a few
questions of my own...
... specificaly reguarding "YUV" specs.

according to an article i read, it said:

"YUV means colour depth from 12 bits down to 9 bits per pixel instead of 16
bits and 24 bits modes
available as standard through video setup dialog in 'any' capture
program..."

If you' re trying to create DIB sections with the wrong bit format you can
expect the color buffer
to point to the wrong bits, hence the black picture. (or a picture with a
screwy scan result)

Also, try using "CreateDIBSection" so you can use a BITMAPINFOHEADER
instance wich you
can type-cast to: "BITMAPINFO"  ... exemple:

bmp = CreateDIBSection
 (
  dc, (BITMAPINFO *)&RGB32BITSBITMAPINFO, DIB_RGB_COLORS, &m_pBits32, NULL,
0
 );

This allows you to specify to bit format you need. (god knows YUV is needs
it)

Also, the "BT YUV 411" format is supported by  the Microsoft Media Player so
you could create
a ATL class that would implement the interface of the MMplayer and subclass
it within the context
of another class based on 'CWindowImpl' that would be used to receive the
messages. In other words,
if it is indeed possible for you to recycle the MMPlayer, just contain it in
a CAxWindow and send a
WM_PAINT to the hWnd of the contained player, so the player can move a block
of bits to YOUR
DIB section when ever you need to. Once your DIB section is filled, you can
then BitBlit it anywhere :)

note : when in dought, blit a copy of the current buffer to the desktop,
just so you know your not
going insane :)

 HDC deskDC = GetWindowDC(GetDesktopWindow());
 BitBlt
 (
    deskDC, 0, 0, width, height,
    MyDIBdc, 0, 0, SRCCOPY
 );
 ReleaseDC(GetDesktopWindow(), deskDC);

I hope this helped a bit.
Best wishes in your quest for a wholesome solution ...



Sun, 19 Jun 2005 17:53:34 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How to display video from memory buffer efficiently?

2. Display DIB directly from video buffers using SDI

3. Trouble allocating memory for VIDEO BUFFER STORAGE.

4. Memory buffer to Video Card

5. how can i display bitmaps from buffer memory?

6. how can i display bitmaps from buffer memory?

7. Display a memory buffer (HTML) in CWebBrowser

8. Displaying an image in memory buffer using CVOImage

9. What is the quickest way to read/display video from memory buffer?

10. Detecting Memory Leaks efficiently

11. buffering, switching video pages.....

12. Accessing the VIDEO BUFFER.

 

 
Powered by phpBB® Forum Software