如何使用Camera API实现SlowMotion和TimeLapse视频录制

Ish*_*oid 3 video android frame-rate android-camera android-mediarecorder

有没有办法使用Camera API实现慢动作和延时录音?

我尝试过使用MediaRecorder设置VideoFrameRate,VideoBitRate VideoCaptureRate但对我来说没什么用.

我已成功使用JNI实现,但我发现它花费了太多时间而且没有进行优化.

如果您找到任何其他解决方案,请帮助我.

Ish*_*oid 8

我自己解决了,我正在分享我的工作代码片段,只使用Camera API慢动作和实现游戏中时光倒流

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

设置视频帧捕获率.这可用于设置与录制视频的播放速率不同的视频帧捕获速率.该方法还将记录模式设置为时间流逝.在定时视频录制中,仅录制视频.如果应用程序设置了时间间隔记录会话,则会忽略音频相关参数.

TimeLapse
对于时间流逝,您需要使用以下相机配置文件,根据您的视频帧宽度和高度.从下面的配置文件中选择任何一个,或者您可以根据需要选择其他.

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_1080P);

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_720P);

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_480P);
Run Code Online (Sandbox Code Playgroud)

现在你需要配置你的视频setCaptureRatesetVideoEncodingBitRate

video_recorder.setCaptureRate(profile.videoFrameRate/6.0f);
video_recorder.setVideoEncodingBitRate(profile.videoBitRate);
Run Code Online (Sandbox Code Playgroud)

最后,您需要将配置的配置文件设置为MediaRecorder.

video_recorder.setProfile(profile);
Run Code Online (Sandbox Code Playgroud)

慢动作
对于慢动作,您还需要配置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);
Run Code Online (Sandbox Code Playgroud)

对于慢动作,你必须使用CameraAPI2,否则它将无法正常工作.