Android capturing slow motion video using CamcorderProfile

淺唱寂寞╮ 提交于 2019-12-09 15:27:23

问题


I am trying to capture slow motion video on my Nexus 5x. This is how I am configuring the media recorder:

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

The problem is, the captured videos are not the 120 fps slow motion videos that my device supports. They are the regular 29 fps videos.

I went through this answer, which talks about the following in the 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.

The thing that I don't get is, setProfile already calls the two methods setVideoFrameRate and setVideoEncodingBitRate with parameters derived from the chosen CamcorderProfile. Why do I need to call them again? What am I missing here?

Any help would be greatly appreciated. For the life of me, I cannot get this to work!

EDIT: I have tried calling the methods like so but it still captures normal speed video:

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

1/4 since the advertised frame rate by the CamcorderProfile.QUALITY_HIGH_SPEED_HIGH is 120 and I want to capture a 30 fps video as stated in the document here

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.


回答1:


mMediaRecorder.setVideoFrameRate(QUALITY_HIGH_SPEED_LOW);

or

mMediaRecorder.setVideoFrameRate(QUALITY_HIGH_SPEED_HIGH);


来源:https://stackoverflow.com/questions/35116159/android-capturing-slow-motion-video-using-camcorderprofile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!