gpt4 book ai didi

ios - 如何创建样本缓冲区(CMSampleBufferRef)的实例?

转载 作者:行者123 更新时间:2023-12-01 23:12:54 25 4
gpt4 key购买 nike

我尝试编写ios相机,并获取了部分代码from apple :

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
// Create a UIImage from the sample buffer data
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];

< Add your code here that uses the image >

}

我需要从程序中的任何位置调用此函数。但它要求创建一个 (CMSampleBufferRef) 对象类型。怎么做?

我试着写一些类似的东西:

buf1 = [[CMSampleBufferRef alloc]init] 

但这是错误的方式。

最佳答案

这是我目前用于在 swift3 中模拟单元测试的 CMSampleBuffer 的代码片段:

fileprivate func getCMSampleBuffer() -> CMSampleBuffer {
var pixelBuffer : CVPixelBuffer? = nil
CVPixelBufferCreate(kCFAllocatorDefault, 100, 100, kCVPixelFormatType_32BGRA, nil, &pixelBuffer)

var info = CMSampleTimingInfo()
info.presentationTimeStamp = kCMTimeZero
info.duration = kCMTimeInvalid
info.decodeTimeStamp = kCMTimeInvalid


var formatDesc: CMFormatDescription? = nil
CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer!, &formatDesc)

var sampleBuffer: CMSampleBuffer? = nil

CMSampleBufferCreateReadyWithImageBuffer(kCFAllocatorDefault,
pixelBuffer!,
formatDesc!,
&info,
&sampleBuffer);

return sampleBuffer!
}

关于ios - 如何创建样本缓冲区(CMSampleBufferRef)的实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37594097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com