- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
AFTER 点击拍照后,我想锁定曝光并在曝光不再调整后立即关闭手电筒。所以,我添加了一个观察者来处理调整曝光:
- (IBAction)configureImageCapture:(id)sender
{
[self.session beginConfiguration];
[self.cameraController device:self.inputDevice exposureMode:AVCaptureExposureModeAutoExpose];
[self.cameraController device:self.inputDevice torchMode:AVCaptureTorchModeOn torchLevel:0.8f];
[self.session commitConfiguration];
[(AVCaptureDevice *)self.inputDevice addObserver:self forKeyPath:@"adjustingExposure" options:NSKeyValueObservingOptionNew context:MyAdjustingExposureObservationContext];
}
这是 observeValueForKeyPath 方法:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == MyAdjustingExposureObservationContext) {
if( [keyPath isEqualToString:@"adjustingExposure"] )
{
BOOL adjustingExposure = [ [change objectForKey:NSKeyValueChangeNewKey] isEqualToNumber:[NSNumber numberWithInt:1] ];
if (!adjustingExposure)
{
[(AVCaptureDevice *)self.cameraController.inputDevice removeObserver:self forKeyPath:@"adjustingExposure"];
if ([self.inputDevice isExposureModeSupported:AVCaptureExposureModeLocked]) {
dispatch_async(dispatch_get_main_queue(),
^{
NSError *error = nil;
if ([self.inputDevice lockForConfiguration:&error]) {
// 5) lock the exposure
[self.cameraController device:self.inputDevice exposureMode:AVCaptureExposureModeLocked];
// 6) turn off the Torch
[self.cameraController device:self.inputDevice torchMode:AVCaptureTorchModeOn torchLevel:0.0001f];
[self.inputDevice unlockForConfiguration];
}
});
}
}
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
@user3115647 发布了这个 information ,这正是我想要做的。
但我的照片是在手电筒关闭之前拍摄的。
这是我的 captureStillImageAsynchronouslyFromConnection:self.captureConnection completionHandler。此 block 发生在拍摄图像之后。 observeValueForKeyPath 应该在相机拍摄图像之前调整曝光时发生。但是在拍摄图像之前,我的手电筒并没有走低。这是一个时间问题,或者我没有正确设置相机配置。
- (void)captureImage
{
// configureImageCapture has already been done
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:self.captureConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
if (imageSampleBuffer != NULL)
{
// Log the image properties
CFDictionaryRef attachmentsRef = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
NSDictionary *properties = (__bridge NSDictionary *)(attachmentsRef);
NSLog(@"Image Properties => %@", (properties.count) ? properties : @"none");
最佳答案
通过使用闪光灯而不是手电筒,我得到了类似的结果。我也有一个 @"videoDevice.flashActive"
的观察者。我确实首先尝试使用 exposureModeLocked
,但它对我也不起作用。
下面的代码可能不能独立运行,而是根据我所做的进行了简化。
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void*)context
{
if (context == AdjustingExposureContext)
{
self.isAdjustingExposure = [change[NSKeyValueChangeNewKey] boolValue];
}
else if (context == FlashModeChangedContext)
{
self.isFlashActive = [change[NSKeyValueChangeNewKey] boolValue];
if (!self.flashActive)
{
[self captureImage]; // QUICKLY! capture 2nd image without
} // flash before exposure adjusts
}
if (!self.isAdjustingExposure && self.flashActive)
{
[self removeObserver:self forKeyPath:@"videoDevice.adjustingExposure" context:AdjustingExposureContext];
[self captureImage]; // capture 1st image with the flash on
}
}
现在在 captureStillImageAsynchronouslyFromConnection:
的回调中,
if (self.isFlashActive)
[self.videoDeviceInput.device setFlashMode:NO];
但是,如果您需要在不使用闪光灯的情况下以较低的曝光度拍摄多张照片,则此策略可能不起作用。
关于iphone - AVFoundation - 如何控制曝光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22029381/
我有一个 AVMutableVideoComposition,我正在使用 AVAssetExportSession 导出它,我正在尝试覆盖一个每秒更新一次的自定义时间戳。我应该使用 AVAssetWr
我是 MAC OSX 开发的新手。我想在 OSX 10.7 上使用 AVFoundation 将视频捕获为原始帧。我不明白为相机设备设置特定的视频分辨率,不知何故我使用 VideoSettings 设
使用 AVFoundation/QTKit 如何将多个视频设备同时录制到一个文件中? 我知道如何分别记录它们,但是尝试同时记录它们会导致诸如... “无法添加到 session 中,因为源和目标媒体类
我有一个关于 CoreAudio 和 AVFoundation 的问题。 我使用 CoreAudio 和 AUGraph 和 AudioUnit 构建了一个专业音频应用程序。 我想切换到看起来非常棒的
Apple Watch 能用吗AVFoundation ?更具体地说,可以AVAudioPlayer和 AVAudioRecorder工作? 我正在尝试制作一个应用程序,让您可以将声音录制到 Appl
Apple Watch 可以使用 AVFoundation 吗?更具体地说,AVAudioPlayer 和 AVAudioRecorder 可以工作吗? 我正在尝试制作一个应用程序,让您可以将声音录制
当我创建一个 iOS 项目和“Build Phases -> Link binary with Libraries”时,我添加了 AVFoundation.framework 库并使用 #import
我正在尝试创建一个格式正确的视频文件,用于 Apple 的 HTTP Live Streaming。这是创建文件的代码: // Init the device inputs AVCaptureDevi
我检查了答案,但找不到任何代码..我还登录以查看是否丢失了某些东西,但两个Logg都出现了,但声音没有播放...我也导入了 框架...我不知道我在做什么错我是新手,请帮忙...谢谢 - (void)v
对于这个问题,我只询问在没有外部库的情况下使用 Xcode 和 iOS 的可能性。我已经在探索在另一个 question 中使用 libtiff 的可能性. 问题 数周以来,我一直在筛选堆栈溢出,并为
我正在尝试采用不同的方法来组合视频。我正在为每个转换创建一个新轨道。 此代码的问题在于显示了第一个视频,而其他所有视频都是黑色的。 整个片段的音频覆盖都是正确的。看起来视频没有带入合成中,因为文件的大
回到使用AVAudioPlayer时,使用currentPosition来获取并设置位置,但是当使用AVAudioEngine和AVAudioPlayerNode时会使用什么呢? 最佳答案 AVAud
有人可以帮我将一个图标合并到一个视频中,该视频应该在视频播放时摆动。我已将动画添加到摆动图标,但只有静态图标会合并到视频中。如果有人可以帮助我,我将不胜感激。 我给你我正在使用的代码 //- (voi
Example 你好, 努力旋转此视频以显示在正确的方向并填满整个屏幕。 我无法使用 videocompisition 获取 avasset,但无法使其正常工作。 let videoAsset
如何一次在屏幕上显示多个相机预览? 如果我开始一个新的 AVCaptureSession,另一个就会停止。如果我使用与另一个 session 相同的 session 初始化一个新的 AVCapture
以下是我的录制按钮方法的内容。它创建了所需的文件,但无论我记录多长时间,创建的文件的长度始终为 4kb 和 0 秒,我无法弄清楚为什么它无效。对于averagePowerPerChannel,计量也返
我已经研究这个太久了。 我正在尝试获取 MacOS 网络摄像头数据并在网络摄像头输出的帧上运行 CIDetect。 我知道我需要: 连接 AVCaptureDevice (如输入)到AVCapture
我正在尝试从 CMSampleBufferRef 检索 CVPixelBufferRef,以便更改 CVPixelBufferRef 以动态覆盖水印。 我正在使用 CMSampleBufferGetI
捕获图像时,输出图像的颜色与我在预览图层上看到的颜色不同。出于某种原因,颜色略有变化。有没有人遇到过这个问题?我怎样才能解决这个问题? 当我从 didFinishProcessingPhotoSamp
对于 iOS5 来说可能是一个简单的问题他们将 AVFoundation 的eekToTime 方法更改为如下所示: [avPlayer seekToTime:startTime toleranceB
我是一名优秀的程序员,十分优秀!