I am capturing video using following code:
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSo
We can use NSFileManager's moveItemAtPath:toPath:error: method to move the video file to our app's document directory. It's more efficient.
Also we should get the extension of the video file and use it as extension of our local video file name.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil] ;
if ([info[UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie]) {
// video
NSURL *url = [info[UIImagePickerControllerMediaType] ;
NSString *filePath = [url path] ;
NSString *pathExtension = [filePath pathExtension] ;
if ([pathExtension length] > 0) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;
NSString *documentsDirectory = [paths objectAtIndex:0] ;
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"temp.%@", pathExtension]] ;
NSError *error = nil ;
BOOL res = [[NSFileManager defaultManager] moveItemAtPath:filePath toPath:localFilePath error:&error] ;
if (!res) {
NSLog(@"%@", [error localizedDescription]) ;
}
}
}
}
It works for me.