2016-06-16 2 views
1

AVCaptureVideoDataOutput에서 얻은 동영상을 AVAsset으로 저장하려면 아래의 writeVideoAtPathToSavedPhotosAlbum을 사용하십시오.사진 앨범에 저장 한 비디오의 정보를 URL로 가져옵니다.

NSString* filename = [NSString stringWithFormat:@"capture%d.mp4", _currentFile]; 
    NSString* path = [NSTemporaryDirectory() stringByAppendingPathComponent:filename]; 
    NSURL* url = [NSURL fileURLWithPath:path]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     [_encoder finishWithCompletionHandler:^{ 
      ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
      [library writeVideoAtPathToSavedPhotosAlbum:url completionBlock:^(NSURL *assetURL, NSError *error){ 
       NSLog(@"save completed"); 
      }]; 
     }]; 
    }); 

그러나 비디오를 저장 한 후 나는 우리가 UIImagePickerController을 사용하는 경우 다음과 같이 얻을 다시처럼 '동영상 정보 저장'을 싶어.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    [picker dismissViewControllerAnimated:YES completion:NULL]; 

    NSLog(@"there"); 

    // Handle a movie capture 
    NSString *type = info[UIImagePickerControllerMediaType]; 
    NSURL *videoURL = info[UIImagePickerControllerMediaURL]; 

    //do things with that info 
} 

답변

0

동영상을 저장하고 해당 동영상을 맞춤 앨범에 추가 한 다음 저장 위치를 ​​알려주는 코드입니다.

[library writeVideoAtPathToSavedPhotosAlbum:videoInputUrl completionBlock:^(NSURL *assetURL, NSError *error){ 
    if (error) { 

     NSLog(@"Video could not be saved"); 
    } 
    else{ 

      [library assetForURL:assetURL 
        resultBlock:^(ALAsset *asset) { 
         // assign the photo to the album 
         [groupToAddTo addAsset:asset]; 
         NSLog(@"Added Successfully %@ to %@", [[asset defaultRepresentation] filename], albumName); 
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Video Saved to xyz Album." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil, nil]; 
         [alert show]; 
        } 
        failureBlock:^(NSError* error) { 
         NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]); 
        }]; 
    } 
}]; 

희망이 도움이 당신에게 ... :)

관련 문제