Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if iOS device can support HEVC encoding

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?

like image 297
Clayton J. Avatar asked Jun 20 '18 19:06

Clayton J.


People also ask

Is HEVC supported by iPhone?

Support for HEIF and HEVC is built in to iOS 11 and later and macOS High Sierra and later, allowing you to view, edit or duplicate this media in a variety of apps, including Photos, iMovie and QuickTime Player. On some older devices, support for HEVC is affected by the resolution and frame rate (fps) of the video.

Does iPhone 13 support HEVC?

Support for HEIF and HEVC is built into iOS 11 and later and macOS High Sierra and later, letting you view, edit, or duplicate this media in a variety of apps, including Photos, iMovie, and QuickTime Player.

Does iPad air support HEVC?

HEVC is supported on the following devices: iPhone 7/7 Plus or newer. iPad Pro or newer.


1 Answers

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.

like image 199
Ryder Mackay Avatar answered Sep 20 '22 23:09

Ryder Mackay