同时AVCaptureVideoDataOutput和AVCaptureMovieFileOutput [英] Simultaneous AVCaptureVideoDataOutput and AVCaptureMovieFileOutput
问题描述
我需要能够同时使用 AVCaptureVideoDataOutput
和 AVCaptureMovieFileOutput
。下面的代码工作,但是,视频录制不。在调用 startRecordingToOutputFileURL
之后,直接调用 didFinishRecordingToOutputFileAtURL
现在,如果我从
AVCaptureSession
中删除 AVCaptureVideoDataOutput
,只需注释掉以下行:
I need to be able to have AVCaptureVideoDataOutput
and AVCaptureMovieFileOutput
working at the same time. The below code works, however, the video recording does not. The didFinishRecordingToOutputFileAtURL
delegate is called directly after startRecordingToOutputFileURL
is called. Now if i remove AVCaptureVideoDataOutput
from the
AVCaptureSession
by simply commenting out the line:
[captureSession addOutput:captureDataOutput];
那么SampleBufferDelegate不会被调用(我需要它)。
The video recording works but then the SampleBufferDelegate is not called (which i need).
如何使用 AVCaptureVideoDataOutput
c $ c> AVCaptureMovieFileOutput 同时工作。
How can i go about having AVCaptureVideoDataOutput
and AVCaptureMovieFileOutput
working simultaneously.
- (void)initCapture {
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] error:NULL];
captureDataOutput = [[AVCaptureVideoDataOutput alloc] init];
[captureDataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
m_captureFileOutput = [[AVCaptureMovieFileOutput alloc] init];
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[captureDataOutput setVideoSettings:videoSettings];
captureSession = [[AVCaptureSession alloc] init];
[captureSession addInput:captureInput];
[captureSession addOutput:m_captureFileOutput];
[captureSession addOutput:captureDataOutput];
[captureSession beginConfiguration];
[captureSession setSessionPreset:AVCaptureSessionPresetLow];
[captureSession commitConfiguration];
[self performSelector:@selector(startRecording) withObject:nil afterDelay:10.0];
[self performSelector:@selector(stopRecording) withObject:nil afterDelay:15.0];
[captureSession startRunning];
}
- (void) startRecording
{
[m_captureFileOutput startRecordingToOutputFileURL:[self tempFileURL] recordingDelegate:self];
}
- (void) stopRecording
{
if([m_captureFileOutput isRecording])
[m_captureFileOutput stopRecording];
}
- (NSURL *) tempFileURL
{
NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"camera.mov"];
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:outputPath]) {
[[NSFileManager defaultManager] removeItemAtPath:outputPath error:nil];
[outputPath release];
return [outputURL autorelease];
}
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didStartRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections
{
NSLog(@"start record video");
}
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
{
NSLog(@"end record");
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
// do stuff with sampleBuffer
}
我应该添加我得到的错误: / p>
I should add i am getting the error:
Error Domain=NSOSStatusErrorDomain Code=-12780 "The operation couldn’t be completed. (OSStatus error -12780.)" UserInfo=0x23fcd0 {AVErrorRecordingSuccessfullyFinishedKey=false}
来自
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
干杯
推荐答案
一个苹果支持的工程师,他告诉我不支持同时 AVCaptureVideoDataOutput
+ AVCaptureMovieFileOutput
使用。我不知道他们是否会在未来支持它,但他使用了此时不支持这个词。
I have contacted an engineer at Apple's support and he told me that simultaneous AVCaptureVideoDataOutput
+ AVCaptureMovieFileOutput
use is not supported. I don't know if they will support it in the future, but he used the word "not supported at this time".
我鼓励你填写一个错误报告/ feature要求,就像我做的(bugreport.apple.com),因为他们测量人们想要什么东西有多难,我们也许可以看到这在不久的将来。
I encourage you to fill a bug report / feature request on this, as I did (bugreport.apple.com), as they measure how hard people want something and we perhaps can see this in a near future.
这篇关于同时AVCaptureVideoDataOutput和AVCaptureMovieFileOutput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!