Suresh
Suresh

Reputation: 1015

UIImagepickercontroller: converting to low quality video error

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}

Upvotes: 5

Views: 1433

Answers (2)

Xcoder
Xcoder

Reputation: 1807

Instead of this

[info objectForKey:UIImagePickerControllerMediaURL];

use

NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];

AVAssetLibrary can access your video through its reference url only.

Upvotes: 0

Suresh
Suresh

Reputation: 1015

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.

Upvotes: 1

Related Questions