Closed GPX-NSlog closed 11 months ago
在不同版本的系统中AVVideoCodecType的默认值不同导致安卓端无法播放
AVVideoCodecType
// 在startRecord方法中查看默认的AVVideoCodecType if #available(iOS 11.0, *) { let outputSettings = [AVVideoCodecKey: AVVideoCodecType.h264] if let connection = movieFileOutput.connection(with: .video) { let dict1 = movieFileOutput.outputSettings(for: connection) print(dict) movieFileOutput.setOutputSettings(outputSettings, for: connection) let dict2 = movieFileOutput.outputSettings(for: connection) print(dict1) } }
输出结果:
dict1: ["AVVideoCompressionPropertiesKey": { AllowFrameReordering = 1; AllowOpenGOP = 1; AverageBitRate = 7651584; ExpectedFrameRate = 30; MaxKeyFrameIntervalDuration = 1; MaxQuantizationParameter = 41; MinimizeMemoryUsage = 1; Priority = 80; ProfileLevel = "HEVC_Main_AutoLevel"; RealTime = 1; RelaxAverageBitRateTarget = 1; SoftMinQuantizationParameter = 18; }, "AVVideoHeightKey": 1080, "AVVideoWidthKey": 1920, "AVVideoCodecKey": hvc1] dict2: ["AVVideoCompressionPropertiesKey": { AllowFrameReordering = 0; AverageBitRate = 15303168; ExpectedFrameRate = 30; H264EntropyMode = CABAC; MaxKeyFrameIntervalDuration = 1; Priority = 80; ProfileLevel = "H264_High_AutoLevel"; QuantizationScalingMatrixPreset = 3; RealTime = 1; }, "AVVideoWidthKey": 1920, "AVVideoCodecKey": avc1, "AVVideoHeightKey": 1080]
有两条评论,你少看了一条。 另一个地方也加上 @available(iOS 11.0, *) 就好了,本身这个属性就是给11.0之后的系统用的,这两个地方加下就好了
@available(iOS 11.0, *)
在不同版本的系统中
AVVideoCodecType
的默认值不同导致安卓端无法播放输出结果: