AVFoundation을 사용하여 비디오를 캡처하는 iOS 비디오 응용 프로그램을 작성합니다. 앱을 시작할 때 AVCaptureSession을 만듭니다. 사용자가 녹화 버튼을 누르면 비디오가 캡처되어 "temp.MOV"이름 아래의 문서 폴더에 기록됩니다. 내 컴포지션을 병합하고 다시 포맷하는 내 AVAssetExporter에는 문제가 없습니다.AVAssetExporter 및 UIImagePickerViewController 비디오
그러나 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];
}
}