如何获得在Mac OS的视频采集设备(网络摄像机)的列表? (C ++) [英] How to get a list of video capture devices (web cameras) on Mac OS? (C++)

查看:2492
本文介绍了如何获得在Mac OS的视频采集设备(网络摄像机)的列表? (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So all I need is simple - a list of currently avaliable video capture devices (web cameras). I need it in simple or C++ console app. By list I mean something like such console output:

1) Asus Web Camera
2) Sony Web Camera

所以它似乎很简单,但我有一个要求 - 利用原生操作系统的API尽可能 - 无需外部库 - 毕竟 - 我们想要的是打印出AA列表 - !不飞至月球)(和没有用客观-C的,请 - 纯C / C ++)

So It seems simple but I have one requirement - use of native OS apis as much as possible - no external libs - after all - all we want is to print out a a list - not to fly onto the moon!) (and no use of objective-C, please - pure C/C++)

如何做这种事?

也是从这个系列:

  • How to get a list of video capture devices on linux? and special details on getting cameras NAMES with correct, tested answers
  • How to get a list of video capture devices on Mac OS? with correct, not yet tested by my answers
  • How to get a list of video capture devices on windows? with correct, tested answers
  • How to get a list video capture devices NAMES using Qt (crossplatform)?

推荐答案

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

You need to use SGGetChannelDeviceList, which is part of the QuickTime C API. Each device can have multiple inputs. The proper way to parse it is like this:

    // 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
                }
            }
        }       
    }

这篇关于如何获得在Mac OS的视频采集设备(网络摄像机)的列表? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆