【问题标题】:How to get a list of video capture devices (web cameras) on Mac OS? (C++)如何在 Mac OS 上获取视频捕获设备(网络摄像头)的列表? (C++)
【发布时间】:2011-05-30 18:09:09
【问题描述】:

所以我需要的只是简单的 - 当前可用的视频捕获设备(网络摄像头)的列表。我在简单或 C++ 控制台应用程序中需要它。通过列表,我的意思是这样的控制台输出:

1) Asus Web Camera
2) Sony Web Camera

所以看起来很简单,但我有一个要求 - 尽可能使用本机 OS api - 没有外部库 - 毕竟 - 我们想要的只是打印出一个列表 - 而不是飞上月球!)(和请不要使用 Objective-C - 纯 C/C++)

这样的事情怎么办?


也来自这个系列:

【问题讨论】:

  • 不允许 glibc 让生活变得非常困难。进行直接系统调用(即 OS API)并不好玩。
  • @Ben Voigt:你说只使用 glibc 就可以了吗?
  • 理论上可以不使用库。可以在纯汇编中重写 OS-X。但是,这会浪费大量时间,因为您会花费大量时间在程序中复制库代码,而您本来可以与它链接。我的意思是说“我想最小化依赖关系”是可以的,但是说“根本没有外部库”有点荒谬。
  • @Ben:我认为他的意思是他想尽可能简单直接地做这件事,而不是使用第三方库,对吧?

标签: c++ c macos webcam device


【解决方案1】:

您需要使用 SGGetChannelDeviceList,它是 QuickTime C API 的一部分。每个设备可以有多个输入。解析它的正确方法是这样的:

    // first get a video channel from the sequence grabber

   ComponentDescription    theDesc;
   Component               sgCompID;
   ComponentResult         result;
   theDesc.componentType           = SeqGrabComponentType;
   theDesc.componentSubType        = 0L;
   theDesc.componentManufacturer   = 'appl';
   theDesc.componentFlags          = 0L;
   theDesc.componentFlagsMask      = 0L;   
   sgCompID = FindNextComponent (NULL, &theDesc);
   seqGrabber = OpenComponent (sgCompID);
   result = SGInitialize (seqGrabber);
   result = SGNewChannel (seqGrabber, VideoMediaType, &videoChannel);
   SGDeviceList  theDevices;
   SGGetChannelDeviceList(videoChannel, sgDeviceListDontCheckAvailability | sgDeviceListIncludeInputs, &theDevices);

    if (theDevices)
    {
        int theDeviceIndex;
        for (theDeviceIndex = 0; theDeviceIndex != (*theDevices)->count; ++theDeviceIndex)
        {
            SGDeviceName theDeviceEntry = (*theDevices)->entry[theDeviceIndex];
            // name of device is a pstring in theDeviceEntry.name

        SGDeviceInputList theInputs = theDeviceEntry.inputs;
            if (theInputs != NULL)
            {
                int theInputIndex;
                for ( theInputIndex = 0; theInputIndex != (*theInputs)->count; ++theInputIndex)
                {
                    SGDeviceInputName theInput = (*theInputs)->entry[theInputIndex];
                    // name of input is a pstring in theInput.name
                }
            }
        }       
    }

【讨论】:

  • 需要包含哪些内容?
  • QuickTime.h 您知道 Apple 网站上有很多示例代码可以帮助您入门。
  • 仅供参考,C API 已弃用。你应该使用 Objective-C 来处理这样的事情。
  • 你试过编译这样的代码吗?因为它似乎无法编译=(我该怎么办?你能提供可编译的C++代码吗?
【解决方案2】:

显然你可以在终端中使用system_profiler SPUSBDataType 这就是答案:

USB:

    USB 3.1 Bus:

      Host Controller Driver: AppleT8103USBXHCI

        USB Camera-OV580:

          Product ID: 0x058a
          Vendor ID: 0x05a9  (OmniVision Technologies, Inc.)
          Version: 1.00
          Speed: Up to 5 Gb/s
          Manufacturer: Omnivision Technologies, Inc.
          Location ID: 0x01200000 / 1
          Current Available (mA): 900
          Current Required (mA): 512
          Extra Operating Current (mA): 0

    USB 3.1 Bus:

      Host Controller Driver: AppleT8103USBXHCI

【讨论】:

    猜你喜欢
    • 2011-05-16
    • 2011-05-16
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    相关资源
    最近更新 更多