2

I have to save video to camera roll , video is in the form of nsdata . I know that is the method

UISaveVideoAtPathToSavedPhotosAlbum(videopath, self,  @selector(video:didFinishSavingWithError:contextInfo:), nil);
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {

    NSLog(@"is error?%@",error);
}

Also tried this but not working for me

 NSURL *movieURL = [NSURL fileURLWithPath:self.videoPath];

        NSLog(@"movie url== %@",self.videoPath);
                    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
                 [library writeVideoAtPathToSavedPhotosAlbum:movieURL
                                             completionBlock:^(NSURL *assetURL, NSError *error){NSLog(@"complete ");}];

This method accept path not nsdata . what should i do?

here Video path = @"/var/mobile/Applications/AE75E729-7F10-478B-9DAF-E730EB4231D1/Documents/Videos/12.mp4"

zohaibkhan
  • 227
  • 1
  • 2
  • 12

3 Answers3

0

I have seen a example [here] (https://github.com/versluis/Video-Recorder)

I am not tried it, but hope it will help you.

Download the code, and see the code in ViewController.m

NSURL *chosenMovie = [info objectForKey:UIImagePickerControllerMediaURL];

// save it to the documents directory
NSURL *fileURL = [self grabFileURL:@"video.mov"];
NSData *movieData = [NSData dataWithContentsOfURL:chosenMovie];
[movieData writeToURL:fileURL atomically:YES];

// save it to the Camera Roll
UISaveVideoAtPathToSavedPhotosAlbum([chosenMovie path], nil, nil, nil);

First create a file with NSData, and then path of that file is passed in the method UISaveVideoAtPathToSavedPhotosAlbum.

Here is also another link of [stackoverflow answer] (save mp4 video to device camera roll), that save video in .mp4 format.

Community
  • 1
  • 1
Nimisha Patel
  • 406
  • 5
  • 13
0
NSData *video_data=//Your Video NSData
    // Write it to cache directory
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"file1.mp4"];
    [video_data writeToFile:path atomically:YES];
    NSLog(@"Path:%@",path);
    // After that use this path to save it to PhotoLibrary
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:path] completionBlock:^(NSURL *assetURL, NSError
*error) {
        if (error) {
            NSLog(@"%@", error.description);
        }else {
            NSLog(@"Done :)");
        }
    }];
0

if ur VideoPath is Like

 UploadfilePathString = @"/var/mobile/Applications/AE75E729-7F10-478B-9DAF-E730EB4231D1/Documents/Videos/12.mp4"

then convert video path to NSData in this way

 NSError* error = nil;
 NSData *uploadFileData = [NSData dataWithContentsOfFile:UploadfilePathString  options:0 error:&error];
    NSLog(@"Data read from %@ with error: %@", uploadFileData, error);

output:it comes in data format then simply upload Data format to server . Thank you