从CMSampleBuffer获取曝光时间(EXIF)

问题描述 投票:1回答:3

我试图从使用AVFoundation捕获的图像中获取曝光时间。当我按照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];
}

我在CFDictionaryRef线上有一个错误:

Cannot initialize a variable of type'CFDictionaryRef (aka 'const __CFDictionary*') with an rvalue of type CFTypeRef..

所以我在互联网上遵循了一个解决方案:

CFDictionaryRef exifAttachments = (CFDictionaryRef)CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL);

现在它给了我另一个错误:架构armv7s的未定义符号

(Apple Mach-o Linker Error: "_kCGImagePropertyExifDictionary", referenced from:)
(Apple Mach-o Linker Error: "_CMGetAttachment", referenced from:)

我不明白我的程序出了什么问题。有人有什么想法吗?

ios camera metadata exif cmsamplebuffer
3个回答
2
投票

我也苦苦思索,我发现你可以简单地将Exif附件作为NSDictionary。我希望这会对任何人有所帮助。

let metadata = CMGetAttachment(image, "{Exif}", nil ) as! NSDictionary
let buf = metadata.valueForKey("ExposureTime") as! NSNumber
let xposure:Double = buf.doubleValue

2
投票

编辑:您必须包含ImageIO库和标题才能使此键正常工作。如果您不想这样做,可以使用:

关于我认为的关键是什么。这对我有用:

CFDictionaryRef exifAttachments = CMGetAttachment(buf, (CFStringRef)@"{Exif}", NULL);

1
投票

修改版的Philli's回答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
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.