zoukankan      html  css  js  c++  java
  • iOS CMSampleBuffer deep copy

    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

  • 相关阅读:
    vue脚手架配置插件image-webpack-loader 图片压缩
    umi-request 一个新的请求工具
    uniapp 中出现 wx.config is not a function
    项目跨域开启代理,前端不再需要找后端了!!!
    vue脚手架项目 以及react项目,webpack配置去除多余css样式
    uniapp 实现动态切换全局主题色
    uniapp 开发app 开启页面的下拉刷新无效
    C# ? 语法糖
    正则表达式
    nginx 自签名
  • 原文地址:https://www.cnblogs.com/mlj318/p/7478920.html
Copyright © 2011-2022 走看看