How to programmatically record high speed videos (

2019-04-16 10:42发布

问题:

I have a piece of code that can use the android camera to record videos at QUALITY_HIGH using MediaRecorder and the camera api 1.

The camera code is based off: https://github.com/Glamdring/EasyCamera

And the video recording might resemble this: How to record video of particular width and height on samsung device android?

I can see from the documentation http://developer.android.com/intl/es/reference/android/media/CamcorderProfile.html#QUALITY_HIGH_SPEED_HIGH that there's a profile for high speed video but... calling this:

 CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH_SPEED_LOW);

throws an exception saying:

"E/MediaProfiles: The given camcorder profile camera 0 quality 2000 is not found"

calling:

 mMediaRecorder.setVideoFrameRate(100);

runs but the output video is not 100fps.

and calling:

 mMediaRecorder.setVideoFrameRate(CamcorderProfile.QUALITY_HIGH_SPEED_LOW);

throws an exception:

MediaRecorder: setVideoFrameRate failed: -22

I can use the built in camera application to record a "slow motion video" which will produce an mp4 at 120fps so I am pretty sure that the device can record a high speed video but something seems missing.

回答1:

First check the supported fps range of your camera device using getSupportedPreviewFpsRange.

I also did a test on a smartphone built-in camera app that supports slow motion and can indeed record at high frame rate (120fps). But from the results of getSupportedPreviewFpsRange, the frame rate is no more than 30fps.

I think the vendor does not originally provide the interface to record at high frame rate although the built-in camera app shows its hardware ability to do so. I guess this is because it may cause unexpected results such as hardware damage if it is not used properly.

The hardware requirement of recording high speed videos is higher than that of recording conventional videos. The built-in camera app may use a different recording strategy for slow motion videos. For example, it may use a lower resolution and different responses to light. Thus the access to programmatically recording high speed videos is not exposed.

However, there is a hack solution in here which utilizes the new camera2 API. You need root and it may not be stable.