UIImagepickercontroller: converting to low quality video error

余生长醉 提交于 2019-12-10 15:27:11

问题


I am getting inputurl [info objectForKey:UIImagePickerControllerMediaURL] from UIImagepickercontroller's didFinishPickingMediaWithInfo's method.

NSURL *inputURL = [NSURL URLWithString:inputurlstring];

I am giving outputurl from this code

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

I used the following code to get low quality video

 - (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); 

    } 

    }]; 
}           

I am getting following error when I use large files only. Because when I use small size video file I did not get any 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}

回答1:


the above code is perfectly works. the only change is inputURL.

after I changed the inputURL to fileURLWithPath:

 NSURL *inputURL = [NSURL fileURLWithPath:inputurlstring];

Now its perfectly works.




回答2:


Instead of this

[info objectForKey:UIImagePickerControllerMediaURL];

use

NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];

AVAssetLibrary can access your video through its reference url only.



来源:https://stackoverflow.com/questions/14872953/uiimagepickercontroller-converting-to-low-quality-video-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!