原因:由于GPUImage代码过于老旧所以并不支持超广角的设置
修改文件--所有代码都是在GPUImageVideoCamera.m文件中修改
第1步--先封装一个获取当前设备的函数放在.m文件最后
- (AVCaptureDevice *)wjx_getCaptureDeviceWithPosition:(AVCaptureDevicePosition)positon{
NSArray<AVCaptureDeviceType> *deviceTypes = @[AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInDualCamera];//设备类型:广角镜头、双镜头
if (@available(iOS 13.0, *)) {
// 数组成员的顺序,决定搜索设备的顺序,不要随意调整。
deviceTypes = @[AVCaptureDeviceTypeBuiltInTripleCamera,AVCaptureDeviceTypeBuiltInDualWideCamera,AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInDualCamera];
}
AVCaptureDeviceDiscoverySession *dissession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:deviceTypes mediaType:AVMediaTypeVideo position:positon];
// NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in dissession.devices)
{
if ([device position] == positon)
{
return device;
}
}
}
第2步--把所有获取摄像头的位置都换成上面的方法
//第1处
- (id)initWithSessionPreset:(NSString *)sessionPreset cameraPosition:(AVCaptureDevicePosition)cameraPosition;
{
/*
...省略
**/
// Grab the back-facing or front-facing camera
_inputCamera = nil;
// NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
// for (AVCaptureDevice *device in devices)
// {
// if ([device position] == cameraPosition)
// {
// _inputCamera = device;
// }
// }
//上面代码注释掉换成下面
_inputCamera = [self wjx_getCaptureDeviceWithPosition:cameraPosition];
if (!_inputCamera) {
return nil;
}
/*
...省略
**/
}
//第2处
- (void)rotateCamera
{
/*
...省略
**/
// AVCaptureDevice *backFacingCamera = nil;
// NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
// for (AVCaptureDevice *device in devices)
// {
// if ([device position] == currentCameraPosition)
// {
// backFacingCamera = device;
// }
// }
//上面代码注释掉换成下面
AVCaptureDevice *backFacingCamera = [self wjx_getCaptureDeviceWithPosition:currentCameraPosition];
newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];
/*
...省略
**/
}