FileOutput(封装前后摄像头,闪光灯,分辨率设置,焦距,设置帧率,调节ISO,光感度 0.0-1.0,横竖屏切换)
由于公司需求 视频录制需要自定义视频码率 使用AVCaptureFileOutput只能实现视频帧率更改
所以更改项目功能 使用AVAssetWriter来实现
基本思路
使用
AVCaptureVideoDataOutput//视频输
AVCaptureAudioDataOutput//音频输出
AVCaptureVideoDataOutputSampleBufferDelegate
AVCaptureAudioDataOutputSampleBufferDelegate
逻辑思路
根据代理获取CMSampleBufferRef 获取视频帧,通过AVAssetWriter媒体写入对象,更改视频码率编码
videoCompressionProps = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:FrameRate], AVVideoMaxKeyFrameIntervalKey,
[NSNumber numberWithInteger:BitRate], AVVideoAverageBitRateKey,
AVVideoH264EntropyModeCABAC,AVVideoH264EntropyModeKey,
nil];
videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264,AVVideoCodecKey,
videoCompressionProps, AVVideoCompressionPropertiesKey,
AVVideoScalingModeResizeAspectFill,AVVideoScalingModeKey,
[NSNumber numberWithInteger:videoWight],AVVideoWidthKey,
[NSNumber numberWithInteger:videoHeight],AVVideoHeightKey,
nil];
//初始化视频写入类
_videoInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];
//表明输入是否应该调整其处理为实时数据源的数据
_videoInput.expectsMediaDataInRealTime = YES;
//将视频输入源加入
[_writer addInput:_videoInput];
通过获取CMSampleBufferRef的时间节点 调整timeOffset
CMSampleBufferGetPresentationTimeStamp
开始不断的进行拼接视频帧数据
//获取开始写入的CMTime
CMTime startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
//开始写入
[_writer startWriting];
[_writer startSessionAtSourceTime:startTime];
下面是具体封装的demo
https://github.com/qw9685/Two-methods-of-video-recording