Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SampleGrabber snapshot

169 views
Skip to first unread message

Gossamer

unread,
Sep 4, 2008, 8:57:55 AM9/4/08
to
Hi,

I have problem with samplegrabber filter. My graph looks like this:

AsyncReader->Mpeg2Demuxer(1)->InfTee(0)->H264 Decoder->Video render
->InfTee(1)->SampleGrabber

->Mpeg2Demuxer(0)->AAC Decoder->Audio Render

I get video decoded and displayed, but samplegrabber returns black image...
My snapshot function :

void CMFCDirectshowCtrl::SnapShot()
{

HRESULT hr = dsp->pSampleGrabber->SetBufferSamples(TRUE);
if (FAILED(hr))
return ;
hr = dsp->pSampleGrabber->SetOneShot(TRUE);
if (FAILED(hr))
return ;

AM_MEDIA_TYPE MediaType;
ZeroMemory(&MediaType,sizeof(MediaType));
hr = dsp->pSampleGrabber->GetConnectedMediaType(&MediaType);
if (FAILED(hr))
return;

VIDEOINFOHEADER *pVideoHeader = (VIDEOINFOHEADER*)MediaType.pbFormat;
if (pVideoHeader == NULL)
return;

BITMAPINFO BitmapInfo;
ZeroMemory(&BitmapInfo, sizeof(BitmapInfo));
CopyMemory(&BitmapInfo.bmiHeader, &(pVideoHeader->bmiHeader),
sizeof(BITMAPINFOHEADER));

void *buffer = NULL;
HBITMAP hBitmap = ::CreateDIBSection(0, &BitmapInfo, DIB_RGB_COLORS,
&buffer,
NULL, 0);
GdiFlush();

long buffsize = 0;
hr = dsp->pSampleGrabber->GetCurrentBuffer(&buffsize,(long *)buffer);

CBitmap bmp;
bmp.Attach(hBitmap);

BITMAP bitmap;
bmp.GetBitmap(&bitmap);

int size = bitmap.bmWidth*bitmap.bmHeight*bitmap.bmBitsPixel/8;
BYTE *lpBits = new BYTE[size];

::GetBitmapBits(hBitmap,size,lpBits);
WriteBmp("e:\\mreza\\output.bmp",&bitmap,(int*)lpBits);
delete []lpBits;
}
//-------------------------------------------------------------------------------

I dont receive any error msg, it just creates black image with correct image
size.
I've tried to create that graph in GraphEditor and when i execute it creates
one more H264 decoder after SampleGrabber. I tried to do same thing in my
code but put decoder before sample grabber, and than i get error msg when i
call GetConnectedMediaType function. Error is : 0x80040209 ...


Michel Roujansky - Senior developer, Starfish Technologies Ltd

unread,
Sep 4, 2008, 9:16:15 AM9/4/08
to
> //-------------------------------------------------------------------------­------

>
> I dont receive any error msg, it just creates black image with correct image
> size.
> I've tried to create that graph in GraphEditor and when i execute it creates
> one more H264 decoder after SampleGrabber. I tried to do same thing in my
> code but put decoder before sample grabber, and than i get error msg when i
> call GetConnectedMediaType function. Error is : 0x80040209 ...

1) your samplegrabber is in the wrong place. At this place you are
capturing compressed H264 stream.... You need to insert it after the
H264 decoder (set the samplegrabber capture mediatype as 24 or 32 bit
video).
2) after setting the parameters on the samplegrabber (one shot, etc, )
you must run the graph.

Gossamer

unread,
Sep 4, 2008, 9:50:46 AM9/4/08
to
Ok, now my graph branch for grabber looks like this:
AsyncReader->Mpeg2Demuxer(1)->InfTee(1)->H264 Decoder Sample->SampleGrabber

Application is first initialize graph, than it plays video in one screen
(thats why i use inftee, to split h264 on two decoders. one for playback and
other for snapshot). Than, when user clicks on snapshot button it calls
snapshot function as showed in previous post.

I have also put setbuffersamples and setoneshot function into intilialize
function, so graph is running before calling GetConnectedMediaType.
But i still get same error msg from that call.


"Michel Roujansky - Senior developer, Starfish Technologies Ltd"
<jeremi...@yahoo.com> wrote in message
news:bb0297d4-aa86-48c0...@s1g2000pra.googlegroups.com...

Gossamer

unread,
Sep 4, 2008, 10:02:27 AM9/4/08
to
Ok, i think i found where the problem is but dont have idea how to correct
it ...

EInfTeeOutGrabber = GetOutPin( pEInfTee, 1);
SampleDecoderInput = GetInPin (pH264DecoderSample, 0);
hr = pGraph->Connect( EInfTeeOutGrabber, SampleDecoderInput ); //this call
doesnt retun S_OK

Both pins are refering to some memory address, so on first sight looks ok.
Do i need to run graph to create second output of inf tee ?


"Gossamer" <cbin...@WITHOUT.gmail.com> wrote in message
news:g9op3p$oo4$1...@news1.carnet.hr...

Mitesh Shah

unread,
Sep 4, 2008, 7:23:21 PM9/4/08
to
1. What does your GetOutPin & GetInPin code look like?
2. Make sure that you receive different output pins for each decoder.
3. Is the InfTee filter correctly set up for 2 outputs?

Gossamer

unread,
Sep 8, 2008, 12:40:29 PM9/8/08
to
1.
HRESULT DSPlayer::GetPin( IBaseFilter * pFilter, PIN_DIRECTION dirrequired,
int iNum, IPin **ppPin)
{
CComPtr< IEnumPins > pEnum;
*ppPin = NULL;

HRESULT hr = pFilter->EnumPins(&pEnum);
if(FAILED(hr))
return hr;

ULONG ulFound;
IPin *pPin;
hr = E_FAIL;

while(S_OK == pEnum->Next(1, &pPin, &ulFound))
{
PIN_DIRECTION pindir = (PIN_DIRECTION)3;

pPin->QueryDirection(&pindir);
if(pindir == dirrequired)
{
if(iNum == 0)
{
*ppPin = pPin; // Return the pin's interface
hr = S_OK; // Found requested pin, so clear error
break;
}
iNum--;
}

pPin->Release();
}

return hr;
}
//-------------------------------------------------------------------------------
IPin * DSPlayer::GetInPin( IBaseFilter * pFilter, int nPin )
{
CComPtr<IPin> pComPin=0;
GetPin(pFilter, PINDIR_INPUT, nPin, &pComPin);
return pComPin;
}
IPin * DSPlayer::GetOutPin( IBaseFilter * pFilter, int nPin )
{
CComPtr<IPin> pComPin=0;
GetPin(pFilter, PINDIR_OUTPUT, nPin, &pComPin);
return pComPin;
}

2. I have two instances of Decoder interface so i guess it should be
different pins ..

3. I'm not sure about that .. do i need to run graph to set next output or ?

"Mitesh Shah" <ms...@tdvisioncorp.com> wrote in message
news:eSLmPVuD...@TK2MSFTNGP05.phx.gbl...

Mitesh Shah

unread,
Sep 8, 2008, 5:38:36 PM9/8/08
to
I don't think your GetPin code works correctly for more than one pin of the
same type.
For example, if you call GetPin once, connect that pin, and call it again,
wouldn't it retrieve the same pin? Does it ignore connected pins?
And if it does, do you call the second GetPin after connecting the first one
or before?


"Gossamer" <cbin...@REM--gmail.com> wrote in message
news:ga3ki1$b1r$1...@news1.carnet.hr...

Gossamer

unread,
Sep 9, 2008, 3:33:58 AM9/9/08
to
GetPin code should work well because when i dont use samplegrabber filter it
connects demux filter with input to video and audio decoder. Demuxer filter
has two output pins. But now i have put more checking in my code and it
seems that connect call for first output pin of inftee filter fails (first
output pin connects to video decoder for normal video playback, and second
one is for samplegrabber filter)
I' not sure what that means, do i need to somehow initialize inftee filter
before calling getoutput pin or what ?
The error code i'm receiving after connect call is: Couldn't create system
enumerator! hr=0x80040217

"Mitesh Shah" <ms...@tdvisioncorp.com> wrote in message

news:eWysVtfE...@TK2MSFTNGP03.phx.gbl...

The March Hare [MVP]

unread,
Sep 9, 2008, 11:45:19 AM9/9/08
to

On Tue, 9 Sep 2008 09:33:58 +0200, Gossamer wrote:

> The error code i'm receiving after connect call is: Couldn't create system
> enumerator! hr=0x80040217

That's not the error description.

HRESULT: 0x80040217 (2147746327)
Name: VFW_E_CANNOT_CONNECT
Description: No combination of intermediate filters could be found to make
the connection.
Severity code: Failed
Facility Code: FACILITY_ITF (4)
Error Code: 0x0217 (535)

Use the DxErr tool that comes with the DX SDK.

--
Please read this before replying:
1. Dshow & posting help: http://tmhare.mvps.org/help.htm
2. Trim & respond inline (please don't top post or snip everything)
3. Benefit others: follow up if you are helped or you found a solution

0 new messages