错误代码-12743表示AVAssetWriter无法添加HDR元数据。要解决此问题,您可以尝试以下解决方法:
isHDRVideoSupported
属性来确定设备是否支持HDR。如果设备不支持HDR,则无法添加HDR元数据。if let device = AVCaptureDevice.default(for: .video), device.isHDRVideoSupported {
// HDR is supported
} else {
// HDR is not supported
}
availableVideoCodecTypes
属性获取设备支持的视频编解码器类型,并确保选择的编码器支持HDR。let videoDataOutput = AVCaptureVideoDataOutput()
let availableCodecs = videoDataOutput.availableVideoCodecTypes
// Check if any codec supports HDR
let hdrSupportedCodecs = availableCodecs.filter { codec in
let supportsHDR = codec.supportsHDR
return supportsHDR
}
// Select a codec that supports HDR
let selectedCodec = hdrSupportedCodecs.first
// Set the selected codec to output settings
videoDataOutput.setSampleBufferDelegate(self, queue: DispatchQueue.main)
videoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA,
AVVideoCodecKey: selectedCodec]
let writer = try AVAssetWriter(outputURL: outputURL, fileType: .mov)
let outputSettings = [
AVVideoCodecKey: selectedCodec,
AVVideoCompressionPropertiesKey: [
// Set HDR metadata
AVVideoHDRMetadataKey: hdrMetadata
]
]
let videoInput = AVAssetWriterInput(mediaType: .video, outputSettings: outputSettings)
writer.add(videoInput)
请注意,上述代码示例仅供参考,并且可能需要根据您的具体需求进行适当的修改。