简体   繁体   English

AVAssetWriter 编解码器类型 hevc

[英]AVAssetWriter codec type hevc

I a trying to transcode an H264 video to HEVC using AVAssetWriter and it fails on iPhone 6s.我尝试使用 AVAssetWriter 将 H264 视频转码为 HEVC,但在 iPhone 6s 上失败。 Supposedly, the iPhone 6s supports HEVC for transcoding, not real-time video encoding.据说,iPhone 6s 支持 HEVC 转码,而不是实时视频编码。 The same code works on iPhone 7 and above.相同的代码适用于 iPhone 7 及更高版本。 If the iPhone 6s doesn't support the HEVC codec, how do we programmatically determine supported codecs at runtime?如果 iPhone 6s 不支持 HEVC 编解码器,我们如何在运行时以编程方式确定支持的编解码器?

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如果您的应用面向 < iOS 11,则需要#available检查以使编译器满意

You can get the iPhone model by the following code:您可以通过以下代码获取iPhone型号:

+ (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.并确定 iPhone 6S 是否禁用 H265 编码和 iPhone7 以上启用 H265 编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM