Delphi 用 DirectShow 获取本机的视频摄像设备列表


本文整理自网络,侵删。

 
最近的项目用到一个视频模块,要求很简单,就是用本机的摄像头、摄像机或照相机实时拍照获取照片,用 VFW 很容易实现了,不过 avicap 中的函数 capGetDriverDescription 在获取驱动名称的时候,只能获取基本接口驱动的名称 Microsoft WDM Image Capture (Win32),无法获取真实设备的名称,而且没有其它相关函数来实现此功能。

视频相关的开发现在首选 DirectShow,用 Delphi + DirectShow 很容易就实现了:

unit DirectShow;
interface
uses
    Windows, Messages, SysUtils, Variants, Classes, ActiveX;
const
    CLSID_SystemDeviceEnum: TGUID = (D1:$62BE5D10;D2:$60EB;D3:$11D0;D4:($BD,$3B,$00,$A0,$C9,$11,$CE,$86));
    CLSID_VideoInputDeviceCategory: TGUID = (D1:$860BB310;D2:$5D01;D3:$11D0;D4:($BD,$3B,$00,$A0,$C9,$11,$CE,$86));
    IID_ICreateDevEnum: TGUID = '{29840822-5B84-11D0-BD3B-00A0C911CE86}';
    IID_IPropertyBag: TGUID = '{55272A00-42CB-11CE-8135-00AA004BB851}';
type
    ICreateDevEnum = interface(IUnknown)
        ['{29840822-5B84-11D0-BD3B-00A0C911CE86}']
        function CreateClassEnumerator(const clsidDeviceClass: TGUID;
        out ppEnumMoniker: IEnumMoniker; dwFlags: DWORD): HResult; stdcall;
    end;
procedure GetVideoDeviceList(List: TStrings);
implementation
procedure GetVideoDeviceList(List: TStrings);
var
    SysDevEnum: ICreateDevEnum;
    EnumCat: IEnumMoniker;
    Moniker: IMoniker;
    PropBag: IPropertyBag;
    Fetched: LongInt;
    VarName: OleVariant;
begin
    CoCreateInstance(CLSID_SystemDeviceEnum, nil, CLSCTX_INPROC, IID_ICreateDevEnum, SysDevEnum);
    SysDevEnum.CreateClassEnumerator(CLSID_VideoInputDeviceCategory, EnumCat, 0);
    List.Clear;
    while EnumCat.Next(1, Moniker, @Fetched) = S_OK do begin
        Moniker.BindToStorage(nil, nil, IID_IPropertyBag, PropBag);
        PropBag.Read('FriendlyName', VarName, nil);
        List.Add(VarName);
        PropBag := nil;
        Moniker := nil;
    end;
    EnumCat := nil;
    SysDevEnum := nil;
end;
end.

相关阅读 >>

Delphi 获取含跨域网址的框架网页的源码

Delphi 2009 之 tbuttonededit

Delphi的几种类型转换

Delphi xe5 为android增加启动图片显示

Delphi 根据字符串找到函数并执行

Delphi提示‘error loading midas.dll’的原因及解决方案

Delphi几个进制相关的代码(hextoint、hextoasc)

Delphi twebbrowser也能响应回车键

Delphi 获取网卡信息

Delphi 搭配hotkeyedit控件来解决问题

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...