I'm implementing video recording with Android camera. I use MediaCodec to encode frames from onPreviewFrame() callback.
Now I want to record slow motion video. How can I set the camera capture rate or frame rate? Where can I set these parameters, for example, if I want to record at 120fps, and play at 30fps?
The following is what I have researched:
I recorded a slow-motion video with MOTO X (having built-in slow-motion video recording function) and used FFmpeg to check its fps. I found it records at 110 fps(near 120fps) and playback at 30fps. This proves that it provides hardware support for recording at high fps.
However, when I use getSupportedPreviewFpsRange to check its supported fps range, there are only 4 sets supported fps range with no one greater than 30fps:
min_fps: 15.0 , max_fps15.0
min_fps: 15.0 , max_fps20.0
min_fps: 15.0 , max_fps30.0
min_fps: 24.0 , max_fps30.0
I used setPreviewFpsRange to set the fps higher, but it remains no more than 30fps. I also tried set KEY_FRAME_RATE and KEY_CAPTURE_RATE of MediaFormat. But it still does not work.
I have also searched the solution by setting CamcorderProfile or setVideoFrameRate with MediaRecorder. But I'm doing with MediaCodec.
Can anyone help me with this problem?
I think this question encloses two separate problems.
MediaCodec
encoder?The second part is simple. As described in this answer, you can either insert interpolating/dummy frames, or modify time stamps. The first part is peculiar in that most sample codes deal with normal mode of capturing rather than high-speed captures required in this use case (usually higher than 60FPS, and generally speaking, we are dealing with 120~240FPS.)
About the first part of the question, I would like you to take a look at the description about Camera2 constrained high-speed capture APIs, like this. Unfortunately, there seem to be only niche demand on such an API and I was not able to gather much information upon my own findings, and I am currently dealing with mentally taxing projects myself to create a sample code by myself. However, judging from its similarity with ordinary movie recording and burst shots, I don't think deriving such a use case would be that much complex.