使用 AVFoundation 录制到电影文件时出错

发布于 2024-12-06 18:29:39 字数 1748 浏览 0 评论 0原文

这是一个奇怪的问题。我没有更改我的项目中涉及此的任何代码,但我的视频录制随机停止工作。当我尝试将电影保存到文件时,出现以下错误:

Error Domain=NSOSStatusErrorDomain Code=-12780“操作无法完成。(OSStatus 错误 -12780。)”

I使用以下代码开始捕获:

- (void)initVideoCapture {
self.captureSession = [[AVCaptureSession alloc] init];

AVCaptureDevice *videoCaptureDevice = [self frontFacingCameraIfAvailable];
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:nil];
[self.captureSession addInput:videoInput];

aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];    
[self.captureSession addOutput:aMovieFileOutput];
[self detectVideoOrientation:aMovieFileOutput];

[self.captureSession setSessionPreset:AVCaptureSessionPresetMedium];

[self.captureSession startRunning];

}

然后我从 viewController 调用此方法来开始录制:

- (void) startRecord {
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSString *newDateString = [outputFormatter stringFromDate:[NSDate date]];
[outputFormatter release];

NSString * fileString = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mov",newDateString]];
recordFileURL = [[NSURL alloc] initFileURLWithPath:fileString];        

[aMovieFileOutput startRecordingToOutputFileURL:recordFileURL recordingDelegate:self];

}

此时我在该函数中收到错误。

  • (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)连接错误:(NSError *)错误

真正奇怪的是它有时会随机工作。就像,我将编译该项目,它会 100% 运行。下次编译时,它的运行率为 0%。我可能做错了什么?有什么明显的吗?

This is a strange problem. I have not changed any code involving this in my project but my video recording has randomly stopped working. When I try to save to a movie to a file I get the following error:

Error Domain=NSOSStatusErrorDomain Code=-12780 "The operation couldn’t be completed. (OSStatus error -12780.)"

I start my capture with the following code:

- (void)initVideoCapture {
self.captureSession = [[AVCaptureSession alloc] init];

AVCaptureDevice *videoCaptureDevice = [self frontFacingCameraIfAvailable];
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:nil];
[self.captureSession addInput:videoInput];

aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];    
[self.captureSession addOutput:aMovieFileOutput];
[self detectVideoOrientation:aMovieFileOutput];

[self.captureSession setSessionPreset:AVCaptureSessionPresetMedium];

[self.captureSession startRunning];

}

I then call this method from the viewController to start recording:

- (void) startRecord {
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSString *newDateString = [outputFormatter stringFromDate:[NSDate date]];
[outputFormatter release];

NSString * fileString = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mov",newDateString]];
recordFileURL = [[NSURL alloc] initFileURLWithPath:fileString];        

[aMovieFileOutput startRecordingToOutputFileURL:recordFileURL recordingDelegate:self];

}

At this time I get the error in this function.

  • (void)captureOutput:(AVCaptureFileOutput *)captureOutput
    didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
    fromConnections:(NSArray *)connections error:(NSError *)error

What is really weird is that it randomly works sometimes. Like, I will compile the project and it will work 100% of the time. Next time I compile it will work 0%. What could I be doing wrong? Anything obvious?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚气少女 2024-12-13 18:29:40

当设备方向为 UIDeviceOrientationFaceUp、UIDeviceOrientationFaceDown 和 UIDeviceOrientationUnknown 时,我得到 -12780。由于录制视频的方向必须是纵向或横向,因此可能会出错。我必须编写一个快速方法来检查这三个,然后将它们转换为肖像。

I've gotten -12780 when the orientation of the device was UIDeviceOrientationFaceUp, UIDeviceOrientationFaceDown and UIDeviceOrientationUnknown. Since a recoded video's orientation has to be portrait or landscape, it'll error out on you. I had to write a quick method that checks for those three, and just translates them to portrait.

羁客 2024-12-13 18:29:40

这似乎是苹果的一个错误。我通过使用 AVAssetWriter 和 AVAssetWriterInput 解决了这个问题

this seems to be a bug with apple. i solved it by using AVAssetWriter and AVAssetWriterInput

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文