码迷,mamicode.com
首页 > 移动开发 > 详细

iOS视频拍摄压缩上传和播放

时间:2015-12-08 20:07:18      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:

视频分享

想实现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:^{
        
    }];
    
}

 

 

 

 

 

iOS视频拍摄压缩上传和播放

标签:

原文地址:http://www.cnblogs.com/zhangjiayi/p/5030035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!