[英]Getting Exposure Time (EXIF) from CMSampleBuffer
I am trying to get the exposure time from an image captured using AVFoundation
. 我试图从使用
AVFoundation
捕获的图像中获取曝光时间。 When I followed the 2010's WWDC instruction about retrieving useful image metadata from CMSampleBuffer
like this: 当我按照2010年的WWDC指令进行有关从
CMSampleBuffer
检索有用的图像元数据时,如下所示:
-(void)captureStillImageWithCompletion:(completion_exp)completionHandler
{
AVCaptureConnection *connection = [stillImage connectionWithMediaType:AVMediaTypeVideo];
typedef void(^MyBufBlock)(CMSampleBufferRef, NSError*);
MyBufBlock h = ^(CMSampleBufferRef buf, NSError *err){
CFDictionaryRef exifAttachments = CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL);
if(exifAttachments){
NSLog(@"%@",exifAttachments);
}
if(completionHandler){
completionHandler();
}
};
[stillImage captureStillImageAsynchronouslyFromConnection:connection completionHandler:h];
}
I had an error on the CFDictionaryRef
line: 我在
CFDictionaryRef
行上出错:
Cannot initialize a variable of type'CFDictionaryRef (aka 'const __CFDictionary*') with an rvalue of type CFTypeRef..
So I followed a solution in the internet by casting it like this: 因此,我在互联网上跟踪了一个解决方案,方法如下:
CFDictionaryRef exifAttachments = (CFDictionaryRef)CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL);
And now it gives me another error: Undefined symbols for architecture armv7s 现在,它给了我另一个错误:体系结构armv7s的未定义符号
(Apple Mach-o Linker Error: "_kCGImagePropertyExifDictionary", referenced from:)
(Apple Mach-o Linker Error: "_CMGetAttachment", referenced from:)
I don't understand what went wrong with my program. 我不明白我的程序出了什么问题。 Anybody has any idea?
有人知道吗?
EDIT: You have to include ImageIO library and header to make this key work. 编辑:您必须包括ImageIO库和标头,以使此键起作用。 If you do not want to do that you can use this:
如果您不想这样做,可以使用以下命令:
There's something about the key I think. 我认为钥匙有些事情。 This worked for me:
这为我工作:
CFDictionaryRef exifAttachments = CMGetAttachment(buf, (CFStringRef)@"{Exif}", NULL);
Struggling with that too, I found out that you can simply cast the Exif attachment as an NSDictionary. 我也很努力地发现,您可以简单地将Exif附件转换为NSDictionary。 I hope this will help anyone.
我希望这会对任何人有帮助。
let metadata = CMGetAttachment(image, "{Exif}", nil ) as! NSDictionary
let buf = metadata.valueForKey("ExposureTime") as! NSNumber
let xposure:Double = buf.doubleValue
Modified version of Philli's answer for Swift4 : 修改后的版本Philli的答案Swift4:
var exifEd: Double?
if let metadata = CMGetAttachment(sampleBuffer, key: "{Exif}" as CFString, attachmentModeOut: nil) as? NSDictionary {
if let exposureDurationNumber = metadata.value(forKey: "ExposureTime") as? NSNumber {
exifEd = exposureDurationNumber.doubleValue
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.