使用GPUImage开启的相机进行摄像,保存写入到Path
之前已经有一篇博客讲过怎么开启摄像头并完成对摄像头的图像的滤镜化了,现在就说说怎么录像,并把这个添加滤镜的录像文件写到Path
原理是GPUImage给出了GPUImageMovieWriter这么个类,专门用于记录摄像头的录像。设定了路径和声音视频参数以后,把GPUImageMovieWriter的对象委托给滤镜对象,再把滤镜对象委托给VideoCamera就可以开始录制了。
首先定义:
GPUImageMovieWriter * movieWriter;
GPUImageVideoCamera * videoCamera;
NSMutableDictionary * videoSettings;
NSDictionary * audioSettings;
NSString * pathToMovie;
这些都是录像必备的属性
接下来是初始化的工作
首先初始化声音和视频参数:
//init Video Setting
videoSettings = [[NSMutableDictionaryalloc] init];;
[videoSettingssetObject:AVVideoCodecH264forKey:AVVideoCodecKey];
] forKey:AVVideoWidthKey];
] forKey:AVVideoHeightKey];
//init audio setting
AudioChannelLayout channelLayout;
, sizeof(AudioChannelLayout));
channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
audioSettings = [NSDictionarydictionaryWithObjectsAndKeys:
[ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[ ], AVNumberOfChannelsKey,
[ NSNumber numberWithFloat: 16000.0 ], AVSampleRateKey,
[ NSData dataWithBytes:&channelLayout length: sizeof( AudioChannelLayout ) ], AVChannelLayoutKey,
[ ], AVEncoderBitRateKey,
nil];
然后是初始化文件路径和视频写入对象
//init Movie path
pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:thePath];
unlink([pathToMovieUTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
//init movieWriter
movieWriter = [[GPUImageMovieWriteralloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0) fileType:AVFileTypeMPEG4outputSettings:videoSettings];
[movieWritersetHasAudioTrack:YESaudioSettings:audioSettings];
接下来是GPUImageVideoCamera和滤镜效果的初始化,我就不写了,看我另外一篇博客
初始化的最后动作就是赋予委托:
//把滤镜效果加给摄像头
[videoCameraaddTarget:testFilter];
//把摄像头上的图像给GPUImageView显示出来
[testFilteraddTarget:imageView];
[testFilteraddTarget:movieWriter];
这样初始化的工作就全部做完了,要开始录制只要开启以下代码:
videoCamera.audioEncodingTarget = movieWriter;
[movieWriterstartRecording];
就可以开始录制了,结束录制也很简单:
//stop recording
[testFilterremoveTarget:movieWriter];
[movieWriterfinishRecording];
录制完的视频将会保存在路径里
还有两个小设置:
开启和关闭闪光灯:
[videoCamera.inputCamerasetTorchMode:AVCaptureTorchModeOn];
[videoCamera.inputCameraunlockForConfiguration];
[videoCamera.inputCameralockForConfiguration:nil];
[videoCamera.inputCamerasetTorchMode:AVCaptureTorchModeOff];
[videoCamera.inputCameraunlockForConfiguration];
使用GPUImage开启的相机进行摄像,保存写入到Path的更多相关文章
- 在webapp上使用input:file, 指定capture属性调用默许相机,摄像,录音功能
## 在webapp上使用input:file, 指定capture属性调用默认相机,摄像,录音功能 在iOS6下开发webapp,使用inputz之file,很有用 <input type=& ...
- 用GPUImage开启相机并且开启滤镜效果
GPUImage提供了GPUImageVideoCamera这么一个类,它的对象能够调用摄像头,并且加上滤镜的效果. //init VideoCamera //这里的两个参数可以设定拍 ...
- 导入GPUImage,实时滤镜相机,GUPImage遇到的问题解决,_OBJC_METACLASS_$_GBGPUImageView in GBGPUImageView.o
导入方法转自:http://www.cnblogs.com/S2-huai/p/3881349.html.. (原文:http://www.cnblogs.com/YouXianMing/p/3709 ...
- RealSense R400系列深度相机的图像获取保存和格式转换
关于RealSense的基础使用的博文用的库有点混杂,挺多博文都是早期maneger的那个库,对那个不是很了解,主要记录一下使用最新的函数库的基础使用. 相机型号:RealSense R435 使用函 ...
- 调用android系统相机拍照并保存
[java] view plaincopyprint? <span style="font-size:18px;">package com.demo; import j ...
- android调用系统相机拍照并保存在本地
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...
- ## 在webapp上使用input:file, 指定capture属性调用默认相机,摄像,录音功能
在iOS6下开发webapp,使用inputz之file,很有用 <input type="file" accept="image/*" capture= ...
- DevExpress asp.net 导出Excel 自动开启迅雷问题,默认保存为aspx页面
目前采取曲线救国策略: 利用MVC ..... <dx:ASPxGridView ID="ASPxGridView1" runat="server" Au ...
- Android下 调用原生相机拍照摄像
1 http://www.cnblogs.com/franksunny/archive/2011/11/17/2252926.html 2 http://www.cnblogs.com/vir56k/ ...
随机推荐
- phpMyAdmin教程 之 创建新用户/导入/导出数据库
盗用了被人的教程. 需要看就点击进去吧.复制过来实在是过意不去 http://www.wpdaxue.com/phpmyadmin-import-export-database.html
- 1.RABBITMQ 入门 - WINDOWS - 获取,安装,配置
一. 背景: 公司项目有所改动,要求微信(移动端调用的接口),日志接口换位log4net,全部改成以rabbitMQ作为服务支持, 二.本地环境: windows 10 enterpr ...
- oracle查询最占用资源的查询
从V$SQLAREA中查询最占用资源的查询 select b.username username,a.disk_reads reads,a.executions exec,a.disk_reads/d ...
- jquery动态插入行,不用拼写html,简洁版
这个一个利用jquery实现动态插入输入行效果小功能,不用在javascript里拼写html字符串,更简洁.高效. html代码: <div class="fitem"&g ...
- 将数字n转换为字符串并保存到s中
将数字n转换为字符串并保存到s中 参考 C程序设计语言 #include <stdio.h> #include <string.h> //reverse函数: 倒置字符串s中各 ...
- 在Windows下用MingW 4.5.2编译OpenCV 2.3.0
需要的工具:1.安装QT SDK环境2.安装CMake for Windows3.OpenCV最新Windows源码步骤:1.将QT SDK安装目录下的{QtSDK}\mingw\bin添加到系统环境 ...
- 分享一个自己写的基于TP的关系模型(四)
修复分页BUG,原有代码查询到最后一页就一只查询最后一页 $ ? $; $this->maxPage = ceil($this->total/$this->rows); //$thi ...
- ARM开发板系统移植-----u-boot的编译
本文和另外两篇姊妹篇都是为了说明如何裁剪出适合在mini2440 开发板上运行的Linux系统,以记录自己的学习成果.其中本文先介绍了嵌入式系统的软件组成部分,然后介绍编译出适合在mini2440开发 ...
- DOM中的范围 createRange()
学习<JavaScript 高级程序设计> 12章dom范围的笔记 dom2级在Document类型中定义了 createRange()方法: 创建range对象很简单 var range ...
- ubuntu使用github
Ubuntu下安装Git Ubuntu12.04 LTS默认是已经安装Git的,可以使用 git --version 测试是否安装.如果没有安装,使用命令: sudo apt-get install ...