简体   繁体   English

60 fps 视频录制问题,即使它有能力 swift

[英]60 fps video recording problem even it is capable swift

I am trying to record 60 fps video by modifying AVCAM application which can be found at:我正在尝试通过修改 AVCAM 应用程序来录制 60 fps 视频,该应用程序位于:

https://github.com/Lax/Learn-iOS-Swift-by-Examples/tree/master/AVCam/Swift/AVCam https://github.com/Lax/Learn-iOS-Swift-by-Examples/tree/master/AVCam/Swift/AVCam

Hence, it is normally getting 2-30 fps with my phone (iPhone X) and I tried to change the format it captures video.因此,我的手机(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()
                        }
                    }
                }
            }

''' '''

Here at the line of 'defaultVideoDevice?.activeVideoMaxFrameDuration = CMTimeMake(1,60)' I am getting this error:在 'defaultVideoDevice?.activeVideoMaxFrameDuration = CMTimeMake(1,60)' 行,我收到此错误:

2019-11-21 09:23:50.225376+0300 AVCam[1250:667986] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[AVCaptureDevice setActiveVideoMaxFrameDuration:] Unsupported frame duration - use -activeFormat.videoSupportedFrameRateRanges to discover valid ranges' 2019-11-21 09:23:50.225376+0300 AVCam[1250:667986] * 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'* -[AVCaptureDevice setActiveVideoMaxFrameDuration:] 不支持的帧持续时间 - 使用 -activeFormat.videoSupportedFrameRateRanges 来发现有效范围'

Thanks in advance.提前致谢。

You should set a valid format to AVCaptureDevice .您应该将有效格式设置为AVCaptureDevice

You can do this你可以这样做

// 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
    }
}

Or you can use filter或者你可以使用filter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM