Skip to content

Instantly share code, notes, and snippets.

@lewis262626
Created September 7, 2023 21:22
Show Gist options
  • Save lewis262626/4e03f8bbc2955b4c9f0c5b3ae093125c to your computer and use it in GitHub Desktop.
Save lewis262626/4e03f8bbc2955b4c9f0c5b3ae093125c to your computer and use it in GitHub Desktop.
Apple VideToolbox list supported hardware accelerated video encoders
#include <CoreFoundation/CoreFoundation.h>
#include <CoreMedia/CoreMedia.h>
#include <CoreVideo/CoreVideo.h>
#include <VideoToolbox/VideoToolbox.h>
#include <stdbool.h>
#include <stdio.h>
void printAvailableVideoEncoders();
int main(void) {
bool vp9hardware = VTIsHardwareDecodeSupported(kCMVideoCodecType_VP9);
printf("Is VP9 hardware decode: %d\n", vp9hardware);
printAvailableVideoEncoders();
return 0;
}
void printAvailableVideoEncoders() {
CFArrayRef encoderList = NULL;
CFDictionaryRef encoderDict = NULL;
CFStringRef encoderName = NULL;
CFBooleanRef isHardware = NULL;
OSStatus status = VTCopyVideoEncoderList(NULL, &encoderList);
if (status != 0) {
printf("Failed to fetch encoder list\n");
return;
}
CFIndex encoderCount = CFArrayGetCount(encoderList);
for (CFIndex i = 0; i < encoderCount; i++) {
encoderDict = CFArrayGetValueAtIndex(encoderList, i);
if (encoderDict) {
encoderName =
CFDictionaryGetValue(encoderDict, kVTVideoEncoderList_EncoderName);
isHardware = CFDictionaryGetValue(
encoderDict, kVTVideoEncoderList_IsHardwareAccelerated);
if (encoderName) {
printf("Encoder: %s\n",
CFStringGetCStringPtr(encoderName, kCFStringEncodingUTF8));
}
if (isHardware) {
if (CFBooleanGetValue(isHardware)) {
printf("Hardware Accelerated: Yes\n");
} else {
printf("Hardware Accelerated: No\n");
}
} else {
printf("Hardware Accelerated: No\n");
}
}
}
if (encoderList) {
CFRelease(encoderList);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment