使用avfoundation捕捉图像,但捕捉速度不能太快
我使用avfoundation来捕获图像,但是我不能捕获太快(我将间隔时间设置为0.1s)。它说“空样本缓冲区”。问题是什么?谢谢。
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
if (exifAttachments)
{
// Do something with the attachments.
// NSLog(@"attachements: %@", exifAttachments);
}
else
NSLog(@"no attachments");
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
//use the image
}];
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* +[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - NULL 示例缓冲区。”
I use avfoundation to capture images, but I can not capture too quickly(I set interval time to 0.1s). It says " NULL sample buffer". What is the problem? Thank you.
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
if (exifAttachments)
{
// Do something with the attachments.
// NSLog(@"attachements: %@", exifAttachments);
}
else
NSLog(@"no attachments");
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
//use the image
}];
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - NULL sample buffer.'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,它在文档中说:
因此,无论您检查
imageSampleBuffer
是否为NULL
,还是我所做的,我将整个事情包装在 if 语句检查中:CMSampleBufferIsValid(imageSampleBuffer)
但真的不知道这是否是正确的调用。文档有点稀疏。Well it says in the documentation:
So either you check your
imageSampleBuffer
forNULL
or what I did, I wrapped the entire thing in an if-statement checking:CMSampleBufferIsValid(imageSampleBuffer)
but don't really know if that is the correct call. Documentation is a bit sparse.现在对我有帮助的是
这里我使用一个辅助类来运行会话和一个计时器来获取图像帧。因此,首先我调用捕获图像函数,并在延迟 0.3 秒后调用。我正在使计时器无效并停止 AVCaptureSession 。
The thing helped me right now is
Here I am using a helper class to run the session and a timer to get the frames of image. So at first i call my capture image function and after a delay of 0.3 seconds. i am invalidating the timer and stopping the
AVCaptureSession
.