我正在使用AV基金会在Apple发布iOS 4.0之后通过遵循http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html给出的代码不断捕获图像
但是,当我调用"[session startRunning];"时 启动相机预览大约需要1-2秒.因此,这对最终用户来说是令人沮丧的,因为他需要等待一段时间.
有没有办法暂停会话而不是停止它,因为我可以在程序启动时启动会话并保持暂停直到用户导航到摄像机屏幕并开始在那里运行它?谢谢你的帮助.
我使用标准AVFoundation类来捕获视频和显示预览(http://developer.apple.com/library/ios/#qa/qa1702/_index.html)
这是我的代码:
- (void)setupCaptureSession {
NSError *error = nil;
[self setCaptureSession: [[AVCaptureSession alloc] init]];
self.captureSession.sessionPreset = AVCaptureSessionPresetMedium;
device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus] && [device lockForConfiguration:&error]) {
[device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
[device unlockForConfiguration];
}
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
error:&error];
if (!input) {
// TODO: Obs?uga b??du, gdy nie uda si? utworzy? wej?cia
}
[[self captureSession] addInput:input];
AVCaptureVideoDataOutput *output = [[[AVCaptureVideoDataOutput alloc] init] autorelease];
[[self captureSession] addOutput:output];
dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
output.videoSettings =
[NSDictionary …Run Code Online (Sandbox Code Playgroud) 我正在使用基于Apple的AppCam应用程序示例的AVCaptureSession克隆Apple的相机应用程序.问题是我无法在视频预览屏幕中看到焦点矩形.我使用以下代码来设置焦点,但仍未显示焦点矩形.
AVCaptureDevice *device = [[self videoInput] device];
if ([device isFocusModeSupported:focusMode] && [device focusMode] != focusMode) {
NSError *error;
printf(" setFocusMode \n");
if ([device lockForConfiguration:&error]) {
[device setFocusMode:focusMode];
[device unlockForConfiguration];
} else {
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) {
[delegate acquiringDeviceLockFailedWithError:error];
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用UIImagePickerController时,默认支持自动对焦,点击焦点,并且可以看到焦点矩形.是否无法使用AVCaptureSession在视频预览图层中显示焦点矩形?
我想对a执行一些操作CVPixelBufferRef并提出一个cv::Mat
CV_8UC1)我不确定最有效的顺序是什么,但是,我知道所有操作都可以在open:CV矩阵上使用,所以我想知道如何转换它.
- (void) captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
cv::Mat frame = f(pixelBuffer); // how do I implement f()?
Run Code Online (Sandbox Code Playgroud) 使用来自iOS7教程第22章的Ray Wenderlich的QRCode阅读器,我成功阅读了当前应用的QRCodes.我现在在成功读取QR码扩展它,我想存储stringValue的AVMetadataMachineReadableCodeObject被读取,原因请看一个新的视图,并使用在新的观点,即数据,或多或少究竟如何最QRCode的阅读器应用程序(如的RedLaser等...处理条形码和QRCodes.
但是,我打电话[captureSession stopRunning](这样它不再读取QR码并触发额外的段)并且还有10秒以上的挂起.我试图async按照这个问题实施一个电话,但无济于事.我也看过这些 SO 问题,但它们似乎不适合这个目的.
有谁知道如何删除这个悬挂?
这是代码:
#import "BMQRCodeReaderViewController.h"
#import "NSString+containsString.h"
#import "BMManualExperimentDataEntryViewController.h"
@import AVFoundation;
@interface BMQRCodeReaderViewController ()
<AVCaptureMetadataOutputObjectsDelegate>
@end
@implementation BMQRCodeReaderViewController {
AVCaptureSession *_captureSession;
AVCaptureDevice *_videoDevice;
AVCaptureDeviceInput *_videoInput;
AVCaptureVideoPreviewLayer *_previewLayer;
BOOL _running;
AVCaptureMetadataOutput *_metadataOutput;
}
- (void)setupCaptureSession { // 1
if (_captureSession) return;
// 2
_videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (!_videoDevice) {
NSLog(@"No video camera on this device!"); return;
}
// 3 …Run Code Online (Sandbox Code Playgroud) 首先,我想讨论一下在Snapchat中发生的情况.
在Snapchat中,当你开始录制视频和歌曲在后台运行时; 它允许在录制视频时继续播放该歌曲,并且在录制该视频后,您还可以在后台听到该歌曲.
我正在使用SCRecorder录制视频并使用我的自定义布局捕获图像.现在,我想做就像上面的场景,但问题是每当我开始录制背景歌曲中的视频停止播放.
SCRecorder AVCaptureSession用于录制视频.
那么我该如何解决这两个问题呢:
我注意到iPhone 6s上的AVCaptureDeviceFormat 1080p 60 fps不支持焦点像素,因此在光线不足的情况下,移动相机时相机仍会自动对焦。由于焦点搜寻是一个问题,因此这会导致视频录制出现问题。但是,本机摄像头应用程序在1080p 60 fps设置下可完美工作,而在同一场景下无需进行任何对焦搜索。本机相机如何实现它?我尝试在录制之前锁定焦点,还尝试将device.smoothAutoFocusEnabled设置为YES,但结果仍然不如本机Camera应用程序。有任何想法吗 ?
我有一个AVCaptureVideoPreviewLayer实例添加到视图控制器视图层次结构.
- (void) loadView {
...
self.previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:nil];
self.previewLayer.frame = self.view.bounds;
self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer addSublayer: _previewLayer];
// adding other UI elements
...
}
...
- (void) _setupPreviewLayerWithSession: (AVCaptureSession*) captureSession
{
self.previewLayer.session = self.captureManager.captureSession;
self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)
图层框架在-viewDidLayoutSubviews方法中更新.视图控制器方向被锁定UIInterfaceOrientationMaskLandscapeRight.
问题如下:


我尝试将视频图层方向更新为以下(没有结果):
AVCaptureSessionDidStartRunningNotification和UIApplicationDidBecomeActiveNotification通知-viewWillTransitionToSize:withTransitionCoordinator:方法时调用更新-viewWillAppear:该问题似乎与视频层方向本身无关,而是与查看层次结构布局有关.
更新:
正如所建议的那样,我也尝试更新设备方向更改的视频图层方向,但没有帮助.
我还注意到,问题主要发生在应用程序启动后,屏幕首次出现.在同一会话期间的后续屏幕演示中,问题的重现率非常低(类似于1/20).
我试图在AVFoundation输出上找到可接受的格式:
self.theOutput=[[AVCaptureVideoDataOutput alloc]init];
if ([self.theSession canAddOutput:self.theOutput])
[self.theSession addOutput:self.theOutput];
Run Code Online (Sandbox Code Playgroud)
然后我在之后插入断点并且:
po [self.theOutput availableVideoCVPixelFormatTypes]
Run Code Online (Sandbox Code Playgroud)
我明白了
(NSArray *) $5 = 0x2087ad00 <__NSArrayM 0x2087ad00>(
875704438,
875704422,
1111970369
)
Run Code Online (Sandbox Code Playgroud)
如何获取这些格式类型的字符串值?
谢谢
nsstring ios avcapture avcapturesession avcapturemoviefileoutput
所以我正在制作一个播放背景音频的视频捕捉应用程序(来自Spotify或Apple Music),我遇到一个小问题,当我在播放音频时打开我的应用程序时会出现小的音频中断.
这就是我允许播放背景音频的内容(位于didFinishLaunchingWithOptions我的AppDelegate班级中:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers
error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
Run Code Online (Sandbox Code Playgroud)
停止开始中断的任何线索?谢谢!!
编辑
我还应该在设置AVAudioSession后提到我正在设置我的AVCaptureSession.我初始化它然后设置属性.
self.session.usesApplicationAudioSession = YES;
self.session.automaticallyConfiguresApplicationAudioSession = NO;
Run Code Online (Sandbox Code Playgroud) avcapturesession ×10
ios ×7
avfoundation ×5
objective-c ×5
autofocus ×3
iphone ×3
audio ×1
avcapture ×1
c++ ×1
camera ×1
ios4 ×1
ios7 ×1
nsstring ×1
opencv ×1
rotation ×1