【问题标题】:How to implement SlowMotion and TimeLapse video recording using Camera API如何使用 Camera API 实现 SlowMotion 和 TimeLapse 视频录制
【发布时间】:2016-07-10 14:54:01
【问题描述】:

有没有办法使用相机 API 实现慢动作和延时录制?

我尝试使用 MediaRecorder 设置 VideoFrameRate, VideoBitRate VideoCaptureRate 但对我没有任何作用。

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

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

【问题讨论】:

  • 这两个挑战非常不同。虽然 SlowMotion 依赖于高 FPS 原生相机支持,但 TimeLapse 可以使用 MediaCodec 执行。见stackoverflow.com/questions/30972081/…github.com/saki4510t/TimeLapseRecordingSample
  • 另一个开源项目是github.com/mercyorangi/sky-camera
  • @AlexCohn 感谢您的尝试,但上面的代码对我不起作用,以防慢动作。
  • 当然。我提供的链接只是关于 TimeLapse。据我所知,没有一种独立于设备的方式来制作慢动作视频。 camera2 API 可以提供帮助,但仅在少数最近的设备上完全支持。
  • 您好,感谢您的回答,您知道已经以 120 fps 速率拍摄的安卓相机应用程序(第三方)吗?谢谢

标签: android video android-camera android-mediarecorder frame-rate


【解决方案1】:

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

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

设置视频帧捕获率。 这可用于设置不同的视频帧捕获率,而不是 录制视频的播放速率。此方法还设置录制 模式到时间流逝。在延时视频录制中,只有视频是 记录下来。时间流逝时忽略音频相关参数 如果应用程序设置了它们,则记录会话开始。

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

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);

最后,您需要将配置的 Profile 设置为 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);

对于慢动作,您必须使用 CameraAPI2,否则它将无法工作。

【讨论】:

  • 您好,感谢您的回答,您知道已经以 120 fps 速率拍摄的安卓相机应用程序(第三方)吗?谢谢
  • Google 相机 API 2 示例捕获 120fps。但 API 2 取决于设备硬件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-03
相关资源
最近更新 更多