开发者

To save recorded video

Please can anyone provide any sample code to save video after recording. I m able to record video using UIImagePickerController.

if (canShootVideo) {
        UIImagePickerController *videoRecorder = [[UIImagePickerController alloc] init];
        videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
        videoRecorder.delegate = self;

        NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
        NSArray *videoMediaTypesOnly = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF contains %@)", @"movie"]];
        BOOL movieOutputPossible = (videoMediaTypesOnly != nil);

        if (movieOutputPossib开发者_StackOverflowle) {
            videoRecorder.mediaTypes = videoMediaTypesOnly;

            [self presentModalViewController:videoRecorder animated:YES];           
        }
        [videoRecorder release];
    }

but how to save it. Can anyone please tell.

Thanks in advance


- (void)saveVideo:(NSURL *)videoUrl {
    NSData *videoData = [NSData dataWithContentsOfURL:videoUrl];
    [videoData writeToFile:@"YOUR_PATH_HERE" atomically:YES];
}    

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *type = [mediaDict objectForKey:UIImagePickerControllerMediaType];

    if ([type isEqualToString:(NSString *)kUTTypeVideo] || 
        [type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video
        NSURL *videoURL [mediaDict objectForKey:UIImagePickerControllerMediaURL];
        [self saveVideo:videoUrl];
    }

}

This is for the case you want to save the video into some file path that you can control. You can save into "Saved Photos" as well

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜