Android capturing slow motion video

Android Developer picture Android Developer · Oct 16, 2015 · Viewed 7.7k times · Source

How can i capture slow motion video in my app?

I tried using

 mMediaRecorder.setVideoFrameRate(100);

but app crashes if i set the value 20 or more with IllegalStateException.

I have researched a lot.Normal video is between 24 and 30 fps.To see slow motion video we need to capture 100-120 fps but device does not allow that.But I see the default camera in my device has an option of Slow motion.Also few apps in play store allow to create slow motion videos.I also tried setting higher setCaptureRate(),but with that also normal mode video is captured.At few places it is mentioned that slow motion movie can be accomplished through OpenCV/JavaCV libraries but i failed to understand how to use these libraries to capture slow motion video in android?

Answer

Bonatti picture Bonatti · Oct 16, 2015

From the source you provided (CamcorderProfile), all you have to do is INCREASE taken images per second:

mMediaRecorder.setVideoFrameRate(QUALITY_HIGH_SPEED_LOW);

or

mMediaRecorder.setVideoFrameRate(QUALITY_HIGH_SPEED_HIGH);

So, if you take a 100 images per seconds, and show 25 Frames per second, that recorded second takes 4 seconds to shown

Please, read the documentation on the class you are using:

public static final int QUALITY_HIGH_SPEED_LOW

High speed ( >= 100fps) quality level corresponding to the lowest available resolution.

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.