CVPixelBufferCreate使用的坑

CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, imageSize.width,
                                      imageSize.height, kCVPixelFormatType_32ARGB, (__bridge CFDictionaryRef) options,
                                      &pxbuffer);

这个方法在使用的时候 一定要保存图片数据的宽度是16的整倍数,否则显示出的图片会变形

参考

### Stream Filters Implementation and Usage Stream filters allow developers to process data streams by applying transformations or modifications as the data passes through. This concept is widely used in various programming contexts including multimedia processing, network communications, and file operations. In the context of video processing with `AVCaptureVideoDataOutput`, stream filtering involves manipulating captured video frame buffers before further processing occurs[^1]. The delegate method receives each buffer, providing an opportunity to apply custom filter logic: ```objc - (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { // Apply custom filter here CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); // Example: Convert image format or perform color correction } ``` To implement a basic stream filter mechanism programmatically, one approach is creating dedicated classes responsible for specific types of transformations. For instance, implementing brightness adjustment could look like this: ```swift class BrightnessFilter { func apply(to pixelBuffer: CVPixelBuffer, level: Float) -> CVPixelBuffer? { var outputPixelBuffer: CVPixelBuffer? let status = CVPixelBufferCreate( kCFAllocatorDefault, CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer), CVPixelBufferGetPixelFormatType(pixelBuffer), nil, &outputPixelBuffer) guard status == kCVReturnSuccess else { return nil } // Perform actual brightness modification return outputPixelBuffer } } ``` The key aspect lies in ensuring all operations occur within a single-threaded environment provided by the specified serial dispatch queue when configuring `AVCaptureVideoDataOutput`. This guarantees ordered delivery and prevents race conditions during concurrent access scenarios. For more complex applications requiring multiple chained filters, consider designing modular components that can be easily connected together while maintaining thread safety throughout the pipeline.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值