[iOS 视频流开发-获得视频帧处理]

调用视频流所使用框架:<Foundation/Foundation.h>

必须定义的参数:
1.AVCaptureDevice(捕获设备:前置、后置摄像头等)
2.AVCaptureInput(捕获输入:一般就是捕获设备的输入)
3.AVCaptureOutput(捕获输出:可输入为视频文件、图像文件等)
4.AVCaptureSession(调节多个输入输出)
关键代码:
- (void)setupCamera
{
NSError *error = nil; // Create the session
_session = [[AVCaptureSession alloc] init]; // Configure the session to produce lower resolution video frames, if your
// processing algorithm can cope. We'll specify medium quality for the
// chosen device.
_session.sessionPreset = AVCaptureSessionPresetMedium; // Find a suitable AVCaptureDevice
AVCaptureDevice *device = [AVCaptureDevice
defaultDeviceWithMediaType:AVMediaTypeVideo]; // Create a device input with the device and add it to the session.
_input = [AVCaptureDeviceInput deviceInputWithDevice:device
error:&error];
if (!_input) {
// Handling the error appropriately.
}
[_session addInput:_input]; // Create a VideoDataOutput and add it to the session
_output = [[AVCaptureVideoDataOutput alloc] init];
[_session addOutput:_output]; // Configure your output.
dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[_output setSampleBufferDelegate:self queue:queue]; // Specify the pixel format
_output.videoSettings =
[NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
forKey:(id)kCVPixelBufferPixelFormatTypeKey]; // If you wish to cap the frame rate to a known value, such as 15 fps, set
// minFrameDuration.
_output.minFrameDuration = CMTimeMake(, ); // Start the session running to start the flow of data
[_session startRunning]; // Assign session to an ivar.
[self setSession:_session];
} // Delegate routine that is called when a sample buffer was written
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
// Create a UIImage from the sample buffer data
UIImage *img = [self imageFromSampleBuffer:sampleBuffer]; /*
dispatch_async(dispatch_get_main_queue(), ^{
self.catchview.image=img;
});
*/ }
// 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, ); // 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); // Get the number of bytes per row for the pixel buffer
u_int8_t *baseAddress = (u_int8_t *)malloc(bytesPerRow*height);
memcpy( baseAddress, CVPixelBufferGetBaseAddress(imageBuffer), bytesPerRow * height ); // size_t bufferSize = CVPixelBufferGetDataSize(imageBuffer); // Create a device-dependent RGB color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // Create a bitmap graphics context with the sample buffer data //The context draws into a bitmap which is `width'
// pixels wide and `height' pixels high. The number of components for each
// pixel is specified by `space'
CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, ,
bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst); // Create a Quartz image from the pixel data in the bitmap graphics context
CGImageRef quartzImage = CGBitmapContextCreateImage(context); // Unlock the pixel buffer
CVPixelBufferUnlockBaseAddress(imageBuffer,); // Free up the context and color space
CGContextRelease(context);
//CGColorSpaceRelease(colorSpace); // Create an image object from the Quartz image
UIImage *image = [UIImage imageWithCGImage:quartzImage scale:1.0 orientation:UIImageOrientationRight];
free(baseAddress);
// Release the Quartz image
CGImageRelease(quartzImage);
return (image);
}
[iOS 视频流开发-获得视频帧处理]的更多相关文章
- iOS视频流开发(1)—视频基本概念
iOS视频流开发(1)-视频基本概念 手机比PC的优势除了便携外,她最重要特点就是可以快速方便的创作多媒体作品.照片分享,语音输入,视频录制,地理位置.一个成功的手机APP从产品形态上都有这其中的一项 ...
- iOS视频流开发(2)—视频播放
承上篇,本篇文章主要介绍iOS视频播放需要用到的类.以及他们的使用场景和开发中遇到的问题. MPMoviePlayerViewController MP简介 iOS提供MPMoviePlayerCon ...
- iOS视频流开发(2) — 视频播放
iOS视频流开发(2) — 视频播放 承上篇,本篇文章主要介绍iOS视频播放需要用到的类.以及他们的使用场景和开发中遇到的问题. MPMoviePlayerViewController MP简介 i ...
- iOS开发系列--视频处理
MPMoviePlayerController 在iOS中播放视频可以使用MediaPlayer.framework种的MPMoviePlayerController类来完成,它支持本地视频和网络视频 ...
- iOS开发系列- 视频MPMoviePlayerController
MPMoviePlayerController 在iOS中播放视频可以使用MediaPlayer.framework种的MPMoviePlayerController类来完成,它支持本地视频和网络视频 ...
- FFmpeg进行视频帧提取&音频重采样-Process.waitFor()引发的阻塞超时
由于产品需要对视频做一系列的解析操作,利用FFmpeg命令来完成视频的音频提取.第一帧提取作为封面图片.音频重采样.字幕压缩等功能: 前一篇文章已经记录了FFmpeg在JAVA中的使用-音频提取&am ...
- Python+moviepy音视频剪辑:视频帧数据的本质、Clip的fl方法进行变换处理的原理以及滚屏案例
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt+moviepy音视频剪辑实战 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一. ...
- 音视频处理基础知识扫盲:数字视频YUV像素表示法以及视频帧和编解码概念介绍
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt+moviepy音视频剪辑实战 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一. ...
- iOS常用开发资源整理
在行--专家付费咨询 杂项 App Release Checklist—iOS App发布清单. Hey Focus—帮助你专注于一个任务. Objective Cloud—Objective C A ...
随机推荐
- JBOSS EAP 6.0+ Standalone模式安装成Windows服务
网上有一些文章介绍用JavaService.exe来实现,但是到EAP 6以上版本,我试过好象没成功,幸好JBoss官方已经推出了专门的工具. 一.先到官网下载http://www.jboss.org ...
- 国内优秀Android学习资源
技术博客 应用开发 博主 博客 备注 任玉刚 CSDN博客 深入Android应用开发,深度与广度兼顾 郭霖 CSDN博客 内容实用,行文流畅,高人气博主 夏安明 CSDN博客 张鸿洋 CSDN博 ...
- JavaEE PO VO BO DTO POJO DAO 整理总结
佩服能将复杂难懂的技术,抽象成简单易懂事物的人. 厌恶将简单易懂的技术,添加一堆专业术语将别人弄的头晕目眩的人. PO VO BO DTO POJO DAO 总体一览: 1.DAO[data acce ...
- 单片机C语言探究--为什么变量最好要赋初值
有许多书上说,变量最好要赋初值.但是为什么要初值呢?不赋初值可能会出现什么样的意外呢?以下就我在以51单片机为MCU,Keil为编译器看到的实现现象作分析.众所周知,变量是存储在RAM中,掉电后即丢失 ...
- GitHub 上一份很受欢迎的前端代码优化指南-强烈推荐收藏
看到一份很受欢迎的前端代码指南,根据自己的理解进行了翻译,但能力有限,对一些JS代码理解不了,如有错误,望斧正. HTML 语义化标签 HTML5 提供了很多语义化元素,更好地帮助描述内容.希望你能从 ...
- 系统升级日记(2)- 升级到SharePoint Server 2013
最近一段时间在公司忙于将各类系统进行升级,其最主要的目标有两个,一个是将TFS2010升级到TFS2013,另外一个是将SharePoint 2010升级到SharePoint 2013.本记录旨在记 ...
- 前端框架——BootStrap学习
BootStrap简单总结下:1.栅格系统,能够很好的同时适应手机端和PC端(及传说中的响应式布局) 2.兼容性好 接下来是对BootStrap学习的一些基础案例总结和回顾: 首先引入:bootstr ...
- 使用delegate实现简单的查询功能
protected void imgbtnSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e) { string keyWo ...
- MyEclipse10中自动生成Hibernate的实体和xml配置文件
前提:1.在项目中添加Hibernate支持 2.MyEclipse中已经创建好数据库连接 3.表已经建好并且有主键 步骤如下: 1.在DB Browser窗口的已打开连接节点中选中用户创建的所有的表 ...
- Java网络编程——IP
类:InetAdrress 该类主要用于表示互联网协议(IP对象)地址,且无构造方法 主要方法: public static InetAddress getLocalHost()-->返回本地主 ...