2013-02-14 36 views
5

Tôi đang nhận inputurl [info objectForKey:UIImagePickerControllerMediaURL] từ phương thức của UIImagepickercontroller's didFinishPickingMediaWithInfo.UIImagepickercontroller: chuyển sang lỗi video chất lượng thấp

NSURL *inputURL = [NSURL URLWithString:inputurlstring]; 

Tôi cho outputurl từ mã này

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

tôi đã sử dụng đoạn mã sau để có được video chất lượng thấp

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

    } 

    }]; 
}   

Tôi nhận được lỗi sau khi tôi sử dụng các file lớn duy nhất. Bởi vì khi tôi sử dụng tệp video kích thước nhỏ, tôi không nhận được bất kỳ lỗi nào.

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} 
+0

Bạn đang cắt tỉa video lớn? Dường như trang trí đang được lưu trữ trong một thư mục riêng tư. –

+0

Tôi đang chuyển đổi thành chất lượng thấp và tôi đang lưu trữ trong thư mục tài liệu @AlbertRenshaw – Suresh

+4

Tại sao bạn không bỏ qua chuyển đổi và đặt thuộc tính videoQuality trên UIImagePickerController thành UIImagePickerControllerQualityTypeLow? –

Trả lời

1

mã trên hoàn toàn hoạt động. thay đổi duy nhất là inputURL.

sau khi tôi thay đổi inputURL để fileURLWithPath:

NSURL *inputURL = [NSURL fileURLWithPath:inputurlstring]; 

Bây giờ nó hoàn toàn hoạt động.

0

Thay vì

[info objectForKey:UIImagePickerControllerMediaURL]; 

sử dụng này

NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL]; 

AVAssetLibrary có thể truy cập vào video của bạn thông qua chỉ reference url của nó.

Các vấn đề liên quan