11

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.

Siddharth
  • 396
  • 2
  • 14
  • Just a guess, but did you actually try to call `setVideoFrameRate` and `setVideoEncodingBitRate` manually? Did you check the values your profile is submitting? – damian Feb 24 '16 at 16:39
  • Yes @damian, I call the following just before prepare: `mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate/4);` `mMediaRecorder.setVideoFrameRate(profile.videoFrameRate/4);` The profile `videoBitRate` is `27000000` and `videoFrameRate` is `120` – Siddharth Feb 26 '16 at 19:42
  • Hi, @Siddharth. Did you ever figure out a solution to this? I am having the same problem. – flutillie Apr 03 '16 at 02:18
  • @flutillie No. Could not solve this problem. Please do comment if you have any suggestions. – Siddharth Apr 23 '16 at 10:28
  • @Siddharth Any solutions? Stuck in same issue. – Murtuza Saifee May 30 '16 at 07:48
  • Hello, thanks for the answer, do you know an android camera application (third-party) which already capture at 120 fps rate? Thanks – Jugali Lakota Jun 04 '16 at 23:13

1 Answers1

-1
mMediaRecorder.setVideoFrameRate(QUALITY_HIGH_SPEED_LOW);

or

mMediaRecorder.setVideoFrameRate(QUALITY_HIGH_SPEED_HIGH);
Phiter
  • 14,570
  • 14
  • 50
  • 84
Ajin kumar
  • 311
  • 1
  • 3
  • 14
  • 1
    The [doc](https://developer.android.com/intl/es/reference/android/media/CamcorderProfile.html#QUALITY_HIGH_SPEED_HIGH) says that value of `CamcorderProfile.QUALITY_HIGH_SPEED_HIGH` is `2001`. I doubt I can set videoFrameRate as 2001. Can you elaborate your answer? – Siddharth Mar 03 '16 at 16:58