标签:
声明变量
@interface ********** { GPUImageVideoCamera *Camera; GPUImageOutput *Filters; GPUImageView *CameraShowView; }
首先是Camera,一种是GPUImageStillCamera,另一个种为GPUImageVideoCamera.正如其命名,如果只是拍照使用前者.录制视频使用后者.
//init, 第一个参数分辨率 第二个参数,前后摄像头选择 Camera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront]; Camera.outputImageOrientation = UIInterfaceOrientationPortrait; Camera.horizontallyMirrorFrontFacingCamera = NO; Camera.horizontallyMirrorRearFacingCamera = NO;
其次camera获取视频(图片)后,加以滤镜也就是filter, filter可以叠加,也可以自定义(比如美颜).
//黑白滤镜 Filters = [GPUImageColorPackingFilter new]; //将将滤镜加至摄像头 [Camera addTarget:Filters];
最后输出处理后的视频或图片,这里可以可以直接输出至屏幕,也可以使用GPUImageMovieWriter,也就是录制了.
//用于显示视频的GPUImageView CameraShowView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 64,self.view.frame.size.width,self.view.frame.size.width*1.25)]; [CameraShowView setInputRotation:kGPUImageFlipHorizonal atIndex:0]; CameraShowView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill; [self.view addSubview:CameraShowView]; //将视频输出到->CameraShowView [Filters addTarget:CameraShowView];
当然也不要忘记启动
//视频启动 [Camera startCameraCapture];
其他
//前后摄像头切换 -(void)VideoPosition:(UIButton*)Button{ [Camera rotateCamera]; Button.selected = !Button.selected; } //闪关灯 -(void)LightBtn:(UIButton*)Btn{ if (Camera.inputCamera.position == AVCaptureDevicePositionBack) { if (Btn.selected) { [Camera.inputCamera lockForConfiguration:nil]; [Camera.inputCamera setTorchMode:AVCaptureTorchModeOff]; [Camera.inputCamera unlockForConfiguration]; }else{ [Camera.inputCamera lockForConfiguration:nil]; [Camera.inputCamera setTorchMode:AVCaptureTorchModeOn]; [Camera.inputCamera unlockForConfiguration]; } Btn.selected = !Btn.selected; }else{ NSLog(@"当前使用前置摄像头,未能开启闪光灯"); } }
未完待续,算是挖坑. 后续也就是滤镜切换,视频的简单剪辑...
标签:
原文地址:http://www.cnblogs.com/ngi8/p/5885809.html