swift - 判断 iOS 设备是否支持 HEVC 编码

标签 swift encode codec hevc h.265

我的问题是我想使用 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)

参见 “Working with HEIF and HEVC” from WWDC 2017了解更多信息。

关于swift - 判断 iOS 设备是否支持 HEVC 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50956097/

相关文章:

ios - 如何处理Apple App Store "Limited time only"内购?

html - 通过根据 html 标签调整单元格大小,使用 UITextView 在 UITableViewCell 中显示 html [不是 UILabel!]

go - 如何在 golang 中以 UTF-8 编码 gob?

ios4 - MPMoviePlayerController 支持哪些格式?

ios - 如何在 iOS 中将 AAC 音频缓冲区解码为 PCM 缓冲区?

ios - swift : Button not responding to tap

iOS:如何写入项目中特定目录的文件?

go - 尝试在 golang 中解码 gob 时出现 "extra data in buffer"错误

c# - Encoding.ASCII.GetString 返回空白值(仅在 Windows 应用程序中)

java - Redisson:有没有一种方法可以对特定包中的类使用不同的编解码器,而不是全局配置的编解码器?