Skip to content

Instantly share code, notes, and snippets.

@jkuri
Created March 25, 2018 01:53
Show Gist options
  • Save jkuri/afb373b72138dc22aecd892f3af1e4e1 to your computer and use it in GitHub Desktop.
Save jkuri/afb373b72138dc22aecd892f3af1e4e1 to your computer and use it in GitHub Desktop.
Output all video capture devices with all video modes available on MacOS using AVFoundation framework

Output all video capture devices with all video modes available on MacOS using AVFoundation

Compile program using:

clang -o video_capture_devices video_capture_devices.m -framework Foundation -framework AVFoundation -framework CoreMedia

Sample output:

Device [0]: FaceTime HD Camera
Supported Video Modes:
  640x480 @ 30.000030
  640x480 @ 29.000049
  640x480 @ 28.000067
  640x480 @ 27.000027
  640x480 @ 26.000026
  640x480 @ 25.000000
  640x480 @ 24.000038
  640x480 @ 23.000032
  640x480 @ 22.000022
  640x480 @ 21.000021
  640x480 @ 20.000000
  640x480 @ 19.000029
  640x480 @ 18.000018
  640x480 @ 17.000009
  640x480 @ 16.000000
  640x480 @ 15.000015
  640x480 @ 14.000014
  640x480 @ 13.000013
  640x480 @ 12.000005
  640x480 @ 11.000011
  640x480 @ 10.000000
  640x480 @ 9.000001
  640x480 @ 8.000000
  640x480 @ 7.000002
  640x480 @ 6.000002
  640x480 @ 5.000000
  640x480 @ 4.000000
  640x480 @ 3.000000
  640x480 @ 2.000000
  640x480 @ 1.000000
  1280x720 @ 30.000030
  1280x720 @ 29.000049
  1280x720 @ 28.000067
  1280x720 @ 27.000027
  1280x720 @ 26.000026
  1280x720 @ 25.000000
  1280x720 @ 24.000038
  1280x720 @ 23.000032
  1280x720 @ 22.000022
  1280x720 @ 21.000021
  1280x720 @ 20.000000
  1280x720 @ 19.000029
  1280x720 @ 18.000018
  1280x720 @ 17.000009
  1280x720 @ 16.000000
  1280x720 @ 15.000015
  1280x720 @ 14.000014
  1280x720 @ 13.000013
  1280x720 @ 12.000005
  1280x720 @ 11.000011
  1280x720 @ 10.000000
  1280x720 @ 9.000001
  1280x720 @ 8.000000
  1280x720 @ 7.000002
  1280x720 @ 6.000002
  1280x720 @ 5.000000
  1280x720 @ 4.000000
  1280x720 @ 3.000000
  1280x720 @ 2.000000
  1280x720 @ 1.000000
  640x480 @ 30.000030
  640x480 @ 29.000049
  640x480 @ 28.000067
  640x480 @ 27.000027
  640x480 @ 26.000026
  640x480 @ 25.000000
  640x480 @ 24.000038
  640x480 @ 23.000032
  640x480 @ 22.000022
  640x480 @ 21.000021
  640x480 @ 20.000000
  640x480 @ 19.000029
  640x480 @ 18.000018
  640x480 @ 17.000009
  640x480 @ 16.000000
  640x480 @ 15.000015
  640x480 @ 14.000014
  640x480 @ 13.000013
  640x480 @ 12.000005
  640x480 @ 11.000011
  640x480 @ 10.000000
  640x480 @ 9.000001
  640x480 @ 8.000000
  640x480 @ 7.000002
  640x480 @ 6.000002
  640x480 @ 5.000000
  640x480 @ 4.000000
  640x480 @ 3.000000
  640x480 @ 2.000000
  640x480 @ 1.000000
  1280x720 @ 30.000030
  1280x720 @ 29.000049
  1280x720 @ 28.000067
  1280x720 @ 27.000027
  1280x720 @ 26.000026
  1280x720 @ 25.000000
  1280x720 @ 24.000038
  1280x720 @ 23.000032
  1280x720 @ 22.000022
  1280x720 @ 21.000021
  1280x720 @ 20.000000
  1280x720 @ 19.000029
  1280x720 @ 18.000018
  1280x720 @ 17.000009
  1280x720 @ 16.000000
  1280x720 @ 15.000015
  1280x720 @ 14.000014
  1280x720 @ 13.000013
  1280x720 @ 12.000005
  1280x720 @ 11.000011
  1280x720 @ 10.000000
  1280x720 @ 9.000001
  1280x720 @ 8.000000
  1280x720 @ 7.000002
  1280x720 @ 6.000002
  1280x720 @ 5.000000
  1280x720 @ 4.000000
  1280x720 @ 3.000000
  1280x720 @ 2.000000
  1280x720 @ 1.000000
Device [1]: HD Pro Webcam C920
Supported Video Modes:
  160x90 @ 30.000030
  160x90 @ 24.000038
  160x90 @ 20.000000
  160x90 @ 15.000015
  160x90 @ 10.000000
  160x90 @ 7.500002
  160x90 @ 5.000000
  160x120 @ 30.000030
  160x120 @ 24.000038
  160x120 @ 20.000000
  160x120 @ 15.000015
  160x120 @ 10.000000
  160x120 @ 7.500002
  160x120 @ 5.000000
  176x144 @ 30.000030
  176x144 @ 24.000038
  176x144 @ 20.000000
  176x144 @ 15.000015
  176x144 @ 10.000000
  176x144 @ 7.500002
  176x144 @ 5.000000
  320x180 @ 30.000030
  320x180 @ 24.000038
  320x180 @ 20.000000
  320x180 @ 15.000015
  320x180 @ 10.000000
  320x180 @ 7.500002
  320x180 @ 5.000000
  320x240 @ 30.000030
  320x240 @ 24.000038
  320x240 @ 20.000000
  320x240 @ 15.000015
  320x240 @ 10.000000
  320x240 @ 7.500002
  320x240 @ 5.000000
  352x288 @ 30.000030
  352x288 @ 24.000038
  352x288 @ 20.000000
  352x288 @ 15.000015
  352x288 @ 10.000000
  352x288 @ 7.500002
  352x288 @ 5.000000
  432x240 @ 30.000030
  432x240 @ 24.000038
  432x240 @ 20.000000
  432x240 @ 15.000015
  432x240 @ 10.000000
  432x240 @ 7.500002
  432x240 @ 5.000000
  640x480 @ 30.000030
  640x480 @ 24.000038
  640x480 @ 20.000000
  640x480 @ 15.000015
  640x480 @ 10.000000
  640x480 @ 7.500002
  640x480 @ 5.000000
  800x448 @ 30.000030
  800x448 @ 24.000038
  800x448 @ 20.000000
  800x448 @ 15.000015
  800x448 @ 10.000000
  800x448 @ 7.500002
  800x448 @ 5.000000
  864x480 @ 30.000030
  864x480 @ 24.000038
  864x480 @ 20.000000
  864x480 @ 15.000015
  864x480 @ 10.000000
  864x480 @ 7.500002
  864x480 @ 5.000000
  800x600 @ 30.000030
  800x600 @ 24.000038
  800x600 @ 20.000000
  800x600 @ 15.000015
  800x600 @ 10.000000
  800x600 @ 7.500002
  800x600 @ 5.000000
  1024x576 @ 30.000030
  1024x576 @ 24.000038
  1024x576 @ 20.000000
  1024x576 @ 15.000015
  1024x576 @ 10.000000
  1024x576 @ 7.500002
  1024x576 @ 5.000000
  960x720 @ 30.000030
  960x720 @ 24.000038
  960x720 @ 20.000000
  960x720 @ 15.000015
  960x720 @ 10.000000
  960x720 @ 7.500002
  960x720 @ 5.000000
  1280x720 @ 30.000030
  1280x720 @ 24.000038
  1280x720 @ 20.000000
  1280x720 @ 15.000015
  1280x720 @ 10.000000
  1280x720 @ 7.500002
  1280x720 @ 5.000000
  1600x896 @ 30.000030
  1600x896 @ 24.000038
  1600x896 @ 20.000000
  1600x896 @ 15.000015
  1600x896 @ 10.000000
  1600x896 @ 7.500002
  1600x896 @ 5.000000
  1920x1080 @ 30.000030
  1920x1080 @ 24.000038
  1920x1080 @ 20.000000
  1920x1080 @ 15.000015
  1920x1080 @ 10.000000
  1920x1080 @ 7.500002
  1920x1080 @ 5.000000
  160x90 @ 30.000030
  160x90 @ 24.000038
  160x90 @ 20.000000
  160x90 @ 15.000015
  160x90 @ 10.000000
  160x90 @ 7.500002
  160x90 @ 5.000000
  160x120 @ 30.000030
  160x120 @ 24.000038
  160x120 @ 20.000000
  160x120 @ 15.000015
  160x120 @ 10.000000
  160x120 @ 7.500002
  160x120 @ 5.000000
  176x144 @ 30.000030
  176x144 @ 24.000038
  176x144 @ 20.000000
  176x144 @ 15.000015
  176x144 @ 10.000000
  176x144 @ 7.500002
  176x144 @ 5.000000
  320x180 @ 30.000030
  320x180 @ 24.000038
  320x180 @ 20.000000
  320x180 @ 15.000015
  320x180 @ 10.000000
  320x180 @ 7.500002
  320x180 @ 5.000000
  320x240 @ 30.000030
  320x240 @ 24.000038
  320x240 @ 20.000000
  320x240 @ 15.000015
  320x240 @ 10.000000
  320x240 @ 7.500002
  320x240 @ 5.000000
  352x288 @ 30.000030
  352x288 @ 24.000038
  352x288 @ 20.000000
  352x288 @ 15.000015
  352x288 @ 10.000000
  352x288 @ 7.500002
  352x288 @ 5.000000
  432x240 @ 30.000030
  432x240 @ 24.000038
  432x240 @ 20.000000
  432x240 @ 15.000015
  432x240 @ 10.000000
  432x240 @ 7.500002
  432x240 @ 5.000000
  640x480 @ 30.000030
  640x480 @ 24.000038
  640x480 @ 20.000000
  640x480 @ 15.000015
  640x480 @ 10.000000
  640x480 @ 7.500002
  640x480 @ 5.000000
  800x448 @ 30.000030
  800x448 @ 24.000038
  800x448 @ 20.000000
  800x448 @ 15.000015
  800x448 @ 10.000000
  800x448 @ 7.500002
  800x448 @ 5.000000
  864x480 @ 24.000038
  864x480 @ 20.000000
  864x480 @ 15.000015
  864x480 @ 10.000000
  864x480 @ 7.500002
  864x480 @ 5.000000
  800x600 @ 24.000038
  800x600 @ 20.000000
  800x600 @ 15.000015
  800x600 @ 10.000000
  800x600 @ 7.500002
  800x600 @ 5.000000
  1024x576 @ 15.000015
  1024x576 @ 10.000000
  1024x576 @ 7.500002
  1024x576 @ 5.000000
  960x720 @ 15.000015
  960x720 @ 10.000000
  960x720 @ 7.500002
  960x720 @ 5.000000
#import <AVFoundation/AVFoundation.h>
#include <stdio.h>
typedef struct video_capabilities_t {
const char *resolution;
double framerate;
} video_capabilities_t;
typedef struct device_t {
int index;
const char *name;
video_capabilities_t caps[500];
int num_caps;
} device_t;
typedef struct devices_t {
device_t devices[50];
int num_devices;
} devices_t;
int main() {
devices_t devs;
devs.num_devices = 0;
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
int index = 0;
for (AVCaptureDevice *device in devices) {
devs.num_devices++;
const char *name = [[device localizedName] UTF8String];
index = [devices indexOfObject:device];
devs.devices[devs.num_devices - 1].index = index;
devs.devices[devs.num_devices - 1].name = malloc(30);
devs.devices[devs.num_devices - 1].num_caps = 0;
memcpy((void *)devs.devices[devs.num_devices - 1].name, name, strlen(name));
for (AVCaptureDeviceFormat *format in [device formats]) {
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions((CMVideoFormatDescriptionRef)[format formatDescription]);
for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
devs.devices[devs.num_devices - 1].num_caps++;
devs.devices[devs.num_devices - 1].caps[devs.devices[devs.num_devices - 1].num_caps - 1].resolution = malloc(30);
char res[15];
sprintf(res, "%dx%d", dimensions.width, dimensions.height);
memcpy((void *)devs.devices[devs.num_devices - 1].caps[devs.devices[devs.num_devices - 1].num_caps - 1].resolution, res, strlen(res));
devs.devices[devs.num_devices - 1].caps[devs.devices[devs.num_devices - 1].num_caps - 1].framerate = range.minFrameRate;
}
}
index++;
}
for (int i = 0; i < devs.num_devices; i++) {
device_t d = devs.devices[i];
fprintf(stderr, "Device [%d]: %s\n", d.index, d.name);
fprintf(stderr, "Supported Video Modes:\n");
for (int x = 0; x < d.num_caps; x++) {
video_capabilities_t cap = d.caps[x];
fprintf(stderr, " %s @ %f\n", cap.resolution, cap.framerate);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment