Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement SlowMotion and TimeLapse video recording using Camera API

Is there any way to implement Slow Motion and Time Lapse recording using Camera API?

I tried using MediaRecorder setting VideoFrameRate, VideoBitRate VideoCaptureRate but nothing work for me.

I have successfully implemented using JNI but i found it is taking too much time and not optimized as well.

If you find any other solution available please help me.

like image 933
IshRoid Avatar asked Jan 06 '23 10:01

IshRoid


1 Answers

I solved it myself and i am sharing my working code piece , just using Camera API slow motion and timelapse are implemented

Before start you must know definition of setCaptureRate(double fps)

Set video frame capture rate. This can be used to set a different video frame capture rate than the recorded video's playback rate. This method also sets the recording mode to time lapse. In time lapse video recording, only video is recorded. Audio related parameters are ignored when a time lapse recording session starts, if an application sets them.

TimeLapse
For time lapse you need to use following camera profile , According to you video frame width and height. Choose any one from below profile or you may choose other according to your need.

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_1080P);

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_720P);

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_480P);

And now you need configure your video setCaptureRate and setVideoEncodingBitRate

video_recorder.setCaptureRate(profile.videoFrameRate/6.0f);
video_recorder.setVideoEncodingBitRate(profile.videoBitRate);

and at last you need to set your configured Profile to your MediaRecorder.

video_recorder.setProfile(profile);

Slow Motion
For slow motion you also need to configure CamcorderProfile i am using following config for profile.

profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH_SPEED_HIGH);
 video_recorder.setCaptureRate(profile.videoFrameRate / 0.25f);
video_recorder.setVideoEncodingBitRate(profile.videoBitRate);
video_recorder.setProfile(profile);

For slowmotion you have to use CameraAPI2 otherwise it will not work.

like image 103
IshRoid Avatar answered Mar 19 '23 03:03

IshRoid