![](/img/trans.png)
[英]How to resolve the issue while recording a video at 60fps with iphone 4s, ipad 2?
[英]60 fps video recording problem even it is capable swift
我正在嘗試通過修改 AVCAM 應用程序來錄制 60 fps 視頻,該應用程序位於:
https://github.com/Lax/Learn-iOS-Swift-by-Examples/tree/master/AVCam/Swift/AVCam
因此,我的手機(iPhone X)通常可以達到 2-30 fps,我嘗試更改它捕獲視頻的格式。
'''
do {
// Choose the back dual camera if available, otherwise default to a wide angle camera.
if let dualCameraDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front) {
defaultVideoDevice = dualCameraDevice
do{
if let formats = defaultVideoDevice?.formats {
for format in formats{
let formatDesc = format.formatDescription
print(format.videoSupportedFrameRateRanges)
let frameRate = format.videoSupportedFrameRateRanges.first
print(format.formatDescription)
if let frameRate = frameRate, frameRate.maxFrameRate == 60.0 {
try defaultVideoDevice?.lockForConfiguration()
print(frameRate.maxFrameRate) //here prints 60.0
defaultVideoDevice?.activeVideoMaxFrameDuration = CMTimeMake(1,60)
defaultVideoDevice?.activeVideoMinFrameDuration = CMTimeMake(1,60)
defaultVideoDevice?.unlockForConfiguration()
}
}
}
}
'''
在 'defaultVideoDevice?.activeVideoMaxFrameDuration = CMTimeMake(1,60)' 行,我收到此錯誤:
2019-11-21 09:23:50.225376+0300 AVCam[1250:667986] * 由於未捕獲的異常 'NSInvalidArgumentException' 導致應用程序終止,原因:'* -[AVCaptureDevice setActiveVideoMaxFrameDuration:] 不支持的幀持續時間 - 使用 -activeFormat.videoSupportedFrameRateRanges 來發現有效范圍'
提前致謝。
您應該將有效格式設置為AVCaptureDevice
。
你可以這樣做
// get device what you like
let device = xxxxx
// list all default formats for this device
for format in device.formats {
var founded = false
// check what you want and pick a perfect format.
let formatDesc = format.formatDescription
// mediaType / SubType
let mediaType = format.mediaSubType
// if your target is above(equal) iOS 13. use formatDesc.mediaSubType
let mediaSubType = CMFormatDescriptionGetMediaSubType(formatDesc)
// dimensions
// if your target is above(equal) iOS 13. use formatDesc.dimensions
let dimensions = CMVideoFormatDescriptionGetDimensions(formatDesc)
// fps
let ranges = format.videoSupportedFrameRateRanges.first
for supportedFPSRange in ranges {
if supportedFPSRange.maxFrameRate == 60 {
founded = true
}
}
// support Multi cam
let isMultiCamSupported = format.isMultiCamSupported
....
if founded {
// Set activeFormat for device! Your capture device is up and loaded.
do {
try device.lockForConfiguration()
device.activeFormat = format
device.unlockForConfiguration()
} catch {
// catch some locking error
}
// Don't forget break the loop.:p
break
}
}
或者你可以使用filter
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.