7

我的问题是我想使用AVVideoCodecHEVC. 我知道它只在 iOS 11 中可用,但没有 A10 芯片的设备不支持它。

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

4

3 回答 3

15

您可以使用 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)

有关更多信息,请参阅WWDC 2017 中的“使用 HEIF 和 HEVC”

于 2018-06-20T20:16:30.853 回答
2

Apple 设备上的 HEVC 媒体

使用 iOS 11 或更高版本时,这些设备可以捕获 HEIF 或 HEVC 格式的媒体:

iPhone 7 or iPhone 7 Plus or later
iPad (6th generation)
iPad Pro (10.5 inch)
iPad Pro 12.9-inch (2nd generation)
于 2018-10-29T07:26:55.800 回答
0

使用 AVFoundation:

let isHEVC = AVOutputSettingsAssistant.availableOutputSettingsPresets().contains(.hevc3840x2160)

...或来自AVOutputSettingsPreset枚举的其他预设

于 2019-12-25T00:04:10.147 回答