我正在构建一个使用AVFoundation捕获视频的iOS视频应用程序。 启动应用程序时,我创建一个AVCaptureSession,当用户按下“录制”按钮时,视频将被捕获并以“temp.MOV”名称写入Documents文件夹。 这对我的AVAssetExporter来说没有问题,它可以合并和重新格式化我的构图。
但是,如果我尝试使用UIImagePicker中的Video,AVAssetExporter会因错误而停止。
Export failed: Operation Stopped
Export failed: Error Domain=AVFoundationErrorDomain Code=-11841 "Operation Stopped" UserInfo=0x17db5100 {NSLocalizedDescription=Operation Stopped, NSLocalizedFailureReason=The video could not be composed.}
我想知道是否需要使用UIImagePicker的视频做一些特别的事情。
//从AVCaptureSession写的文件
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error{
NSLog(@"didFinishRecordingToOutputFileAtURL %@", outputFileURL);
//DOCUMENTS/temp.mov
self.movieFileURLForExport = outputFileURL;
}
UIImagePickerController视频导入代码
- (IBAction)iba_importVideo:(id)sender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [[NSArray alloc]
initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.delegate = self;
picker.allowsEditing = YES;
picker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:(NSString *)kUTTypeVideo] ||
[type isEqualToString:(NSString *)kUTTypeMovie]) {
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"PickedVideoURL %@", [videoURL absoluteString]);
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
NSString *dataPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/films"];
NSString *moviepath = [dataPath stringByAppendingString:@"/temp.mov"];
BOOL success = [videoData writeToFile:moviepath atomically:YES];
NSLog(@"Write Successs: %@", success ? @"YES" : @"NO");
[self checkDIRECTORYContents];
self.view.userInteractionEnabled = NO;
self.movieFileURLForExport = [NSURL fileURLWithPath:moviepath];
[picker dismissViewControllerAnimated:YES completion:nil];
}
}
答案 0 :(得分:0)
我找到了解决方案。 以前当我创建我的AVAssetExporter时,我正在使用
AVAssetURL
为已挑选的视频加载我的NSURL。
我把它改成了
AVAsset *videoasset = [AVAsset assetWithURL:videoURL];
并解决了这个问题。
我不知道为什么这会纠正UIImagePicker挑选的视频,而不是通过AVfoundation拍摄并保存到某个位置的视频。但纠正了我的问题。