Я пытаюсь уменьшить частоту кадров, используемую доступной камерой при захвате видео. Ниже мой код. После попытки уменьшить частоту кадров за счет увеличения длительности кадра устройства оно, по-видимому, не изменилось. Пожалуйста, кто-нибудь может посоветовать? Можно ли установить для частоты кадров значение между min и max для macFrameDuration, minFrameDuration, maxFrameRate и min frameRate?
Ниже приведен мой код:
let videoDevice = AVCaptureDevice.default(for: .video) // AvCaptureDevice instance
guard let device = videoDevice else{return}
print("BEFORE CAMERA CONFIG")
for value in device.activeFormat.videoSupportedFrameRateRanges{
print("\(value.minFrameRate)")
print("\(value.maxFrameRate)")
print("\(value.maxFrameDuration)")
print("\(value.minFrameDuration)")
}
print("")
var lowestFormat: AVCaptureDevice.Format?
var leastFrameRateRange: AVFrameRateRange?
var numberFormats = 0
for format in device.formats{ // AVCaptureDevice.Format
// Range of frameRate supported by each format the device supports
let ranges = format.videoSupportedFrameRateRanges // [AVFrameRateRange]
for range in ranges{
if range.minFrameRate < leastFrameRateRange?.minFrameRate ?? 30{
print("supported format.formatDescription: \(format.formatDescription)")
// iterate through all formats and assigns final value for 'lowestFormat' & 'leastFrameRate'
lowestFormat = format
leastFrameRateRange = range
}
}
}
if let lowestFormat = lowestFormat,
let leastFrameRateRange = leastFrameRateRange {
do{
try device.lockForConfiguration()
// Set the device;s active format
device.activeFormat = lowestFormat
// Set the device's min/max frame duration
let duration = leastFrameRateRange.maxFrameDuration
device.activeVideoMaxFrameDuration = duration
device.activeVideoMinFrameDuration = duration
print("device.activeVideoMaxFrameDuration \(device.activeVideoMaxFrameDuration)")
print("device.activeVideoMinFrameDuration \(device.activeVideoMinFrameDuration)")
device.unlockForConfiguration()
}catch{
// Handle error
}
}
print("AFTER CAMERA CONFIG")
print("device.activeFormat.formatDescription: \(device.activeFormat.formatDescription)")
for value in device.activeFormat.videoSupportedFrameRateRanges{
print("\(value.minFrameRate)")
print("\(value.maxFrameRate)")
print("\(value.maxFrameDuration)")
print("\(value.minFrameDuration)")
}
CONSOLE:
BEFORE CAMERA CONFIG
2.0
30.0
CMTime(value: 1, timescale: 2, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0)
CMTime(value: 1, timescale: 30, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0)
supported format.formatDescription: <CMVideoFormatDescription 0x283b9c540 [0x22a141430]> {
mediaType:'vide'
mediaSubType:'420v'
mediaSpecific: {
codecType: '420v' dimensions: 192 x 144
}
extensions: {(null)}
}
device.activeVideoMaxFrameDuration CMTime(value: 1, timescale: 2, flags:
__C.CMTimeFlags(rawValue: 1), epoch: 0)
device.activeVideoMinFrameDuration CMTime(value: 1, timescale: 2, flags:
__C.CMTimeFlags(rawValue: 1), epoch: 0)
AFTER CAMERA CONFIG
device.activeFormat.formatDescription: <CMVideoFormatDescription 0x283b9c540 [0x22a141430]> {
mediaType:'vide'
mediaSubType:'420v'
mediaSpecific: {
codecType: '420v' dimensions: 192 x 144
}
extensions: {(null)}
}
2.0
30.0
CMTime(value: 1, timescale: 2, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0)
CMTime(value: 1, timescale: 30, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0)