UIImagePickerController 视频录制操作,视频大小,时间长度
一:使用 iOS 系统 UIImagePickerController
- 获取视频大小
- 获取视频长度
- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view. self.title = @"AVVideo Demo";CGRect theFrame = CGRectMake(10, 15, 130, 20);[self addOpBtnWith:@"pick Video" frame:theFrame action:@selector(pickVideoTaped)];theFrame = CGRectMake(150, 15, 130, 20);[self addOpBtnWith:@"转成mp4" frame:theFrame action:@selector(revoverToMp4)];}#pragma mark action//转换格式为 mp4 - (void)revoverToMp4 {AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:_videoURL options:nil];NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]){AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAssetpresetName:AVAssetExportPresetHighestQuality];NSDateFormatter* formater = [[NSDateFormatter alloc] init];[formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];NSString* _mp4Path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/output-%@.mp4", [formater stringFromDate:[NSDate date]]];exportSession.outputURL = [NSURL fileURLWithPath: _mp4Path];exportSession.shouldOptimizeForNetworkUse = YES;exportSession.outputFileType = AVFileTypeMPEG4;[exportSession exportAsynchronouslyWithCompletionHandler:^{switch ([exportSession status]) {case AVAssetExportSessionStatusFailed:{UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error"message:[[exportSession error] localizedDescription]delegate:nilcancelButtonTitle:@"OK"otherButtonTitles: nil];[alert show];break;}case AVAssetExportSessionStatusCancelled:NSLog(@"Export canceled");break;case AVAssetExportSessionStatusCompleted:NSLog(@"Successful!");NSLog(@"%@",_mp4Path);NSLog(@"file Size %ldk",(long)[self getFileSize:_mp4Path]);break;default:break;}}];}else{UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error"message:@"AVAsset doesn't support mp4 quality"delegate:nilcancelButtonTitle:@"OK"otherButtonTitles: nil];[alert show];}}//弹出视频拍摄- (void)pickVideoTaped {pickVideo = [[UIImagePickerController alloc]init];pickVideo.sourceType = UIImagePickerControllerSourceTypeCamera;NSArray* availableMedia = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];pickVideo.mediaTypes = [NSArray arrayWithObject:availableMedia[1]];pickVideo.delegate = self;[self presentViewController:pickVideo animated:YES completion:nil];} #pragma mark - UIImagePickerControllerDelegate//拍照完成代理 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {NSLog(@"%@",info);_videoURL = info[UIImagePickerControllerMediaURL];NSString * size = [NSString stringWithFormat:@"%ld kb", (long)[self getFileSize:[[_videoURL absoluteString] substringFromIndex:16]]];NSString *length = [NSString stringWithFormat:@"%.0f s", [self getVideoDuration:_videoURL]];NSLog(@"-------------%@%@",size,length);[picker dismissViewControllerAnimated:YES completion:nil];}//取消代理- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {[picker dismissViewControllerAnimated:YES completion:nil]; }//获取视频时间 - (CGFloat) getVideoDuration:(NSURL*) URL {NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]forKey:AVURLAssetPreferPreciseDurationAndTimingKey];AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:URL options:opts];float second = 0;second = urlAsset.duration.value/urlAsset.duration.timescale;return second; }//获取视频 大小 - (NSInteger) getFileSize:(NSString*) path {NSFileManager * filemanager = [[NSFileManager alloc]init];if([filemanager fileExistsAtPath:path]){NSDictionary * attributes = [filemanager attributesOfItemAtPath:path error:nil];NSNumber *theFileSize;if ( (theFileSize = [attributes objectForKey:NSFileSize]) )return [theFileSize intValue]/1024;elsereturn -1;}else{return -1;} }- (void)addOpBtnWith:(NSString *)name frame:(CGRect)frame action:(SEL)action {UIButton *aBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];aBtn.frame = frame;[aBtn setTitle:name forState:UIControlStateNormal];[aBtn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:aBtn]; }
转载于:https://www.cnblogs.com/cocoajin/p/3494290.html
UIImagePickerController 视频录制操作,视频大小,时间长度相关推荐
- SDVideoCamera:仿抖音(视频录制、视频剪辑、视频合成)
闲话不多讲,先上项目Github传送门. SDVideoCamera传送门 前言 又是好久没有更新博客了,哈哈哈,由于近来从公司离职,再加上近来要结婚的缘故,所以有大量充足的时间来整理以前写的一个仿写 ...
- Filmage Screen,4K视频录制,视频剪辑软件
Filmage Screen是一款专业的视频录制和视频编辑软件,集最好的屏幕录制,专业的视频编辑,快速的视频格式转换,视频播放器于一体,是处理视频的一站式解决方案! Filmage Screen界面简 ...
- Flex与.NET互操作(十三):FluorineFx.Net实现视频录制与视频回放
本文主要介绍使用FluorineFx.Net来实现视频录制与视频回放,FluorineFx如同FMS一样,除了有AMF通信,RTMP协议,RPC和远程共享对象外,它同样具备视频流服务的功能.通过它我们 ...
- iOS开发-UI控件:UIImagePickerController 视频录制操作,视频大小,时间长度
转自: http://www.cnblogs.com/cocoajin/p/3494290.html 简介: 使用 iOS 系统 UIImagePickerController 获取视频大小 获取视频 ...
- 摄像头 UIImagePickerController拍照和视频录制
下面看一下在iOS如何拍照和录制视频.在iOS中要拍照和录制视频最简单的方法就是使用UIImagePickerController.UIImagePickerController继承于UINaviga ...
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制(转)
概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制,还是对麦克风.摄像 ...
- 牛人iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制,还是对麦克风.摄像 ...
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制,还是对麦克风.摄像 ...
- iOS 音频播放,录音,视频播放,拍照,视频录制
iOS开发系列--音频播放.录音.视频播放.拍照.视频录制 2014-12-26 09:15 by KenshinCui, 149110 阅读, 67 评论, 收藏, 编辑 --iOS多媒体 概览 随 ...
最新文章
- 【C 语言】二级指针作为输入 ( 自定义二级指针内存 | 二级指针排序 | 抽象业务逻辑函数 )
- 7-17 BCD解密(10 分)
- 2018-2019-2 20165330《网络对抗技术》Exp9 Web安全基础
- 一个妹子的美团面试经历,成功拿到 Offer
- mysql blob key length_mysql – 没有密钥长度的密钥规范中使用的BLOB / TEXT列’bestilling’...
- HDU - 2859 Phalanx(动态规划/哈希表)
- 在Windows 7或Vista(或Windows 8.x,Sorta)上禁用Aero
- NameError: name 'file' is not defined
- OpenShift 4 Hands-on Lab (7) - 用Jenkins Pipeline实现在不同运行环境中升迁部署应用
- Manjaro.常用命令/ Mnajaro安装后的配置
- 02(d)多元无约束优化问题-拟牛顿法
- html5制作前端优势,HTML5前端开发原来有这么多优势!
- jquery-1.10.2_d88366fd.js和jquery-3.1.0.min.js 在用touch事件时候, event.changedTouches[0]报错的问题。...
- Linux 系统中用户切换(su user与 su - user 的区别)
- pr新建字幕样式(模板)
- 容器云系列之容器技术相关概念介绍
- 电脑连接WiFi,浏览器打不开网页
- Pyinstaller的Spec文件用法
- linux yum和apt,yum和apt-get用法及区别
- python爬虫实现豆瓣模拟登录