Skip to content

Instantly share code, notes, and snippets.

@teaglin
Created October 16, 2018 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teaglin/f1e2e9478228311edc8663c6902c7d82 to your computer and use it in GitHub Desktop.
Save teaglin/f1e2e9478228311edc8663c6902c7d82 to your computer and use it in GitHub Desktop.
EncoderTest
//
// EncoderTest.swift
//
//
// Created by T
// Copyright © 2018 T. All rights reserved.
//
import VideoToolbox
import AVFoundation
var _Hardware_H264: Bool = false
var _Hardware_HEVC: Bool = false
public func canPerformHardwareH264Compression() -> Bool
{
// Hardware encode also depends on the image dimensions
var sessionRef: VTCompressionSession? = nil
var status = noErr
#if os(OSX)
let encoderSpecs = [kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder as String : true]
status = VTCompressionSessionCreate(nil, 512, 512, CMVideoCodecType(kCMVideoCodecType_H264), encoderSpecs as CFDictionary, nil, nil, nil, nil, &sessionRef)
#elseif os(iOS)
status = VTCompressionSessionCreate(nil, 512, 512, CMVideoCodecType(kCMVideoCodecType_H264), nil, nil, nil, nil, nil, &sessionRef)
#endif
_Hardware_H264 = (status == noErr)
if let s = sessionRef
{
VTCompressionSessionInvalidate(s)
}
//}
return _Hardware_H264
}
public func canPerformHardwareHEVCCompression() -> Bool
{
// Hardware encode also depends on the image dimensions
var sessionRef: VTCompressionSession? = nil
var status = noErr
#if os(OSX)
let encoderSpecs = [kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder as String : true]
status = VTCompressionSessionCreate(nil, 512, 512, CMVideoCodecType(kCMVideoCodecType_HEVC), encoderSpecs as CFDictionary, nil, nil, nil, nil, &sessionRef)
#elseif os(iOS)
status = VTCompressionSessionCreate(nil, 512, 512, CMVideoCodecType(kCMVideoCodecType_HEVC), nil, nil, nil, nil, nil, &sessionRef)
#endif
_Hardware_HEVC = (status == noErr)
if let s = sessionRef
{
VTCompressionSessionInvalidate(s)
}
//}
return _Hardware_HEVC
}
print("Can do hardware H264 encoding: \(canPerformHardwareH264Compression())")
print("Can do hardware HEVC encoding: \(canPerformHardwareHEVCCompression())")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment