Hi,
I'm developing a Directshow application to preview and capture videos from any video device (not using the LEAD Multimedia SDK).
I also have to grab single frames using the ISampleGrabber interface.
It worked great since I installed the LEAD MPEG4 Encoder.
During the installation, the default color space converter has been replaced with the LEAD Color Space Converter.
Now, when i grab a single frame, the image is corrupt (see attachment) but rendering the video works properly.
This is how I grab the frame:
HRESULT hr;
if(!m_mediaControl) {
return;
}
AM_MEDIA_TYPE MediaType;
m_sampleGrabber->GetConnectedMediaType(&MediaType);
VIDEOINFOHEADER *pVideoHeader = (VIDEOINFOHEADER*)MediaType.pbFormat;
long vSize = pVideoHeader->bmiHeader.biSizeImage;
long vWidth = pVideoHeader->bmiHeader.biWidth;
long vHeight = pVideoHeader->bmiHeader.biHeight;
CoTaskMemFree(MediaType.pbFormat);
long *buffer = new long[vSize];
int counter = 0;
while (++counter < 10) {
hr = m_sampleGrabber->GetCurrentBuffer(&vSize, buffer);
if (hr == VFW_E_WRONG_STATE)
Sleep(100);
else
break;
}
if(FAILED(hr)) {
return;
}
/* create BITMAP header */
HANDLE fh;
BITMAPFILEHEADER bmphdr;
DWORD nWritten;
memset(&bmphdr, 0, sizeof(bmphdr));
bmphdr.bfType = ('M' << 8) | 'B';
bmphdr.bfSize = sizeof(bmphdr) + sizeof(BITMAPINFOHEADER) + vSize;
bmphdr.bfOffBits = sizeof(bmphdr) + sizeof(BITMAPINFOHEADER);
/* write file*/
std::string fileName = "myfilename.avi";
fh = CreateFile(fileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(fh, &bmphdr, sizeof(bmphdr), &nWritten, NULL);
WriteFile(fh, &pVideoHeader->bmiHeader, sizeof(BITMAPINFOHEADER), &nWritten, NULL);
WriteFile(fh, buffer, vSize, &nWritten, NULL);
CloseHandle(fh);
Red Rabbit attached the following image(s):