标签:
视频分享
想实现iPhone手机拍摄一段视频,上传到云端分享给手机好友。
技术实现
视频压缩。iPhone拍摄的视频很大,几秒钟就几十兆文件了,需要做压缩,原来考虑用ffmpeg,安装起来比较复杂,网上也有很多教程,不过在通过appstore审核的时候有一定风险。
首先是点击开始录制的代码:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.videoQuality = UIImagePickerControllerQualityTypeIFrame960x540;//视频质量设置 imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.delegate = self; imagePicker.allowsEditing = YES; imagePicker.videoMaximumDuration = 300.0f;//设置最长录制5分钟 imagePicker.mediaTypes = [NSArray arrayWithObject:@"public.movie"]; [self presentViewController:imagePicker animated:YES completion:^{ }]; }
录制完之后的回调方法:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL]; NSLog(@"------%@",url); NSString *appDocumentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSURL *uploadURL = [NSURL fileURLWithPath:[[appDocumentPath stringByAppendingPathComponent:[self dateString]] stringByAppendingString:@".mp4"]]; // Compress movie first [self convertVideoToLowQuailtyWithInputURL:url outputURL:uploadURL]; [self dismissViewControllerAnimated:YES completion:^{ }]; }
标签:
原文地址:http://www.cnblogs.com/zhangjiayi/p/5030035.html