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 行。
最佳答案
我有一些代码使用 IID_IAMStreamConfig 接口(interface)来设置相机图像大小。我没有用它来设置图像格式,但我添加了我认为可以完成这项工作的代码。然而,它未经测试。
// 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 中的以下 block 之后:
if(hr != NOERROR)
hr = gcap.pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video, gcap.pVCap,
IID_IAMStreamConfig, (void **)&pSC);
同样,这是未经测试的代码,但您可以尝试一下,希望对您有所帮助。
关于.net - 如何设置amcap的默认色彩空间为YUY2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/897300/