Android 使用 CamcorderProfile 捕捉慢动作视频

标签 android android-camera android-mediarecorder slowmotion

我正尝试在我的 Nexus 5x 上拍摄慢动作视频。这就是我配置媒体记录器的方式:

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

mMediaRecorder = new MediaRecorder();

// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);

// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

// Step 3: Set the high speed CamcorderProfile
mMediaRecorder.setProfile(profile);

// Step 4: Set output file
// Step 5: Prepare media recorder
// Step 6: Capture video

问题是,捕获的视频不是我的设备支持的 120 fps 慢动作视频。它们是常规的 29 fps 视频。

我经历了this answer ,在 official documentation 中讨论了以下内容:

For all the high speed profiles defined below ((from QUALITY_HIGH_SPEED_LOW to QUALITY_HIGH_SPEED_2160P), they are similar as normal recording profiles, with just higher output frame rate and bit rate. Therefore, setting these profiles with setProfile(CamcorderProfile) without specifying any other encoding parameters will produce high speed videos rather than slow motion videos that have different capture and output (playback) frame rates. To record slow motion videos, the application must set video output (playback) frame rate and bit rate appropriately via setVideoFrameRate(int) and setVideoEncodingBitRate(int) based on the slow motion factor. If the application intends to do the video recording with MediaCodec encoder, it must set each individual field of MediaFormat similarly according to this CamcorderProfile.

我不明白的是,setProfile已经使用从所选 CamcorderProfile 派生的参数调用了两个方法 setVideoFrameRate 和 setVideoEncodingBitRate。为什么我需要再次给他们打电话?我在这里缺少什么?

如有任何帮助,我们将不胜感激。对于我的生活,我无法让它工作!

编辑:我试过像这样调用方法,但它仍然捕获正常速度的视频:

mMediaRecorder.setVideoFrameRate(profile.videoFrameRate/4); 
mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate/4);

1/4,因为 CamcorderProfile.QUALITY_HIGH_SPEED_HIGH 宣传的帧速率是 120,我想捕捉文档 here 中所述的 30 fps 视频

public int videoFrameRate

Added in API level 8 The target video frame rate in frames per second.

This is the target recorded video output frame rate per second if the application configures the video recording via setProfile(CamcorderProfile) without specifying any other MediaRecorder encoding parameters. For example, for high speed quality profiles (from QUALITY_HIGH_SPEED_LOW to QUALITY_HIGH_SPEED_2160P), this is the frame rate where the video is recorded and played back with. If the application intends to create slow motion use case with the high speed quality profiles, it must set a different video frame rate that is corresponding to the desired output (playback) frame rate via setVideoFrameRate(int). For example, if QUALITY_HIGH_SPEED_720P advertises 240fps videoFrameRate in the CamcorderProfile, and the application intends to create 1/8 factor slow motion recording videos, the application must set 30fps via setVideoFrameRate(int). Failing to do so will result in high speed videos with normal speed playback frame rate (240fps for above example). If the application intends to do the video recording with MediaCodec encoder, it must set each individual field of MediaFormat similarly according to this CamcorderProfile.

最佳答案

mMediaRecorder.setVideoFrameRate(QUALITY_HIGH_SPEED_LOW);

mMediaRecorder.setVideoFrameRate(QUALITY_HIGH_SPEED_HIGH);

关于Android 使用 CamcorderProfile 捕捉慢动作视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35116159/

相关文章:

android - 如何在用户长按主页时暂停我的应用程序?

java - 在 android 中处理视频(裁剪、叠加等)——如何?

android - MediaPlayer 将数据源设置为字符串

android - 我想使用 mediaplayer 来录制声音,然后计算 "amplitude"以随着声音的变化上下移动 Bars

Android相机预览回调和mediarecorder录制视频

android - 使用样式在主题中设置 Activity 背景?

php - 单选按钮的值无法存储到 String 中并保存在 mysql 中

android - 在 Fragment android 中实现 AsyncTask

android - Android 设备摄像头图像的人体形状检测

android - 在 Camera2 API 中切换闪光灯