VMR7 and scrambled images

VMR7 and scrambled images

Post by ZillionDol » Thu, 20 Oct 2005 18:25:57

Hello,
the filter I was working on finally works - I just needed to preceed it
with an Avi Decompressor.
Now my graph is like this:

Capture-->Grabber-->AvIDec-->MyFilter-->VMR7

When I try it in GraphEdit, it works though the image is turned upside
down. When I try it in my application, it's not only upside down, it's
scrambled. This is what I do:

//Connection between Capture and Grabber
AM_MEDIA_TYPE* GrabMedia;
hr=pSrc->FindPin(reinterpret_cast<LPCWSTR>("0"),&capturePin);
CComQIPtr<IAMStreamConfig> pSC(capturePin);

pSC->GetFormat(&GrabMedia);
VIDEOINFOHEADER* pviGrab = (VIDEOINFOHEADER*)GrabMedia->pbFormat;
pviGrab->bmiHeader.biWidth = 704;
pviGrab->bmiHeader.biHeight = 576;
pviGrab->bmiHeader.biSizeImage =704*576*3;

GrabMedia->formattype = FORMAT_VideoInfo;
GrabMedia->subtype = MEDIASUBTYPE_YUY2;
GrabMedia->lSampleSize = pviGrab->bmiHeader.biSizeImage;

pSC->SetFormat(GrabMedia);

//grabber pin and its connection
grabberPinIn=GetPin(pGrabberBaseFilter, PINDIR_INPUT);

hr=pGraph->ConnectDirect(capturePin,grabberPinIn,GrabMedia);

//AVI Decompressor
IBaseFilter* pAvi;
hr=CoCreateInstance(CLSID_AVIDec, NULL, CLSCTX_INPROC,IID_IBaseFilter,
(LPVOID *)&pAvi);
pGraph->AddFilter(pAvi,L"AviFilter");

//My Filter - converts from VIDEOINFOHEADER to VIDEOINFOHEADER2
IBaseFilter* pConv;
hr=CoCreateInstance(CLSID_culo, NULL, CLSCTX_INPROC,IID_IBaseFilter,
(LPVOID *)&pConv);
pGraph->AddFilter(pConv,L"Conv");

//VMR7
IBaseFilter* pVMR;
hr=CoCreateInstance(CLSID_VideoMixingRenderer, NULL,
CLSCTX_INPROC,IID_IBaseFilter, (LPVOID *)&pVMR);
pGraph->AddFilter(pVMR,L"Render");

CComQIPtr<IVMRFilterConfig> vmrC;
pVMR->QueryInterface(IID_IVMRFilterConfig, (void**)&vmrC);
vmrC->SetNumberOfStreams(1);

CComQIPtr<IVMRMixerControl> pVmrMix;
pVMR->QueryInterface(IID_IVMRMixerControl,(void**)&pVmrMix);
pVmrMix->SetMixingPrefs(MixerPref_RenderTargetYUV422);

//Rendering
pBuilder->RenderStream(
0,
&MEDIATYPE_Video,
pGrabberBaseFilter,
pAvi,
pConv
);

pBuilder->RenderStream(
0,
&MEDIATYPE_Video,
pConv,
NULL,
pVMR
);

Any idea?
Thanks,
ZDS.

 
 
 

VMR7 and scrambled images

Post by Odie » Tue, 25 Oct 2005 08:25:09


Ignore that its GraphEdit / VM7. These are just different ways of rendering
the video. The problem is not in your main code but your filter.

These problems are typically caused in the code you used to copy the data
from the input pin to the output pin.
If the image is upside down -> Check for a negative height on the image
height.

If the image is scrambled then I'll guess its the stride. When given an
image of 320x200, the buffer that its in is not necessarily 320x200. It
could be 640x200 or something like that.
"The value returned in plStrideinBytes is the byte offset from the start of
one row to the start of the next row down. Thus, the address of the second
row from the top is pbTop + lStrideInBytes."

So you'll do something like this:
for t = 0 to height -1
{
copymemory(target, source, width*bits)
source = source + sourceStride
target = target + targetStride
}

For more info:
http://www.yqcomputer.com/

 
 
 

VMR7 and scrambled images

Post by ZillionDol » Tue, 25 Oct 2005 16:58:44

Thanks. I've added the GetVideoInfoParametes to my filter and I did it
from the class view, you know... right click, add new function,
completing the form etc. etc.
When compiling I get a *** error c2511, like I never declared it
which is absurd since the wizard adds it to the h file...
ZDS.
 
 
 

VMR7 and scrambled images

Post by Odie » Tue, 25 Oct 2005 18:30:07

"ZillionDollar *** " < XXXX@XXXXX.COM > wrote


Check out
DX9SDK\DirectShow\Samples\C++\DirectShow\DMO\DMOSample\util.cpp

For the source to this function.
 
 
 

VMR7 and scrambled images

Post by ZillionDol » Tue, 25 Oct 2005 23:53:24

I used the same code from the MSDN docs, but I got error 2511 until I
declard and implemented it as const!
Anyway, now in the Transform function I get the infos with
GetVideoInfoParameters and store them in appropriate variables. In the
Copy function I do this:

BYTE* in=pTop; //pTop is const
BYTE* out=pTopOut; //pTopOut too

for (DWORD y=0;y<height;y++) {

CopyMemory((PVOID)out,(PVOID)in,width*2);
in+=pStrideBytesIn;
out+=pStrideBytesOut;

}

width is the image's width, as taken from GetVideoInfoParameters;
pStrideBytesIn and pStrideBytesOut are the input and output stride
values.
Well, still it doesn't work...
ZDS.