How to save recorded video into photo album?
Following code is to save image took from camera into photo album.
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
image = [info objectForKey:UIImagePickerControllerEditedImage];
UIImageWriteToSavedPhotosAlbum(image, self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
}
How to save Recoded video into photoAlbum?
Solution 1:
Check Below code...
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.movie"]){
// Saving the video / // Get the new unique filename
NSString *sourcePath = [[info objectForKey:@"UIImagePickerControllerMediaURL"]relativePath];
UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil);
}
Solution 2:
- (void)saveMovieToCameraRoll
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:movieURL
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error)
[self showError:error];
else
[self removeFile:movieURL];
dispatch_async(movieWritingQueue, ^{
recordingWillBeStopped = NO;
self.recording = NO;
[self.delegate recordingDidStop];
});
}];
[library release];
}
This is the code snippet from apple example rosywriter. Sould work.
movieURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), @"Movie.MOV"]];
[movieURL retain];
The above lines to create file and path for the video.
- (void) startRecording
{
dispatch_async(movieWritingQueue, ^{
if ( recordingWillBeStarted || self.recording )
return;
recordingWillBeStarted = YES;
// recordingDidStart is called from captureOutput:didOutputSampleBuffer:fromConnection: once the asset writer is setup
[self.delegate recordingWillStart];
// Remove the file if one with the same name already exists
[self removeFile:movieURL];
// Create an asset writer
NSError *error;
assetWriter = [[AVAssetWriter alloc] initWithURL:movieURL fileType:(NSString *)kUTTypeQuickTimeMovie error:&error];
if (error)
[self showError:error];
});
}
This function is used to start recording video into that movieURL file using avassetwriter.