gpt4 book ai didi

iphone - 同时 AVCaptureVideoDataOutput 和 AVCaptureMovieFileOutput

转载 作者:IT王子 更新时间:2023-10-29 08:01:01 24 4
gpt4 key购买 nike

我需要能够让 AVCaptureVideoDataOutputAVCaptureMovieFileOutput 同时工作。以下代码有效,但是视频录制无效。 didFinishRecordingToOutputFileAtURL 委托(delegate)在调用 startRecordingToOutputFileURL 之后直接调用。现在,如果我从中删除 AVCaptureVideoDataOutputAVCaptureSession 通过简单地注释掉以下行:

[captureSession addOutput:captureDataOutput];

视频录制有效,但随后未调用 SampleBufferDelegate(我需要)。

我怎样才能让 AVCaptureVideoDataOutputAVCaptureMovieFileOutput 同时工作。

- (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
}

我应该补充一下我收到的错误:

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

干杯

最佳答案

我联系了 Apple 支持的工程师,他告诉我不支持同时使用 AVCaptureVideoDataOutput + AVCaptureMovieFileOutput。不知道以后会不会支持,但是他用了“暂时不支持”这个词。

我鼓励您像我一样 (bugreport.apple.com) 就此填写错误报告/功能请求,因为它们衡量人们想要某样东西的难易程度,我们也许可以在不久的将来看到这一点。

关于iphone - 同时 AVCaptureVideoDataOutput 和 AVCaptureMovieFileOutput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3968879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com