Directshow中使用IAMStreamConfig接口改变摄像头分辨率
2010-12-30 11:39
405 查看
Directshow中使用IAMStreamConfig接口改变摄像头分辨率
【转自】http://blog.csdn.net/yanqiao1986/archive/2010/04/02/5445486.aspx实验室的江同学在一个有关摄像头的小项目中用到Directshow在.net平台上的封装DshowNet,该项目运行时在显示视频之前都会弹出一个视频属性配置窗口要求手动配置如分辨率等视频属性。江同学要求能够去除这个弹出窗口而在代码中设置分辨率等属性。
于是定位到源码当中的ShowCapPinDialog函数
view plaincopy to clipboardprint?
public static bool ShowCapPinDialog( ICaptureGraphBuilder2 bld, IBaseFilter flt, IntPtr hwnd )
{
int hr;
object comObj = null;
ISpecifyPropertyPages spec = null;
DsCAUUID cauuid = new DsCAUUID();
try
{
Guid cat = PinCategory.Capture;
Guid type = MediaType.Interleaved;
Guid iid = typeof(IAMStreamConfig).GUID;
hr = bld.FindInterface(ref cat, ref type, flt, ref iid, out comObj);
if (hr != 0)
{
type = MediaType.Video;
hr = bld.FindInterface(ref cat, ref type, flt, ref iid, out comObj);
if (hr != 0)
return false;
}
spec = comObj as ISpecifyPropertyPages;
if (spec == null)
return false;
hr = spec.GetPages(out cauuid);
hr = OleCreatePropertyFrame(hwnd, 30, 30, null, 1,
ref comObj, cauuid.cElems, cauuid.pElems, 0, 0, IntPtr.Zero);
return true;
}
catch (Exception ee)
{
Trace.WriteLine("!Ds.NET: ShowCapPinDialog " + ee.Message);
return false;
}
finally
{
if (cauuid.pElems != IntPtr.Zero)
Marshal.FreeCoTaskMem(cauuid.pElems);
spec = null;
if (comObj != null)
Marshal.ReleaseComObject(comObj); comObj = null;
}
}
在改源码中弹出的窗口是IAMStreamConfig的属性页。
于是想想使用IAMStreamConfig接口即能设定视频的分辨率。
搜了下发现http://topic.csdn.net/u/20080827/17/8b2dcced-316f-4b9d-80f6-e4776931ec73.html这个帖子中涉及到这个问题。12楼大虾的回帖很有参考价值。
因为摄像头只能支持固定的几种分辨率,所以必须枚举该摄像头支持的几种分辨率再判断该设置成哪种。
修改后的代码如下。
view plaincopy to clipboardprint?
public static bool ShowCapPinDialog( ICaptureGraphBuilder2 bld, IBaseFilter flt, IntPtr hwnd )
{
int hr;
object comObj = null;
IAMStreamConfig pamsc = null;
try
{
Guid cat = PinCategory.Capture;
Guid type = MediaType.Interleaved;
Guid iid = typeof(IAMStreamConfig).GUID;
hr = bld.FindInterface(ref cat, ref type, flt, ref iid, out comObj);
if (hr != 0)
{
type = MediaType.Video;
hr = bld.FindInterface(ref cat, ref type, flt, ref iid, out comObj);
if (hr != 0)
return false;
}
pamsc = comObj as IAMStreamConfig;
if (pamsc == null)
return false;
int count;
int size;
hr = pamsc.GetNumberOfCapabilities(out count, out size);
IntPtr pt = Marshal.AllocHGlobal(128);
for (int iFormat = 0; iFormat < count; iFormat++)
{
AMMediaType ammtp = new AMMediaType();
hr = pamsc.GetStreamCaps(iFormat, out ammtp, pt);
if (hr == 0)
{
VideoInfoHeader pvihdr = new VideoInfoHeader();
Marshal.PtrToStructure(ammtp.formatPtr, pvihdr);
if (pvihdr.BmiHeader.Width == 176)
{
pvihdr.AvgTimePerFrame = 10000000 / 15;
hr = pamsc.SetFormat(ammtp);
break;
}
}
}
return true;
}
catch (Exception ee)
{
Trace.WriteLine("!Ds.NET: ShowCapPinDialog " + ee.Message);
return false;
}
finally
{
pamsc = null;
if (comObj != null)
Marshal.ReleaseComObject(comObj);
comObj = null;
}
}
上面代码简单描述了IAMStreamConfig接口的用法,最后将摄像头属性设置为分辨率176*144的模式。
发表于 @ 2010年04月02日
相关文章推荐
- Directshow中使用IAMStreamConfig接口改变摄像头分辨率
- Windows CE6.0下使用IAMStreamConfig接口更改拍摄图像的分辨率
- Windows CE6.0下使用IAMStreamConfig接口更改拍摄图像的分辨率
- DirectShow中通过IAMStreamSelect接口实现多音轨切换
- IAMStreamConfig 设置问题/设置分辨率/准确获取filter
- DirectShow中通过IAMStreamSelect接口实现多音轨切换
- 使用DirectShow驱动摄像头
- [原创]自定义Config例子,使用IConfigurationSectionHandler 接口
- 使用DirectShow驱动摄像头
- 使用DirectShow驱动摄像头
- windows mobile中使用DirectShow开发视频流之从摄像头流中捕捉一张图片
- 使用directshow控制摄像头预览捕获视频
- 在Windows Mobile 5中使用DirectShow控制摄像头-转
- MTK 平台上查询当前使用的摄像头模组及所支持预览分辨率
- OpenCV摄像头采集图像问题及DirectShow的使用
- VC6 使用DirectShow做摄像头程序报错"incorrect version. Use the header that matches with the MIDL compiler."
- 在Windows Mobile 5中使用DirectShow控制摄像头
- 使用convert命令改变图片的分辨率
- 在Windows Mobile 5中使用DirectShow控制摄像头
- 使用DirectShow打开摄像头 MFC编程