Determine if iOS device can support HEVC encoding
Asked Answered
S

3

8

My problem is I want to use AVVideoCodecHEVC. I know that it's only available in iOS 11, but device's without the A10 chip do not support it.

So, using if #available(iOS 11.0, *) { let self.codec = AVVideoCodecHEVC } Will throw Cannot Encode error if using a device like an iPhone 6 that doesn't have the A10 chip. Has anyone been able to figure out if a device running iOS 11, can support HEVC?

Subscribe answered 20/6, 2018 at 19:54 Comment(1)
What about availableVideoCodecTypes ?Particularity
F
16

You can check if an iOS device or Mac has hardware encoding support using VideoToolbox:

/// 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
}()

A much higher level way to check is to see if AVAssetExportSession supports one of the HEVC presets:

AVAssetExportSession.allExportPresets().contains(AVAssetExportPresetHEVCHighestQuality)

See “Working with HEIF and HEVC” from WWDC 2017 for more info.

Fluellen answered 20/6, 2018 at 20:16 Comment(2)
AVAssetExportSession.allExportPresets() worked perfectly! than you!Subscribe
I appreciate the depth of this answer, and the way it was written.Stoneham
M
3

HEVC media on Apple devices

When using iOS 11 or later, these devices can capture media in HEIF or HEVC format:

iPhone 7 or iPhone 7 Plus or later
iPad (6th generation)
iPad Pro (10.5 inch)
iPad Pro 12.9-inch (2nd generation)
Magniloquent answered 29/10, 2018 at 7:26 Comment(0)
R
1

Use AVFoundation:

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

...or other presets from the AVOutputSettingsPreset enum

Rinaldo answered 25/12, 2019 at 0:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.