Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of video capture devices (web cameras) on Mac OS? (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

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 do such thing?


also from this series:

  • 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)?
like image 947
Rella Avatar asked Oct 13 '22 19:10

Rella


1 Answers

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
                }
            }
        }       
    }
like image 51
Ken Aspeslagh Avatar answered Nov 01 '22 09:11

Ken Aspeslagh