4

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.

Eric B.
  • 4,622
  • 2
  • 18
  • 33
IshRoid
  • 3,696
  • 2
  • 26
  • 39
  • The two challenges are very different. While SlowMotion depends on high-FPS native camera support, TimeLapse can be performed with MediaCodec. See http://stackoverflow.com/questions/30972081/how-to-drop-frames-while-recording-with-mediacodec-and-inputsurface and https://github.com/saki4510t/TimeLapseRecordingSample – Alex Cohn Mar 29 '16 at 09:11
  • Another open-source project is https://github.com/mercyorangi/sky-camera – Alex Cohn Mar 29 '16 at 09:16
  • @AlexCohn thank you for trying but above code doesn't work for me, in case of slow motion. – IshRoid Mar 30 '16 at 17:29
  • 1
    Absolutely. The links I gave were only about TimeLapse. There is no device-independent way to produce slow motion video, as far as I know. camera2 API can help, but it is fully supported on few recent devices only. – Alex Cohn Mar 30 '16 at 17:33
  • 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

9

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.

IshRoid
  • 3,696
  • 2
  • 26
  • 39