IOS:Camera的特性分析与使用2_AVCapture
来源:互联网 发布:软件开发平台有哪些 编辑:程序博客网 时间:2024/05/23 23:43
<1> AVCapture
前面我们已经分析了Camera的UIImageViewController使用,这个部分我们再来看下AVCapture怎么使用的。
(1)输入源设置:相机、照片库
(2)设置前后摄像头
(3)设置视频质量
(4)设置照片、视频模式
(5)设置闪光灯打开方式
(6)视频编辑
(7)自定义摄像界面
(8)视频缩略图、视频关键帧
拍照:我们同样从这几个分部分析下AVCapture的使用:
(1)设备输入源设置:
AVCaptureDevice *device = [AVCaptureDevicedefaultDeviceWithMediaType:AVMediaTypeVideo];
self.videoInput = [AVCaptureDeviceInputdeviceInputWithDevice:deviceerror:&error];
(2)相机预览层设置
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayerlayerWithSession:self.captureSession];
[self.view.layeraddSublayer:previewLayer];
(3)静态图片抓取
利用AVCaptureSession建立媒体流与Image:JPEG的联系。
self.stillImageOutput = [[AVCaptureStillImageOutputalloc] init];
NSDictionary *stillImageOutputSettings = [[NSDictionaryalloc] initWithObjectsAndKeys:
AVVideoCodecJPEG, AVVideoCodecKey, nil];
[self.stillImageOutputsetOutputSettings:stillImageOutputSettings];
[self.captureSessionaddOutput:self.stillImageOutput];
(4)点击拍照时,调用如下方法:[[selfstillImageOutput]captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer,NSError *error)
{
if (imageDataSampleBuffer != NULL)
{
NSData *imageData = [AVCaptureStillImageOutputjpegStillImageNSDataRepresentation:imageDataSampleBuffer];
ALAssetsLibrary *library = [[ALAssetsLibraryalloc] init];
UIImage *image = [[UIImagealloc] initWithData:imageData];
[library writeImageToSavedPhotosAlbum:[imageCGImage]
orientation:(ALAssetOrientation)[imageimageOrientation]
completionBlock:^(NSURL *assetURL,NSError *error)
{}];
}
}];
AVCaptureDevice *videoDevice = [AVCaptureDevicedefaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *audioDevice = [AVCaptureDevicedefaultDeviceWithMediaType:AVMediaTypeAudio];
self.videoInput = [AVCaptureDeviceInputdeviceInputWithDevice:videoDevice error:nil];
self.audioInput = [[AVCaptureDeviceInputalloc] initWithDevice:audioDeviceerror:nil];
self.movieOutput = [[AVCaptureMovieFileOutputalloc] init];
[self.captureSessionaddInput:self.videoInput];
[self.captureSessionaddOutput:self.stillImageOutput];
(2)点击录制之后调用方法:[self.movieOutputstartRecordingToOutputFileURL:视频文件路径recordingDelegate:self];
视频缩略图、视频关键帧:AVURLAsset *myAsset = [[AVURLAssetalloc] initWithURL:视频文件路径options:[NSDictionarydictionaryWithObject:@"YES"forKey:AVURLAssetPreferPreciseDurationAndTimingKey]];
AVAssetImageGenerator *imageGenerator = [AVAssetImageGeneratorassetImageGeneratorWithAsset:myAsset];
imageGenerator.appliesPreferredTrackTransform =YES;
// 获取视频拍摄的关键帧。
[imageGenerator generateCGImagesAsynchronouslyForTimes:times
completionHandler:^(CMTime requestedTime,CGImageRef image, CMTime actualTime, AVAssetImageGeneratorResult result,NSError *error)
{
image即为关键帧图片
}];
- IOS:Camera的特性分析与使用2_AVCapture
- IOS:Camera的特性分析与使用
- IOS:Camera的特性分析与使用3_OPENGL特效
- iOS - WKWebView的新特性与使用
- 【iOS】WKWebView的新特性与使用
- IOS 特性CALayer的使用
- IOS 特性CALayer的使用
- IOS 特性CALayer的使用
- IOS 特性CALayer的使用
- IOS 特性CALayer的使用
- S3C2440的camera接口特性
- Matrix与graphics.Camera的使用
- Voodoo Camera Tracker 的介绍与使用
- android camera分析2
- RecyclerView的基本使用,特性分析
- java jdk1.5 特性 -- 枚举类型 Enum的使用与分析
- Camera的使用(笔记)
- Android Camera的使用
- Git总结
- 阿里内推-----校招1
- Codeforces Round #151 (Div. 2) A B C D
- POJ 3673 Cow Multiplication(水~)
- DB2初始建库提示SQL1052N数据库路径不存在
- IOS:Camera的特性分析与使用2_AVCapture
- vim列块操作
- 【Struts2二】结果集(result-type)
- 【Unity】Unity中开场动画设置
- pm runtime management
- trac 更新 logo
- js面试题--------JS中数字和字符,布尔类型相加相减问题
- VC问题 IntelliSense:“没有可用的附加信息”,[请参见“C++项目 IntelliSense 疑难解答”,获得进一步的帮助]
- 反射的实现原理