如何使用相机实现慢动作和延时视频录制 API

How to implement SlowMotion and TimeLapse video recording using Camera API

有什么方法可以使用相机实现慢动作和延时摄影API?

我尝试使用 MediaRecorder 设置 VideoFrameRateVideoBitRate VideoCaptureRate,但对我没有用。

我已经成功地使用 JNI 实现了,但我发现它花费了太多时间并且也没有优化。

如果您发现任何其他可用的解决方案,请帮助我。

我自己解决了它,我正在分享我的工作代码片段,只使用相机 API 实现了慢动作和延时摄影

在开始之前你必须知道 setCaptureRate(double fps)

的定义

Set video frame capture rate. This can be used to set a different video frame capture rate than the recorded video's playback rate. This method also sets the recording mode to time lapse. In time lapse video recording, only video is recorded. Audio related parameters are ignored when a time lapse recording session starts, if an application sets them.

延时拍摄
对于延时,您需要使用以下相机配置文件,根据您的视频帧宽度和高度。 从下面的个人资料中选择一个,或者您可以根据需要选择其他。

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_1080P);

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_720P);

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_480P);

现在您需要配置视频 setCaptureRatesetVideoEncodingBitRate

video_recorder.setCaptureRate(profile.videoFrameRate/6.0f);
video_recorder.setVideoEncodingBitRate(profile.videoBitRate);

最后您需要将配置的配置文件设置到您的 MediaRecorder。

video_recorder.setProfile(profile);

慢动作
对于慢动作,您还需要配置 CamcorderProfile 我正在使用以下配置文件。

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH_SPEED_HIGH);
 video_recorder.setCaptureRate(profile.videoFrameRate / 0.25f);
video_recorder.setVideoEncodingBitRate(profile.videoBitRate);
video_recorder.setProfile(profile);

对于慢动作你必须使用相机API2 否则它不会工作。