1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Android]カメラで利用可能なFPSを判定する

Last updated at Posted at 2021-09-19

これはなに

Android のカメラで、対応しているFPSを判定するためのコードメモ
解像度XXXに対する最高FPSを返すようなAPIがあれば便利なんですが、見つからなかったので、特定の解像度とFPSの組み合わせで利用可能かどうか判定しています。

あまり自信はないので、おかしいところは指摘いただけたらと思います。

コード

    var mCameraId: Int? = null

    private fun findCameraId() {
        var manager = activity?.getSystemService(Context.CAMERA_SERVICE) as CameraManager
        var camerIds: Array<out String> = manager.getCameraIdList()
        for (cameraId in camerIds) {
            if (checkCameraFPS(cameraId.toInt(),
                    CamcorderProfile.QUALITY_1080P, // 利用可能なFPSはカメラの設定で異なる。ここでは1080pに対しての60FPSが利用可能か確認している
                    60) 
            ) {
                mCameraId = cameraId.toInt()
                break
            }
        }
    }

    // 特定の解像度とFPSの組み合わせで利用可能かどうか判定
    private fun checkCameraFPS(camaraId: Int, quality: Int, targetFPS: Int): Boolean {
        val profile = CamcorderProfile.get(camaraId, quality)
        val videoFrameRate = profile.videoFrameRate
        return videoFrameRate >= targetFPS
    }

以上です

参考:
https://stackoverflow.com/questions/36904707/how-to-know-maximum-supported-fps-by-android-device-on-api-level
https://developer.android.com/reference/android/media/CamcorderProfile.html

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?