iOS CMSampleBuffer deep copy
2017-09-05 15:38
387 查看
extension CVPixelBuffer { func copy() -> CVPixelBuffer { precondition(CFGetTypeID(self) == CVPixelBufferGetTypeID(), "copy() cannot be called on a non-CVPixelBuffer") var _copy : CVPixelBuffer? // var BytesAlignment:Int = 4 // let CFBytesAlignment = CFNumberCreate(kCFAllocatorDefault, .intType, &BytesAlignment)! let attribute:[String:Any] = [kCVPixelBufferMetalCompatibilityKey as String:kCFBooleanTrue] // kCVPixelBufferBytesPerRowAlignmentKey as String:CFBytesAlignment CVPixelBufferCreate( kCFAllocatorDefault, CVPixelBufferGetWidth(self), CVPixelBufferGetHeight(self), CVPixelBufferGetPixelFormatType(self), attribute as CFDictionary, &_copy) guard let copy = _copy else { fatalError() } CVPixelBufferLockBaseAddress(self, CVPixelBufferLockFlags.readOnly) CVPixelBufferLockBaseAddress(copy, CVPixelBufferLockFlags(rawValue: 0)) for plane in 0..<CVPixelBufferGetPlaneCount(self) { let dest = CVPixelBufferGetBaseAddressOfPlane(copy, plane) let source = CVPixelBufferGetBaseAddressOfPlane(self, plane) let height = CVPixelBufferGetHeightOfPlane(self, plane) let bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(self, plane) let bytesPerRowDst = CVPixelBufferGetBytesPerRowOfPlane(copy, plane) for h in 0..<height { memcpy(dest?.advanced(by:h*bytesPerRowDst), source?.advanced(by:h*bytesPerRow), bytesPerRow) } } CVPixelBufferUnlockBaseAddress(copy, CVPixelBufferLockFlags(rawValue: 0)) CVPixelBufferUnlockBaseAddress(self, CVPixelBufferLockFlags.readOnly) return copy } }
https://stackoverflow.com/questions/38335365/pulling-data-from-a-cmsamplebuffer-in-order-to-create-a-deep-copy http://blog.csdn.net/fernandowei/article/details/52180840
相关文章推荐
- 【iOS初学笔记】CMSampleBufferRef 转 UIImage
- CMSampleBufferRef与byte*互相转换(audio)
- iOS 使用 AVCaptureVideoDataOutputSampleBufferDelegate获取实时拍照的视频流
- 非常重要:如何创建一个CMSampleBuffer
- iOS 使用 AVCaptureVideoDataOutputSampleBufferDelegate获取实时拍照的视频流
- IOS Dev Intro - Create UImage from Sample Buffer Data
- CMSampleBufferRef转CIImage
- CMSampleBufferRef转换为nsdata对象
- IOS开发之深拷贝与浅拷贝(mutableCopy与Copy)详解(shallow copy and deep copy)
- CMSampleBufferRef TO NSData
- iOS AVCaptureVideoDataOutputSampleBufferDelegate 录制视频
- IOS 深拷贝和浅拷贝问题 (deep copy and shadow copy)
- CMSampleBufferRef转UIImage
- CMSampleBufferRef 与 UIImage 的转换
- 在iOS端使用AVSampleBufferDisplayLayer进行视频渲染
- 在iOS端使用AVSampleBufferDisplayLayer进行视频渲染
- CMSampleBufferRef 与 UIImage 的转换
- CMSampleBufferRef与byte*互相转换
- iOS如何将不可变变量改变成可变变量, deep copy objects into mutable
- CMSampleBufferRef与byte*互相转换(audio)