6

I'm trying to record a video at 60(or more)fps rate on Camera2(android.hardware.camera2) APIs.

Finally, I succeeded recording at 120fps using CameraConstrainedHighSpeedCaptureSession. But it is only targeted at >=120fps use case not for 60fps.

Even I tried to record at 60fps using normal capture session(CameraCaptureSession), it only supports <=30fps. I could figure it out through this code below.

Range<Integer>[] fpsRanges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);

I don't know how I could record at 60fps with Camera2 APIs.

Any idea would be most welcome.

Thanks.

Sunggook Kim
  • 165
  • 1
  • 3
  • 10

2 Answers2

1

You must create a ConstrainedHighSpeedCaptureSession from CameraDevice and instantiate a new session as you possibly did with a normal capture session.

Also you need to set the next values to your Builder:

myPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
myPreviewRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
myPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range<Integer>(frameRate, frameRate));

After, generate a CaptureRequestList with your builder:

 myHighSpeedRequestList = ((CameraConstrainedHighSpeedCaptureSession) cameraCaptureSession).createHighSpeedRequestList(myPreviewRequestBuilder.build());

and use it in your capture Session to generate the CaptureSession:

mCaptureSession.setRepeatingBurst(myHighSpeedRequestList,
                                  YourHighSpeedVideoCaptureCallback,
                                  YourBackgroundHandler);
halfer
  • 19,824
  • 17
  • 99
  • 186
Francisco Durdin Garcia
  • 12,540
  • 9
  • 53
  • 95
  • 3
    Isn't this for >= 120 fps video capture? – goudarziha Jun 27 '16 at 17:31
  • I modify CONTROL_AE_TARGET_FPS_RANGE to get the range that I want to use – Francisco Durdin Garcia Jun 28 '16 at 06:41
  • Thanks @FranciscoDurdinGarcia . But as I already mentioned, the documentation for [CameraConstrainedHighSpeedCaptureSession](https://developer.android.com/reference/android/hardware/camera2/CameraConstrainedHighSpeedCaptureSession.html) said it is targeted above 120fps not for 60fps. Did you checked it working on 60fps? – Sunggook Kim Jun 29 '16 at 02:17
  • In addition, I could see error message as "java.lang.IllegalArgumentException: Fps range [60, 60] in the request is not a supported high speed fps range [[30, 120], [120, 120]] " when I try to put fps ranges as (60, 60). – Sunggook Kim Jun 29 '16 at 06:58
  • that's cause your device resolution doesn't support that fps range.It depends of which device are you using. The app that I worked for was for a device which support in 16:9 and 4:3(with a 1080p resolution) 60fps range. In other way, it was not possible to set a 60fps range for 4K and 720p .I will check my code later to see if i can support you in something else – Francisco Durdin Garcia Jun 29 '16 at 07:19
  • But I think it was caused by limitation of ConstrainedHighSpeedCaptureSession not caused by device resolution. Or if you could add a little more of your code which is working at 60fps, it'll be more helpful to understand. – Sunggook Kim Jun 30 '16 at 07:27
  • 1
    I can't share a lot of this code :S. But anyway, I'm just creating a ConstrainedHighSpeedCaptureSession adding the 3 sets that I post before to the builder, creating the list and setting the RepeatingBurst. Nothing else, just catch exceptions and some conditions to avoid Force closes when the camera device or the session are null – Francisco Durdin Garcia Jun 30 '16 at 08:53
  • 6
    This answer is invalid. You can't use high speed capture session for 60 FPS recording, period. – b005t3r Dec 11 '17 at 08:27
  • 2
    @FranciscoDurdinGarcia I completely disagree with your answer. Why on earth would the documentation be so wrong about the `CameraConstrainedHighSpeedCaptureSession`? – Ashutosh Tiwari Jan 03 '20 at 06:51
  • @AshutoshTiwari Did you find any solution to this problem? I still can't find a characteristic I can read to check if the camera supports 60fps, as the "target fps ranges" are always 30. My system camera records 60fps though. – mrousavy Jan 12 '21 at 09:00
  • what an ignorant answer, you can't use `myPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range(frameRate, frameRate));` for not supported fps ranges, if Camera2 reports that it's `..30` maximum then you can't just set `..60`, you will get an exepection – user924 Feb 28 '23 at 14:00
-1

Use the following code:

private fun recordSession() {
    setUpMediaRecorder()

    val surfaceTexture = textureView.surfaceTexture

    surfaceTexture?.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
    captureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD)
    val surfaces = ArrayList<Surface>()

    val textureSurface = Surface(surfaceTexture)
    surfaces.add(textureSurface)
    captureRequestBuilder.addTarget(textureSurface)


    val recordSurface = mediaRecorder.surface
    surfaces.add(recordSurface)
    captureRequestBuilder.addTarget(recordSurface)


    mCameraDevice.createCaptureSession(
        surfaces,
        object : CameraCaptureSession.StateCallback() {

            override fun onConfigured(session: CameraCaptureSession) {
                captureSession = session
                val fps: Int = if (PreferenceProvider.getIsFrontCameraOpened()) {
                    PreferenceProvider.getFrontCameraVideoFrameRate()
                } else {
                    PreferenceProvider.getBackCameraVideoFrameRate()
                }
                captureRequestBuilder.set(
                    CaptureRequest.CONTROL_MODE,
                    CaptureRequest.CONTROL_MODE_USE_SCENE_MODE
                )
                captureRequestBuilder.set(
                    CaptureRequest.CONTROL_SCENE_MODE,
                    CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO
                )
                captureRequestBuilder.set(
                    CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,
                    Range(fps, fps)
                )
                captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, currentExposureLevel)
                updatePreview()
                isRecording = true
                mediaRecorder.start()
            }

            override fun onConfigureFailed(session: CameraCaptureSession) {
                showLog(TAG, "Failed to create CameraRecordSession!")
            }

        },
        mBackgroundHandler
    )
}

NOTE: Make sure you're setting the same frame rate(i.e. 60) in MediaRecorder Configs to get the 60fps effect in the video.

mendax01
  • 31
  • 6