Created
October 16, 2018 23:01
-
-
Save teaglin/f1e2e9478228311edc8663c6902c7d82 to your computer and use it in GitHub Desktop.
EncoderTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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