mirror of
https://github.com/HaishinKit/HaishinKit.swift.git
synced 2026-05-07 20:12:28 +00:00
22 lines
1.1 KiB
Swift
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
|
|
}
|
|
}
|
|
}
|
|
}
|