ios将摄像头捕获的视频数据转为jpeg格式
来源:互联网 发布:bjd娃娃正版淘宝店 编辑:程序博客网 时间:2024/06/11 17:15
想要将摄像头进行视频录制或者拍照可以用UIImagePickerController,不过UIImagePickerController会弹出一个自己的界面,可是有时候我们不想要弹出的这个界面,那么就可以用另一种方法来获取摄像头得到的数据了。
首先需要引入一个包#import <AVFoundation/AVFoundation.h>,接下来你的类需要实现AVCaptureVideoDataOutputSampleBufferDelegate这个协议,只需要实现协议中的一个方法就可以得到摄像头捕获的数据了
- - (void)captureOutput:(AVCaptureOutput *)captureOutput
- didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
- fromConnection:(AVCaptureConnection *)connection
- {
- // Create a UIImage from the sample buffer data
- UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
- mData = UIImageJPEGRepresentation(image, 0.5);//这里的mData是NSData对象,后面的0.5代表生成的图片质量
- }
下面是imageFromSampleBuffer方法,方法经过一系列转换,将CMSampleBufferRef转为UIImage对象,并返回这个对象:
- // Create a UIImage from sample buffer data
- - (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer
- {
- // Get a CMSampleBuffer's Core Video image buffer for the media data
- CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
- // Lock the base address of the pixel buffer
- CVPixelBufferLockBaseAddress(imageBuffer, 0);
- // Get the number of bytes per row for the pixel buffer
- void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
- // Get the number of bytes per row for the pixel buffer
- size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
- // Get the pixel buffer width and height
- size_t width = CVPixelBufferGetWidth(imageBuffer);
- size_t height = CVPixelBufferGetHeight(imageBuffer);
- // Create a device-dependent RGB color space
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- // Create a bitmap graphics context with the sample buffer data
- CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8,
- bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
- // Create a Quartz image from the pixel data in the bitmap graphics context
- CGImageRef quartzImage = CGBitmapContextCreateImage(context);
- // Unlock the pixel buffer
- CVPixelBufferUnlockBaseAddress(imageBuffer,0);
- // Free up the context and color space
- CGContextRelease(context);
- CGColorSpaceRelease(colorSpace);
- // Create an image object from the Quartz image
- //UIImage *image = [UIImage imageWithCGImage:quartzImage];
- UIImage *image = [UIImage imageWithCGImage:quartzImage scale:1.0f orientation:UIImageOrientationRight];
- // Release the Quartz image
- CGImageRelease(quartzImage);
- return (image);
- }
- ios将摄像头捕获的视频数据转为jpeg格式
- ios将摄像头捕获的视频数据转为jpeg格式
- ios将摄像头捕获的视频数据转为jpeg格式
- ios将摄像头捕获的视频数据转为jpeg格式 .
- ios学习--ios将摄像头捕获的视频数据转为jpeg格式
- ios学习--ios将摄像头捕获的视频数据转为jpeg格式 .
- ios学习--ios将摄像头捕获的视频数据转为jpeg格式
- iOS疯狂详解之将摄像头捕获的视频数据转为jpeg格式
- 利用FFmpeg将Jpeg图片转为任意视频容器格式
- 利用FFmpeg将Jpeg图片转为任意视频容器格式
- 利用FFmpeg将Jpeg图片转为任意视频容器格式
- 利用FFmpeg将Jpeg图片转为任意视频容器格式
- opencv学习笔记(九)捕获摄像头的视频并保存成avi格式
- iOS UIImagePickerController录制视频转为mp4格式
- 上传数据时将其转为base64格式,支持图片视频
- 利用Python将WEBVTT格式的视频字幕文件转为SRT格式
- Xcode中捕获iphone/ipad/ipod手机摄像头的实时视频数据
- iOS 摄像头,进行音视频的数据采集
- C++的namespace
- 把序列合并成字符串
- 【图的遍历】【最小生成树】【SCOI2012】滑雪与时间胶囊
- poj 2386 Lake Counting (BFS~)
- Xcode快捷键和使用技巧
- ios将摄像头捕获的视频数据转为jpeg格式
- 英语速学法
- find: paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression]
- dll文件的加载顺序
- 十五周任务(一)为应用程序增加周长
- chrome浏览器的快捷键
- ios学习--SQLite常用函数
- python-上传样本到virustotal,查询扫描信息
- 如何消除 sql server 2008 查询语句的红色波浪线