[英]iOS Swift how to convert AVCaptureSynchronizedSampleBufferData to Data format or URL format
在我的应用程序中,我使用AVCaptureDataOutputSynchronizerDelegate
来录制通过摄像头录制的视频 output。 我得到的数据是AVCaptureSynchronizedSampleBufferData
,我必须将其转换为 Data 或 Url 格式,以便我能够播放视频预览。 我经历了很多关于 SO 的问题,但没有得到任何相关的代码。 请帮我转换它。 我正在分享我的代码和 output
代码:
extension VideoCapture: AVCaptureDataOutputSynchronizerDelegate
{
func dataOutputSynchronizer(_ synchronizer: AVCaptureDataOutputSynchronizer, didOutput synchronizedDataCollection: AVCaptureSynchronizedDataCollection)
{
guard let syncedVideoData = synchronizedDataCollection.synchronizedData(for: videoDataOutput) as? AVCaptureSynchronizedSampleBufferData else { return }
guard !syncedVideoData.sampleBufferWasDropped else {
print("dropped video:\(syncedVideoData)")
return
}
let videoSampleBuffer = syncedVideoData.sampleBuffer
//print("---", videoSampleBuffer)
let syncedDepthData = synchronizedDataCollection.synchronizedData(for: depthDataOutput) as? AVCaptureSynchronizedDepthData
var depthData = syncedDepthData?.depthData
if let syncedDepthData = syncedDepthData, syncedDepthData.depthDataWasDropped {
print("dropped depth:\(syncedDepthData)")
depthData = nil
}
let syncedMetaData = synchronizedDataCollection.synchronizedData(for: metadataOutput) as? AVCaptureSynchronizedMetadataObjectData
var face: AVMetadataObject? = nil
if let firstFace = syncedMetaData?.metadataObjects.first {
face = videoDataOutput.transformedMetadataObject(for: firstFace, connection: videoConnection)
}
guard let imagePixelBuffer = CMSampleBufferGetImageBuffer(videoSampleBuffer) else { fatalError() }
syncedDataBufferHandler?(imagePixelBuffer, depthData, face)
print("=====",syncedDataBufferHandler!)
}
}
我在控制台中得到了这个 output
dropped video:<AVCaptureSynchronizedSampleBufferData: 0x2808aa3a0>
我需要将此数据转换为 URL 或数据格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.