Choosing the right AVCaptureSessionPreset for different devices

徘徊边缘 提交于 2019-12-02 07:42:23

问题


I am a little confused which preset I should use for different devices. Currently I am using AVCaptureSessionPresetMedium for all devices. However, I want to take advantage of different resolutions for different phones. For example the new iPhone 6s can take 4K video, and in this case I would use AVCaptureSessionPreset3840x2160.

What I am asking is an elegant way to choose the right preset for different devices. Thanks


回答1:


you can use like below.

[CaptureSession setSessionPreset:AVCaptureSessionPresetMedium];
if ([CaptureSession canSetSessionPreset:AVCaptureSessionPreset640x480])     //Check size based configs are supported before setting them
        [CaptureSession setSessionPreset:AVCaptureSessionPreset640x480];
if ([CaptureSession canSetSessionPreset:AVCaptureSessionPreset1280x720])
        [CaptureSession setSessionPreset:AVCaptureSessionPreset1280x720];
if ([CaptureSession canSetSessionPreset:AVCaptureSessionPreset1920x1080])
        [CaptureSession setSessionPreset:AVCaptureSessionPreset1920x1080];
if ([CaptureSession canSetSessionPreset:AVCaptureSessionPreset3840x2160])
        [CaptureSession setSessionPreset:AVCaptureSessionPreset3840x2160];

or you can use just one statement

[CaptureSession setSessionPreset:AVCaptureSessionPresetHigh];



回答2:


#ifdef __AVAILABILITY_INTERNAL__IPHONE_9_0_DEP__IPHONE_9_0
CGFloat iOSVersion = [[[UIDevice currentDevice] systemVersion] integerValue];
if (iOSVersion>=9 && [session canSetSessionPreset:AVCaptureSessionPreset3840x2160]) {
    session.sessionPreset = AVCaptureSessionPreset3840x2160;
}
#else
// the code above won't compile in Xcode 6 and older
#endif

...



来源:https://stackoverflow.com/questions/32754111/choosing-the-right-avcapturesessionpreset-for-different-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!