To save the recorded video

Please provide any sample code to save the video after recording. I can 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 (movieOutputPossible) {
            videoRecorder.mediaTypes = videoMediaTypesOnly;

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

but how to save it. Can someone tell.

Thanks in advance

+3
source share
1 answer
- (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 when you want to save the video in some path to a file that you can control. You can also save to "Saved Photos"

0
source

Source: https://habr.com/ru/post/1763029/


All Articles