【问题标题】:AVAssetExporter and UIImagePickerViewController VideoAVAssetExporter 和 UIImagePickerViewController 视频
【发布时间】:2013-11-20 23:36:18
【问题描述】:

我正在构建一个使用 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];


}

}

【问题讨论】:

    标签: ios uiimagepickercontroller avfoundation avcapturesession avassetexportsession


    【解决方案1】:

    我想出了解决办法。 以前当我创建我的 AVAssetExporter 时,我使用的是

    AVAssetURL
    

    为挑选的视频加载我的 NSURL。

    我改成

     AVAsset *videoasset = [AVAsset assetWithURL:videoURL];
    

    这解决了问题。

    我不确定为什么这更正了 UIImagePicker Picked Videos,而不是通过 AVfoundation 拍摄并保存到某个位置的视频。但更正了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多