确定iOS设备是否可以支持HEVC编码

Cla*_* J. 3 encode codec h.265 hevc swift

我的问题是我想用AVVideoCodecHEVC.我知道它仅适用于iOS 11,但没有A10芯片的设备不支持它.

因此,如果使用像iPhone 6这样没有A10芯片的设备,则使用 if #available(iOS 11.0, *) { let self.codec = AVVideoCodecHEVC } Will throw Cannot Encode错误.有没有人能够弄清楚运行iOS 11的设备是否可以支持HEVC?

Ryd*_*kay 10

您可以使用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
}()
Run Code Online (Sandbox Code Playgroud)

更高级别的检查方法是查看是否AVAssetExportSession支持其中一个HEVC预设:

AVAssetExportSession.allExportPresets().contains(AVAssetExportPresetHEVCHighestQuality)
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅WWDC 2017中的"使用HEIF和HEVC".