Created
September 7, 2023 21:22
-
-
Save lewis262626/4e03f8bbc2955b4c9f0c5b3ae093125c to your computer and use it in GitHub Desktop.
Apple VideToolbox list supported hardware accelerated video encoders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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