0

Im構建一個使用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]; 


} 

}

回答

0

我想通了溶膠ution。 以前當我創造我AVAssetExporter我用

AVAssetURL 

加載我NSURL用於拾取視頻。

我改成了

AVAsset *videoasset = [AVAsset assetWithURL:videoURL]; 

和固定的問題。

我不知道爲什麼這糾正了UIImagePicker拾取的視頻,而不是通過AVfoundation拍攝並保存到某個位置的視頻。但糾正了我的問題。