使用avfoundation捕获图像,但不能捕获得太快 [英] Use avfoundation to capture image, but can not capture too quickly

查看:109
本文介绍了使用avfoundation捕获图像,但不能捕获得太快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用avfoundation来捕获图像,但是不能捕获得太快(我将间隔时间设置为0.1s).它说空样本缓冲区".问题是什么?谢谢.

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
 }]; 

*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* + [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:]-空样本缓冲区.'

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:] - NULL sample buffer.'

推荐答案

文档中的内容如下:

如果jpegSampleBuffer为NULL或不是JPEG格式,则此方法将引发NSInvalidArgumentException.

This method throws an NSInvalidArgumentException if jpegSampleBuffer is NULL or not in the JPEG format.

因此,要么您检查您的imageSampleBuffer中的NULL,要么我做了什么,我将整个内容包装在if语句检查中:CMSampleBufferIsValid(imageSampleBuffer),但并不真正知道那是否是正确的调用.文档有点稀疏.

So either you check your imageSampleBuffer for NULL 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.

这篇关于使用avfoundation捕获图像,但不能捕获得太快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆