使用GPUImage进行采集摄像头数据,并且能够实现大部分的美颜效果 并且集成了闪光灯 摄像头切换 焦点缩放 聚焦功能
GIF演示
Untitled.gif
主要几个核心类:
GPUImageVideoCamera:封装系统的AVCaptureSession,AVCaptureDevice,AVCaptureDeviceInput,AVCaptureVideoDataOutput
演示
-(CCGPUImageVideoCamera *)videoCamera{
if (!_videoCamera) {
_videoCamera = [[CCGPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionFront];
_videoCamera.delegate = self;
_videoCamera.audioDelegate = self;
_videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
_videoCamera.horizontallyMirrorFrontFacingCamera = YES;// 前置摄像头需要 镜像反转
_videoCamera.horizontallyMirrorRearFacingCamera = NO;// 后置摄像头不需要 镜像反转
[_videoCamera addAudioInputsAndOutputs];//避免录制第一帧黑屏闪屏
if ([_videoCamera.inputCamera lockForConfiguration:nil]) {
//自动对焦
if ([_videoCamera.inputCamera isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) {
[_videoCamera.inputCamera setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
}
//自动曝光
if ([_videoCamera.inputCamera isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
[_videoCamera.inputCamera setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
}
//自动白平衡
if ([_videoCamera.inputCamera isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance]) {
[_videoCamera.inputCamera setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
}
[_videoCamera.inputCamera unlockForConfiguration];
}
}
return _videoCamera;
}
GPUImageView:获取采集到的数据进行展示
GPUImageMovieWriter:采集的视频 音频数据进行写入
GPUImageFilter:滤镜核心类
网友评论