Files
HaishinKit.swift/HaishinKit/Sources/Extension/AVCaptureDevice+Extension.swift
2024-11-10 13:27:58 +09:00

22 lines
1.1 KiB
Swift

import AVFoundation
import Foundation
@available(tvOS 17.0, *)
extension AVCaptureDevice {
func videoFormat(width: Int32, height: Int32, frameRate: Float64, isMultiCamSupported: Bool) -> AVCaptureDevice.Format? {
if isMultiCamSupported {
return formats.first {
$0.isMultiCamSupported && $0.isFrameRateSupported(frameRate) && width <= $0.formatDescription.dimensions.width && height <= $0.formatDescription.dimensions.height
} ?? formats.last {
$0.isMultiCamSupported && $0.isFrameRateSupported(frameRate) && $0.formatDescription.dimensions.width < width && $0.formatDescription.dimensions.height < height
}
} else {
return formats.first {
$0.isFrameRateSupported(frameRate) && width <= $0.formatDescription.dimensions.width && height <= $0.formatDescription.dimensions.height
} ?? formats.last {
$0.isFrameRateSupported(frameRate) && $0.formatDescription.dimensions.width < width && $0.formatDescription.dimensions.height < height
}
}
}
}