如何在Mac OS上获取video捕获设备(网络摄像头)列表? (C ++)

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

1) Asus Web Camera 2) Sony Web Camera 

所以看起来很简单,但我有一个要求 – 尽可能使用原生OS apis – 毕竟没有外部库 – 我们想要的就是打印出一个列表 – 不要飞到月球上!)(并没有使用Objective-C,please – pure C / C ++)

怎么办这样的事?


也来自这个系列:

  • 如何在linux上获取video捕获设备列表? 以及使用正确,经过测试的答案获取摄像机名称的特殊细节
  • 如何在Mac OS上获取video捕获设备列表? 正确的,尚未通过我的答案测试
  • 如何在Windows上获取video捕获设备列表? 正确,经过测试的答案
  • 如何使用Qt(跨平台)获取列表video捕获设备NAMES?

您需要使用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 } } } }