AMcap是一款用于捕获视频或从网络摄像头预览的应用。其源代码附带Microsoft Windows SDK作为示例。
我想(在amcap代码中绕过以下用户交互过程或者说想要)将其设置为默认值:
Ampcap菜单
Options
Video Capture Pin ...
Color Space/Compression: YUY2
Output size: 1600x1200
我有兼容的网络摄像头,可以在AMcap应用程序中手动更改为YUY2和1600x1200。
默认情况下为:
Color Space/Compression: MJPG
Output size: 160x120
我试图在整个项目中找到'YUY2'字符串,但我找不到它,所以我可以对它进行硬编码。它似乎是动态创建然后运行的;参考:文件amcap.cpp附近的行号3395。
答案 0 :(得分:1)
我有一些代码使用IID_IAMStreamConfig接口来设置相机图像大小。我没有使用它来设置图像格式,但我添加了我认为可以完成工作的代码。然而,这是未经测试的。
// get the number of formats and make sure the strutucre size matches
int count;
int size;
VIDEO_STREAM_CONFIG_CAPS caps;
pSC->GetNumberOfCapabilities(&count, &size);
if( sizeof(caps) != size )
{
// Error
}
AM_MEDIA_TYPE* mt_p = NULL;
hr = pSC->GetStreamCaps(0, &mt_p, (BYTE*)&caps);
if (hr != S_OK)
{
// Error
}
if ((mt_p->majortype != MEDIATYPE_Video) || (mt_p->formattype != FORMAT_VideoInfo))
{
// Error
}
VIDEOINFOHEADER* video_info_header_p = (VIDEOINFOHEADER *)mt_p->pbFormat;
video_info_header_p->bmiHeader.biWidth = 1600;
video_info_header_p->bmiHeader.biHeight = 1200;
// Code to change video format
// I think 16 is the right value for biBitCount, but I am not sure!!!!
video_info_header_p->bmiHeader.biCompression = MAKEFOURCC('Y','U','Y','2');
video_info_header_p->bmiHeader.biBitCount = 16;
hr = pSC->SetFormat(mt_p);
if (hr != S_OK)
{
// Error
}
if (mt_p->cbFormat != 0)
{
CoTaskMemFree((PVOID)mt_p->pbFormat);
mt_p->cbFormat = 0;
mt_p->pbFormat = NULL;
}
if (mt_p->pUnk != NULL)
{
// Unecessary because pUnk should not be used, but safest.
mt_p->pUnk->Release();
mt_p->pUnk = NULL;
}
您应该将代码放在amcap中的以下块之后:
if(hr != NOERROR)
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, gcap.pVCap,
IID_IAMStreamConfig, (void **)&pSC);
同样,这是未经测试的代码,但您可以尝试它,我希望它有所帮助。
答案 1 :(得分:1)
之后
if(hr != NOERROR)
{
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, gcap.pVCap,
IID_IAMStreamConfig, (void **)&gcap.pVSC);
if(hr != NOERROR)
{
// this means we can't set frame rate (non-DV only)
ErrMsg(TEXT("Error %x: Cannot find VCapture:IAMStreamConfig"), hr);
}
}
gcap.fCapAudioIsRelevant = TRUE;
粘贴:
CMediaType *pmt;
// default capture format
if(gcap.pVSC && gcap.pVSC->GetFormat((AM_MEDIA_TYPE**)&pmt) == S_OK)
{
// DV capture does not use a VIDEOINFOHEADER
if(pmt->formattype == FORMAT_VideoInfo)
{
pmt->SetType(&MEDIATYPE_Video);
pmt->SetFormatType(&FORMAT_VideoInfo);
pmt->SetSubtype(&MEDIASUBTYPE_YUY2);
pmt->SetTemporalCompression(FALSE);
VIDEOINFOHEADER* lpvihin = (VIDEOINFOHEADER*) pmt->pbFormat;
{
//DWORD fccYUY2 = 'YUY2' ;
//lpvihin->bmiHeader.biCompression =fccYUY2;
//'YUY2';// MAKEFOURCC('Y','U','Y','2');
//lpvihin->bmiHeader.biBitCount = 16;
lpvihin->bmiHeader.biWidth = 1600;// 960; //1600;
lpvihin->bmiHeader.biHeight = 1200;// 720; //1200;
lpvihin->bmiHeader.biSizeImage = 1600*1200*3;
hr = gcap.pVSC->SetFormat(pmt);
ResizeWindow(HEADER(pmt->pbFormat)->biWidth,
ABS(HEADER(pmt->pbFormat)->biHeight));
}
}
if(pmt->majortype != MEDIATYPE_Video)
{
// This capture filter captures something other that pure video.
// Maybe it's DV or something? Anyway, chances are we shouldn't
// allow capturing audio separately, since our video capture
// filter may have audio combined in it already!
gcap.fCapAudioIsRelevant = FALSE;
gcap.fCapAudio = FALSE;
}
DeleteMediaType(pmt);
}
非常感谢