2015-05-21 161 views
-2

如何將從相機膠捲中選擇的視頻保存到特定目的地?在我的情況下,我想將選定的視頻保存到destinationPath。另外我怎樣才能獲得視頻的持續時間?將視頻從相機膠捲保存到文檔

代碼:

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info 
{ 

    // Video Path 
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:@"yyyy-MM-dd_HH-mm-ss"]; 
    NSString *destinationPath = [documentsDirectory stringByAppendingFormat:@"/output_%@.mov", [dateFormatter stringFromDate:[NSDate date]]]; 

    // Save Video 

    // Get Video Duration   

    [self dismissViewControllerAnimated:YES completion:nil]; 

} 

回答

0
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info 
    { 
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; 
    AVAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil]; 
    // Video Path 
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:@"yyyy-MM-dd_HH-mm-ss"]; 
    NSString *destinationPath = [documentsDirectory stringByAppendingFormat:@"/output_%@.mov", [dateFormatter stringFromDate:[NSDate date]]]; 
    NSURL *url = [NSURL fileURLWithPath:destinationPath]; 
    // Save Video 
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetHighestQuality]; 
    exportSession.outputURL = url; 
    [exportSession exportAsynchronouslyWithCompletionHandler:nil]; 
    [binaryImageData writeToFile:destinationPath atomically:YES]; 
    // Get Video Duration   
    CMTime duration = avAsset.duration; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    } 
相關問題