UIImagepickercontroller:转换为低质量视频错误

时间:2013-02-14 10:42:16

标签: iphone ios objective-c avfoundation

我从UIImagepickercontroller的[info objectForKey:UIImagePickerControllerMediaURL]方法获取inputurl didFinishPickingMediaWithInfo

NSURL *inputURL = [NSURL URLWithString:inputurlstring];

我从这段代码中给出了outputurl

        NSString  *documentsDirectory = [paths objectAtIndex:0];
        NSString *videoPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"capturedvideo.MOV"];
        NSURL *outputURL = [NSURL fileURLWithPath:videoPath];

我使用以下代码获取低质量视频

 - (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL 
    outputURL:(NSURL*)outputURL 
    handler:(void (^)(AVAssetExportSession*))handler 
    { 

    [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; 
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil]; 
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality]; 
    exportSession.outputURL = outputURL; 
    exportSession.outputFileType = AVFileTypeQuickTimeMovie; 

    [exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
    { 
    if (exportSession.status == AVAssetExportSessionStatusCompleted) 
    { 
    printf("completed\n"); 

    } 
    else 
    { 
    printf("error\n"); 
    NSLog(@"error is %@",exportSession.error); 

    } 

    }]; 
}           

仅在使用大文件时出现以下错误。因为当我使用小尺寸视频文件时,我没有收到任何错误。

Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo=0x616d890         
 {NSErrorFailingURLStringKey=/private/var/mobile/Applications/EE1E6701-EED0-4830-BD1D-7366680713C0/tmp//trim.7mL7VS.MOV, NSErrorFailingURLKey=/private/var/mobile/Applications/EE1E6701-EED0-4830-BD1D-7366680713C0/tmp//trim.7mL7VS.MOV, NSLocalizedDescription=unknown error, NSUnderlyingError=0x2d1460 "The operation couldn’t be completed. (OSStatus error -12935.)", NSURL=/private/var/mobile/Applications/EE1E6701-EED0-4830-BD1D-7366680713C0/tmp//trim.7mL7VS.MOV}

2 个答案:

答案 0 :(得分:1)

以上代码完美无缺。唯一的变化是inputURL。

我将inputURL更改为fileURLWithPath:

 NSURL *inputURL = [NSURL fileURLWithPath:inputurlstring];

现在它完美无缺。

答案 1 :(得分:0)

而不是这个

[info objectForKey:UIImagePickerControllerMediaURL];

使用

NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];

AVAssetLibrary只能通过reference url访问您的视频。