Closed5

AVCaptureDeviceのフォーマット

yorifujiyorifuji
        guard let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) else { return }
        print("------------")
        print(device.activeFormat)
        print("------------")
        for format in device.formats { print(format) }
        print("------------")
yorifujiyorifuji
------------
<AVCaptureDeviceFormat: 0x28281d1e0 'vide'/'420v' 1920x1080, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:16.00 (upscales @1.94), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports multicam>
------------
<AVCaptureDeviceFormat: 0x28281c150 'vide'/'420v'  192x 144, { 1- 60 fps}, HRSI:4032x3024, fov:64.720, max zoom:189.00 (upscales @21.00), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281c140 'vide'/'420f'  192x 144, { 1- 60 fps}, HRSI:4032x3024, fov:64.720, max zoom:189.00 (upscales @21.00), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281c130 'vide'/'420v'  352x 288, { 1- 60 fps}, HRSI:3696x3024, fov:59.327, max zoom:189.00 (upscales @10.50), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281c120 'vide'/'420f'  352x 288, { 1- 60 fps}, HRSI:3696x3024, fov:59.327, max zoom:189.00 (upscales @10.50), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281c110 'vide'/'420v'  480x 360, { 1- 60 fps}, HRSI:4032x3024, fov:64.720, max zoom:189.00 (upscales @8.40), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281c100 'vide'/'420f'  480x 360, { 1- 60 fps}, HRSI:4032x3024, fov:64.720, max zoom:189.00 (upscales @8.40), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281c0f0 'vide'/'420v'  640x 480, { 1- 60 fps}, HRSI:4032x3024, fov:64.720, max zoom:189.00 (upscales @6.30), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281c0e0 'vide'/'420f'  640x 480, { 1- 60 fps}, HRSI:4032x3024, fov:64.720, max zoom:189.00 (upscales @6.30), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281c0d0 'vide'/'420v'  640x 480, { 1- 60 fps}, HRSI:1920x1440, fov:59.308, binned, max zoom:90.00 (upscales @3.00), AF System:2, ISO:34.0-3264.0, SS:0.000025-1.000000, supports multicam>
<AVCaptureDeviceFormat: 0x28281c0c0 'vide'/'420f'  640x 480, { 1- 60 fps}, HRSI:1920x1440, fov:59.308, binned, max zoom:90.00 (upscales @3.00), AF System:2, ISO:34.0-3264.0, SS:0.000025-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281c0b0 'vide'/'420v'  960x 540, { 1- 60 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:32.00 (upscales @3.88), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281c0a0 'vide'/'420f'  960x 540, { 1- 60 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:32.00 (upscales @3.88), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281c090 'vide'/'420v' 1024x 768, { 1- 60 fps}, HRSI:4032x3024, fov:64.720, supports vis, max zoom:30.00 (upscales @3.58), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281c080 'vide'/'420f' 1024x 768, { 1- 60 fps}, HRSI:4032x3024, fov:64.720, supports vis, max zoom:30.00 (upscales @3.58), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281c070 'vide'/'420v' 1280x 720, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:24.00 (upscales @2.91), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281c060 'vide'/'420f' 1280x 720, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:24.00 (upscales @2.91), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281c050 'vide'/'x420' 1280x 720, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:120.00 (upscales @2.91), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports wide color>
<AVCaptureDeviceFormat: 0x28281d150 'vide'/'420v' 1280x 720, { 1- 60 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:24.00 (upscales @2.91), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281d160 'vide'/'420f' 1280x 720, { 1- 60 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:24.00 (upscales @2.91), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281d170 'vide'/'x420' 1280x 720, { 1- 60 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:120.00 (upscales @2.91), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports wide color>
<AVCaptureDeviceFormat: 0x28281d180 'vide'/'420v' 1280x 720, { 1- 60 fps}, HRSI:2048x1152, fov:68.161, binned, supports vis, max zoom:24.00 (upscales @1.45), AF System:1, ISO:34.0-3264.0, SS:0.000025-1.000000, supports multicam>
<AVCaptureDeviceFormat: 0x28281d190 'vide'/'420f' 1280x 720, { 1- 60 fps}, HRSI:2048x1152, fov:68.161, binned, supports vis, max zoom:24.00 (upscales @1.45), AF System:1, ISO:34.0-3264.0, SS:0.000025-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d1a0 'vide'/'420v' 1280x 720, { 1-240 fps}, fov:68.161, binned, supports vis, max zoom:65.50 (upscales @1.45), AF System:1, ISO:34.0-1360.0, SS:0.000025-1.000000>
<AVCaptureDeviceFormat: 0x28281d1b0 'vide'/'420f' 1280x 720, { 1-240 fps}, fov:68.161, binned, supports vis, max zoom:65.50 (upscales @1.45), AF System:1, ISO:34.0-1360.0, SS:0.000025-1.000000, supports wide color>
<AVCaptureDeviceFormat: 0x28281d1c0 'vide'/'420v' 1440x1080, { 1- 60 fps}, HRSI:1920x1440, fov:59.308, binned, max zoom:90.00 (upscales @1.33), AF System:2, ISO:34.0-3264.0, SS:0.000025-1.000000, supports multicam>
<AVCaptureDeviceFormat: 0x28281d1d0 'vide'/'420f' 1440x1080, { 1- 60 fps}, HRSI:1920x1440, fov:59.308, binned, max zoom:90.00 (upscales @1.33), AF System:2, ISO:34.0-3264.0, SS:0.000025-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d1e0 'vide'/'420v' 1920x1080, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:16.00 (upscales @1.94), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports multicam>
<AVCaptureDeviceFormat: 0x28281d1f0 'vide'/'420f' 1920x1080, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:16.00 (upscales @1.94), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d200 'vide'/'x420' 1920x1080, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:120.00 (upscales @1.94), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d210 'vide'/'420v' 1920x1080, { 1- 60 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:16.00 (upscales @1.94), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports multicam>
<AVCaptureDeviceFormat: 0x28281d220 'vide'/'420f' 1920x1080, { 1- 60 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:16.00 (upscales @1.94), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d230 'vide'/'x420' 1920x1080, { 1- 60 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:120.00 (upscales @1.94), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d240 'vide'/'420v' 1920x1080, { 1- 60 fps}, HRSI:2048x1152, fov:68.161, binned, supports vis, max zoom:16.00 (upscales @1.00), AF System:1, ISO:34.0-3264.0, SS:0.000025-1.000000, supports multicam>
<AVCaptureDeviceFormat: 0x28281d250 'vide'/'420f' 1920x1080, { 1- 60 fps}, HRSI:2048x1152, fov:68.161, binned, supports vis, max zoom:16.00 (upscales @1.00), AF System:1, ISO:34.0-3264.0, SS:0.000025-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d260 'vide'/'420v' 1920x1080, { 1-120 fps}, fov:37.609, supports vis, max zoom:130.88 (upscales @1.94), AF System:2, ISO:34.0-1360.0, SS:0.000014-1.000000>
<AVCaptureDeviceFormat: 0x28281d270 'vide'/'420f' 1920x1080, { 1-120 fps}, fov:37.609, supports vis, max zoom:130.88 (upscales @1.94), AF System:2, ISO:34.0-1360.0, SS:0.000014-1.000000, supports wide color>
<AVCaptureDeviceFormat: 0x28281d280 'vide'/'420v' 1920x1080, { 1-240 fps}, fov:68.161, binned, supports vis, max zoom:65.50 (upscales @1.00), AF System:1, ISO:34.0-1360.0, SS:0.000025-1.000000>
<AVCaptureDeviceFormat: 0x28281d290 'vide'/'420f' 1920x1080, { 1-240 fps}, fov:68.161, binned, supports vis, max zoom:65.50 (upscales @1.00), AF System:1, ISO:34.0-1360.0, SS:0.000025-1.000000, supports wide color>
<AVCaptureDeviceFormat: 0x28281d2a0 'vide'/'420v' 1920x1440, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @2.10), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports multicam>
<AVCaptureDeviceFormat: 0x28281d2b0 'vide'/'420f' 1920x1440, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @2.10), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d2c0 'vide'/'x420' 1920x1440, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @2.10), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d2d0 'vide'/'420v' 1920x1440, { 1- 60 fps}, HRSI:1920x1440, fov:63.901, binned, max zoom:90.00 (upscales @1.00), AF System:2, ISO:34.0-3264.0, SS:0.000025-1.000000, supports multicam>
<AVCaptureDeviceFormat: 0x28281d2e0 'vide'/'420f' 1920x1440, { 1- 60 fps}, HRSI:1920x1440, fov:63.901, binned, max zoom:90.00 (upscales @1.00), AF System:2, ISO:34.0-3264.0, SS:0.000025-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d2f0 'vide'/'420v' 2592x1944, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @1.56), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281d300 'vide'/'420f' 2592x1944, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @1.56), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281d310 'vide'/'420v' 3264x2448, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @1.24), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281d320 'vide'/'420f' 3264x2448, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @1.24), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281d330 'vide'/'420v' 3840x2160, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:9.00 (upscales @1.00), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports multicam>
<AVCaptureDeviceFormat: 0x28281d340 'vide'/'420f' 3840x2160, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:9.00 (upscales @1.00), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d350 'vide'/'x420' 3840x2160, { 1- 30 fps}, HRSI:4096x2304, fov:68.161, supports vis, max zoom:125.25 (upscales @1.00), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports wide color, supports multicam>
<AVCaptureDeviceFormat: 0x28281d360 'vide'/'420v' 3840x2160, { 1- 60 fps}, fov:68.161, supports vis, max zoom:9.00 (upscales @1.00), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281d370 'vide'/'420f' 3840x2160, { 1- 60 fps}, fov:68.161, supports vis, max zoom:9.00 (upscales @1.00), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports HDR, supports wide color>
<AVCaptureDeviceFormat: 0x28281d380 'vide'/'x420' 3840x2160, { 1- 60 fps}, fov:68.161, supports vis, max zoom:125.25 (upscales @1.00), AF System:2, ISO:34.0-3264.0, SS:0.000014-1.000000, supports wide color>
<AVCaptureDeviceFormat: 0x28281d390 'vide'/'420v' 4032x3024, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @1.00), AF System:2, ISO:34.0-7616.0, SS:0.000014-1.000000, supports HDR>
<AVCaptureDeviceFormat: 0x28281d3a0 'vide'/'420f' 4032x3024, { 1- 30 fps}, HRSI:4032x3024, fov:67.096, max zoom:189.00 (upscales @1.00), AF System:2, ISO:34.0-7616.0, SS:0.000014-1.000000, supports HDR, supports wide color>
yorifujiyorifuji

特定のfpsのフォーマットを使う場合は以下のようなコードを書くと良い。

  • 指定のfpsがrangeに含まれていて
  • widthが一致するものが見つかったら終了
        guard let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) else { return }
//        print(device.activeFormat)

        var format: AVCaptureDevice.Format? = nil
        let fps_f64 = Float64(fps)
        for range in device.activeFormat.videoSupportedFrameRateRanges {
            if range.minFrameRate <= fps_f64 && fps_f64 <= range.maxFrameRate {
                format = device.activeFormat
            }
        }
        if format == nil {
            found: for f in device.formats {
//                print(f)
                for range in f.videoSupportedFrameRateRanges {
                    if range.minFrameRate <= fps_f64 && fps_f64 <= range.maxFrameRate {
                        format = f
                        if CMVideoFormatDescriptionGetDimensions(f.formatDescription).width == CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription).width {
                            break found
                        }
//                        if CMVideoFormatDescriptionGetDimensions(f.formatDescription).width >= 1024 {  // enough
//                            break found
//                        }
                    }
                }
            }
        }
//        print(format!)

        if let format = format {
            do {
                try device.lockForConfiguration()
                device.activeFormat = format
                device.activeVideoMinFrameDuration = CMTimeMake(value: 1, timescale: fps)
                device.activeVideoMaxFrameDuration = CMTimeMake(value: 1, timescale: fps)
                device.unlockForConfiguration()
            } catch {
                print("failed to set format")
            }
        }
このスクラップは2021/09/07にクローズされました