参考:Configure the Video Quality - DirectShow
图像质量设置
- 逆光补偿
- 亮度
- 对比度
- 色调
- 饱和度
- 清晰度
- 伽马
- 白平衡
- 增益
相机控制
- 缩放
- 调焦
- 曝光
- 光圈
- 全景
- 倾斜
- 滚动
- 低照度补偿
// 视频质量设置
IAMVideoProcAmp *pProcAmp = NULL;
HRESULT hr = pDevFilter->QueryInterface(IID_IAMVideoProcAmp, (void **)&pProcAmp);
if (FAILED(hr))
return;
// 获取指定属性的调整值范围,调整步长,默认值,手动/自动调整,是否支持该属性
long min, max, step, deflt, flags;
hr = pProcAmp->GetRange(VideoProcAmpProperty::VideoProcAmp_BacklightCompensation, &min, &max, &step, &deflt, &flags);
if (hr == E_PROP_ID_UNSUPPORTED)
{
cout << "unsupport this property" << endl;
}
if (flags == VideoProcAmpFlags::VideoProcAmp_Flags_Auto) // 自动调整
{
}
// 获取指定属性当前的值,及调整方式(手动/自动)
long val;
hr = pProcAmp->Get(VideoProcAmpProperty::VideoProcAmp_BacklightCompensation, &val, &flags);
// 设置属性值,设置成手动调整
hr = pProcAmp->Set(VideoProcAmpProperty::VideoProcAmp_BacklightCompensation, val, VideoProcAmpFlags::VideoProcAmp_Flags_Manual);
pProcAmp->Release();
// 相机控制
IAMCameraControl *pCameraCtrl = NULL;
hr = pDevFilter->QueryInterface(IID_IAMCameraControl, (void **)&pCameraCtrl);
// 获取曝光设置范围,调整步长,默认值,手动/自动调整,是否支持该属性
hr = pCameraCtrl->GetRange(CameraControlProperty::CameraControl_Exposure, &min, &max, &step, &deflt, &flags);
if (hr == E_PROP_ID_UNSUPPORTED)
{
cout << "unsupport this property" << endl;
}
视频输出格式设置
参考:Configure the Video Output Format - DirectShow
PIN脚输出多媒体格式选择
视频格式:MJPG/YUY2
视频分辨率
帧率
如何设置?
使用IAMStreamConfig接口,IAMStreamConfig通常会在Capture Pin或Preview Pin中暴露出来;获取该接口有两种方式:
- 直接找到设备filter的输出pin,然后QueryInterface查找
- 使用ICaptureGraphBuilder2::FindInterface查找
// 查找输出设备的pin
IEnumPins *pDeviceEnumPins = NULL;
hr = pDeviceFilter->EnumPins(&pDeviceEnumPins);
IPin *pDeviceOutPin = NULL;
while (pDeviceEnumPins->Next(1, &pDeviceOutPin, NULL) == S_OK)
{
PIN_DIRECTION pdir;
pDeviceOutPin->QueryDirection(&pdir);
if (PIN_DIRECTION::PINDIR_OUTPUT == pdir)
{
break;
}
pDeviceOutPin->Release();
}
// 设置输出视频格式及参数
GUID pSelectFormat = FORMAT_VideoInfo;
GUID pSelectVideoType = MEDIASUBTYPE_MJPG;
LONG pSelectWidth = 1920L;
LONG pSelectHeight = 1080L;
// int pSelectFrameRate = 10;
AM_MEDIA_TYPE *pSelectMediaType = NULL;
AM_MEDIA_TYPE *pMediaType = NULL;
IAMStreamConfig *pStreamConfig = NULL;
hr = pDeviceOutPin->QueryInterface(IID_IAMStreamConfig, (void **)&pStreamConfig);
if (hr == S_OK)
{
int piCount, piSize;
hr = pStreamConfig->GetNumberOfCapabilities(&piCount, &piSize);
cout << "show media type : " << endl;
for (int i = 0; i < piCount; i++)
{
VIDEO_STREAM_CONFIG_CAPS scc;
pStreamConfig->GetStreamCaps(i, &pMediaType, reinterpret_cast<BYTE *>(&scc)); // 获取所有设备支持的多媒体格式
// hr = pStreamConfig->GetFormat(&pMediaType);
// pMediaType->formattype;
// ShowGUID(&pMediaType->formattype);
// ShowGUID(&pMediaType->majortype);
// ShowGUID(&pMediaType->subtype);
// ShowGUID(&pMediaType->subtype);
// pStreamConfig->SetFormat()
if (FORMAT_VideoInfo == pMediaType->formattype)
{
VIDEOINFOHEADER *pvideoInfo = (VIDEOINFOHEADER *)pMediaType->pbFormat;
cout << "format videoinfo frame type ";
if (MEDIASUBTYPE_YUY2 == pMediaType->subtype)
{
cout << "YUY2 , ";
}
else if (MEDIASUBTYPE_MJPG == pMediaType->subtype)
{
cout << "MJPG , ";
}
else
{
ShowGUID(&pMediaType->subtype);
}
cout << " height " << dec << pvideoInfo->bmiHeader.biHeight << " width " << pvideoInfo->bmiHeader.biWidth; // << endl;
cout << ", frame rate " << dec << 10000000 / pvideoInfo->AvgTimePerFrame << endl;
if (pSelectFormat == pMediaType->formattype && pSelectVideoType == pMediaType->subtype &&
pSelectHeight == pvideoInfo->bmiHeader.biHeight && pSelectWidth == pvideoInfo->bmiHeader.biWidth)
{
pSelectMediaType = pMediaType;
}
// cout << " frame size " << dec << pvideoInfo->bmiHeader.biSizeImage << endl;
// 修改帧率
// int _frame_rate = 5;
// pvideoInfo->AvgTimePerFrame = 10000000 / _frame_rate;
// pvideoInfo->dwBitRate = pvideoInfo->bmiHeader.biSizeImage * 8 * _frame_rate;
// pStreamConfig->SetFormat(pMediaType);
}
else if (FORMAT_VideoInfo2 == pMediaType->formattype)
{
VIDEOINFOHEADER2 *pvideoInfo = (VIDEOINFOHEADER2 *)pMediaType->pbFormat;
cout << "format videoinfo2 frame type ";
if (MEDIASUBTYPE_YUY2 == pMediaType->subtype)
{
cout << "YUY2 , ";
}
else if (MEDIASUBTYPE_MJPG == pMediaType->subtype)
{
cout << "MJPG , ";
}
else
{
ShowGUID(&pMediaType->subtype);
}
cout << " height " << dec << pvideoInfo->bmiHeader.biHeight << " width " << pvideoInfo->bmiHeader.biWidth; // << endl;
cout << ", frame rate " << dec << 10000000 / pvideoInfo->AvgTimePerFrame << endl;
if (pSelectFormat == pMediaType->formattype && pSelectVideoType == pMediaType->subtype &&
pSelectHeight == pvideoInfo->bmiHeader.biHeight && pSelectWidth == pvideoInfo->bmiHeader.biWidth)
{
pSelectMediaType = pMediaType;
}
}
else
{
cout << " other video format type ";
ShowGUID(&pMediaType->formattype);
}
}
}
hr = pStreamConfig->SetFormat(pSelectMediaType);
cout << " Set StreamConfig Media Format " << dec << hr << endl;
pStreamConfig->Release();