这是我使用的代码
private func bufferToUInt(sampleBuffer: CMSampleBuffer) -> [UInt8] {
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
CVPixelBufferLockBaseAddress(imageBuffer, CVPixelBufferLockFlags(rawValue: 0))
let byterPerRow = CVPixelBufferGetBytesPerRow(imageBuffer)
let height = CVPixelBufferGetHeight(imageBuffer)
let srcBuff = CVPixelBufferGetBaseAddress(imageBuffer)
let data = NSData(bytes: srcBuff, length: byterPerRow * height)
CVPixelBufferUnlockBaseAddress(imageBuffer, CVPixelBufferLockFlags(rawValue: 0))
return [UInt8].init(repeating: 0, count: data.length / MemoryLayout<UInt8>.size)
}