0

In socket stream while receiving data, I am able to get NSMutableData into image and able to save in photos but not able to convert NSMutableData into video

for Image I'm doing

UIImage *imagess = [[UIImage alloc]initWithData:received];
//dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    UIImageWriteToSavedPhotosAlbum(imagess, nil, nil, nil);
}); 

Somebody help me for same thing for video ?

max_
  • 24,076
  • 39
  • 122
  • 211
Anoop
  • 409
  • 3
  • 13

1 Answers1

0

First you need to save the video as a local file.

NSData *receivedData;
…
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"movie.mp4"];
[receivedData writeToFile:path atomically:YES]; 

Then you can use UISaveVideoAtPathToSavedPhotosAlbum function to save the video file to Photo roll.

NSURL movieURL=[NSURL fileURLWithPath:path];

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(movieURL)){
    UISaveVideoAtPathToSavedPhotosAlbum(movieURL, nil, nil, nil);
}
cekisakurek
  • 2,474
  • 2
  • 17
  • 28
  • we need to create movie.mp4 file before doing this or it will creat automatically ? – Anoop Aug 20 '14 at 11:58
  • UISaveVideoAtPathToSavedPhotosAlbum function needs an file path URL. But in the example [receivedData writeToFile:path atomically:YES]; function is already creating the local file so you should be fine. – cekisakurek Aug 20 '14 at 12:00
  • file saving @cekisakurek but not finding in device ? can you suggest where it was stored ? – Anoop Aug 20 '14 at 12:26
  • if you NSLog(@"%@", movieURL); the file should be there. – cekisakurek Aug 20 '14 at 12:28
  • thanx @cekisakurek :) its work but can you suggest me that its saving in application document but can save directly to camera roll ? – Anoop Aug 20 '14 at 12:43