iOS AVCapture前置摄像头不显示镜像翻转

iOS系统下前置摄像头拍照/录像默认是会沿中间镜像翻转的, 项目用到AVCaptureSession拍照/录像, 需求要使用前置摄像头时不要左右镜像效果, 研究了好久, 谷歌到的都是旋转的, 看到UIImagePicker可以使用transform进行翻转, 于是又找transform和layer也是无果, 最终想到可能会有一个bool值能够设定这个镜像, 于是查阅API发现一个 videoMirrored方法, 判断为前置摄像头然后将该属性设定为YES, 大功告成!
//负责从AVCaptureDevice获得输入数据
@property (strong,nonatomic) AVCaptureDeviceInput *captureDeviceInput;

        //根据设备输出获得连接
        AVCaptureConnection *connection = [self.captureMovieFileOutput connectionWithMediaType:AVMediaTypeVideo];
     
            
            // 前置摄像头翻转
            AVCaptureDevicePosition currentPosition=[[self.captureDeviceInput device] position];
            if (currentPosition == AVCaptureDevicePositionUnspecified || currentPosition == AVCaptureDevicePositionFront) {
                connection.videoMirrored = YES;
            } else {
                connection.videoMirrored = NO;
            }



你可能感兴趣的:(iOS AVCapture前置摄像头不显示镜像翻转)