我的问题是我想使用 AVVideoCodecHEVC
。我知道它只在 iOS 11 中可用,但没有 A10 芯片的设备不支持它。
所以,使用
if#available(iOS 11.0, *) { let self.codec = AVVideoCodecHEVC }
如果使用没有 A10 芯片的 iPhone 6 等设备,将抛出 Cannot Encode
错误。有没有人知道运行 iOS 11 的设备是否可以支持 HEVC?
最佳答案
您可以使用 VideoToolbox 检查 iOS 设备或 Mac 是否支持硬件编码:
/// Whether or not the current device has an HEVC hardware encoder.
public static let hasHEVCHardwareEncoder: Bool = {
let spec: [CFString: Any]
#if os(macOS)
spec = [ kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder: true ]
#else
spec = [:]
#endif
var outID: CFString?
var properties: CFDictionary?
let result = VTCopySupportedPropertyDictionaryForEncoder(width: 1920, height: 1080, codecType: kCMVideoCodecType_HEVC, encoderSpecification: spec as CFDictionary, encoderIDOut: &outID, supportedPropertiesOut: &properties)
if result == kVTCouldNotFindVideoEncoderErr {
return false // no hardware HEVC encoder
}
return result == noErr
}()
一种更高级别的检查方法是查看 AVAssetExportSession
是否支持其中一种 HEVC 预设:
AVAssetExportSession.allExportPresets().contains(AVAssetExportPresetHEVCHighestQuality)
关于swift - 判断 iOS 设备是否支持 HEVC 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50956097/