一:使用 iOS 系统 UIImagePickerController

  • 获取视频大小
  • 获取视频长度
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. self.title = @"AVVideo Demo";
CGRect theFrame = CGRectMake(, , , );
[self addOpBtnWith:@"pick Video" frame:theFrame action:@selector(pickVideoTaped)]; theFrame = CGRectMake(, , , );
[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:avAsset
presetName: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:nil
cancelButtonTitle:@"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:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
} } //弹出视频拍摄 - (void)pickVideoTaped
{
pickVideo = [[UIImagePickerController alloc]init];
pickVideo.sourceType = UIImagePickerControllerSourceTypeCamera;
NSArray* availableMedia = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
pickVideo.mediaTypes = [NSArray arrayWithObject:availableMedia[]];
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:]]];
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 = ;
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]/;
else
return -;
}
else
{
return -;
}
} - (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];
}

UIImagePickerController 视频录制操作,视频大小,时间长度的更多相关文章

  1. iOS开发系列--音频播放、录音、视频播放、拍照、视频录制

    --iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制, ...

  2. iOS开发----音频播放、录音、视频播放、拍照、视频录制

    随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制,还是对麦克风.摄像头的操 ...

  3. 音频播放、录音、视频播放、拍照、视频录制-b

    随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制,还是对麦克风.摄像头的操 ...

  4. iOS音频播放、录音、视频播放、拍照、视频录制

    随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制,还是对麦克风.摄像头的操 ...

  5. Android开发笔记——视频录制播放常见问题

    本文分享自己在视频录制播放过程中遇到的一些问题,主要包括: 视频录制流程 视频预览及SurfaceHolder 视频清晰度及文件大小 视频文件旋转 一.视频录制流程 以微信为例,其录制触发为按下(住) ...

  6. Android使用MediaRecorder和Camera实现视频录制及播放功能整理

    转载请注明出处:http://blog.csdn.net/woshizisezise/article/details/51878566 这两天产品经理向我丢来一个新需求,需要在项目里添加一个视频录制的 ...

  7. 《高级软件测试》11.16.Jira使用说明的撰写和操作视频的录制

    今日任务完成情况如下: 小王:完成了测试管理工具jira的使用手册中,基本情况介绍.下载安装部分的撰写工作:小高:参考官方手册,结合自己的实际使用体会,对jira的基本组成及其工作流程进行了介绍:小陈 ...

  8. iOS视频录制、压缩导出、取帧

    概述 花了点时间研究了一下常用的视频获取.录制.压缩.取帧图功能,分享给大家了!相信阅读完本篇文章,会对你有很大的帮助的! 本篇文章研究几下以个功能: 视频录制 从相册选择视频 保持视频到相册 获取视 ...

  9. Android实现视频录制

    安卓实现视频录制,有两种方法,一种是调用自带的视频功能,一种是使用MediaRecorder. 每种方法都有自己的优缺点.接下来,把两种方法的代码写出来. 先说第一种方法,也是最简单的方法,那就是直接 ...

随机推荐

  1. 携带结果的任务 Callable 与 Future

    Executor框架使用Runnable作为其基本任务表示形式.Runnable是一种有很大局限的抽象,它不能返回一个值或者抛出一个受检查的异常. 但是许多任务实际上都是存在延迟的计算,比如执行数据库 ...

  2. SCU - 4439 Vertex Cover (图的最小点覆盖集)

    Vertex Cover frog has a graph with \(n\) vertices \(v(1), v(2), \dots, v(n)\) and \(m\) edges \((v(a ...

  3. MYSQL注入天书之导入导出介绍

    Background-3 导入导出相关操作的讲解 load_file()导出文件 Load_file(file_name):读取文件并返回该文件的内容作为一个字符串. 使用条件: A.必须有权限读取并 ...

  4. Xamarin.Forms教程下载安装Xamarin.iOS

    Xamarin.Forms教程下载安装Xamarin.iOS 下载安装Xamarin.iOS Xamarin.iOS可以为Mac上iOS应用程序在Windows计算机上编写和测试网络提供构建和部署服务 ...

  5. ubuntu问题集锦

    我使用的是ubuntu 14.04 用UltraIOS 制作镜像安装的  ubuntu 问题1:闪屏问题以及文字显示不全 解决方案:重装显卡驱动 解决过程:http://my.oschina.net/ ...

  6. [Codeforces #174] Tutorial

    Link: Codeforces #174 传送门 A: 求原根的个数,有一条性质是原根个数为$\phi(\phi(n))$,多了一个不会证的性质 如果要确定哪些是原根的话还是要枚举,不过对于每个数不 ...

  7. [Codeforces-div.1 55D] Beautiful numbers

    [Codeforces-div.1 55D] Beautiful numbers 试题分析 还是离散化...\(f_{i,j,k}\)表示i位,gcd为j,余数为k. #include<iost ...

  8. BZOJ 3282 Tree(动态树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3282 [题目大意] 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的x ...

  9. 【线性筛】【质因数分解】【约数个数定理】hdu6069 Counting Divisors

    d(x)表示x的约数个数,让你求(l,r<=10^12,r-l<=10^6,k<=10^7) #include<cstdio> using namespace std; ...

  10. android 关于Make sure the plugin is properly configured问题的解决办法

    这个问题引发的原因最初的报错是: [2013-10-14 10:01:58 - XXX] The connection to adb is down, and a severe error has o ...