I a trying to transcode an H264 video to HEVC using AVAssetWriter and it fails on iPhone 6s. Supposedly, the iPhone 6s supports HEVC for transcoding, not real-time video encoding. The same code works on iPhone 7 and above. If the iPhone 6s doesn't support the HEVC codec, how do we programmatically determine supported codecs at runtime?
let bitrate = trackBitrate / 5
let trackDimensions = trackSize
let compressionSettings: [String: Any] = [
AVVideoAverageBitRateKey: bitrate,
AVVideoMaxKeyFrameIntervalKey: 30,
AVVideoProfileLevelKey: kVTProfileLevel_HEVC_Main_AutoLevel
]
var videoSettings: [String : Any] = [
AVVideoWidthKey: trackDimensions.width,
AVVideoHeightKey: trackDimensions.height,
AVVideoCompressionPropertiesKey: compressionSettings
]
videoSettings[AVVideoCodecKey] = AVVideoCodecType.hevc
I ended up doing it this way
if #available(iOS 11.0, *), AVCaptureVideoDataOutput().availableVideoCodecTypes.contains(.hevc) {
// use .hevc settings here
} else {
// use .h264 settings here
}
The #available
check is needed to make the compiler happy if your app is targeting < iOS 11
You can get the iPhone model by the following code:
+ (NSString *) deviceModel {
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString: systemInfo.machine encoding: NSUTF8StringEncoding];
}
and determine if iPhone 6S disable H265 encode and iPhone7 above enable H265 encode.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.