【问题标题】:60 fps video recording problem even it is capable swift60 fps 视频录制问题,即使它能够快速
【发布时间】:2020-06-09 17:09:41
【问题描述】:

我正在尝试通过修改 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 发现有效范围'

提前致谢。

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    您应该将有效格式设置为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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-08
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 2020-11-22
      相关资源
      最近更新 更多