4

I've succeeded recording video using the mediaRecorder class on Android.

However, what I need to do now is to make it record till I tell it to stop, but keep only max of X seconds recorded.

For example, if I've started recording at time=0 (seconds), and I've set it to record max of 10 seconds, if I stop the recording on time=20 (seconds), the recorded video will be of the 10..20 seconds period.

The only thing similar to what I've found is setMaxDuration, but that automatically stops after the specified time was set, so in my case it will record only the first 10 seconds.

halfer
  • 19,824
  • 17
  • 99
  • 186
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • @Tushar No. Sorry. It was a long time ago. – android developer Apr 08 '15 at 12:28
  • 2
    @Tushar I do not yet know if this is a working example, as I'm just starting to investigate it, but it sounds extremely promising when I ran a test on my phone from source. Check out ContinuousCaptureActivity from grafika, which uses a CircularEncoder for the video. I imagine you can rig up another circular encoder for audio stream as well. [grafika github](https://github.com/google/grafika/blob/master/src/com/android/grafika/ContinuousCaptureActivity.java) – jschlepp Feb 24 '16 at 17:36
  • @jschlepp Thanks for the link. I'll check it out. :) – Tushar Gogna Feb 26 '16 at 07:09
  • The app "snipback" from "hipoint" seems to do this. I don't know how they do this. – jrouquie Oct 07 '21 at 11:27

3 Answers3

3

FOR MEDIA RECORDER TO RECORD X SECOND U HAVE TO SIMPLY PUT THIS CODE IN YOR VIDEO RECORD CODE

Intent captureVideoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
captureVideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
captureVideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(captureVideoIntent, VIDEO_CAPTURED);
RINK
  • 620
  • 5
  • 15
  • 4
    You don't understand: I need to do it within the application, plus I need it to constantly record, and when I tell it to stop, I should give me only the last X seconds. – android developer Mar 15 '13 at 15:57
0

I'm not aware of any way to accomplish what you need using just the SDKs. You could have it record a video and then when you determine it cut the video down to the last 10 seconds.

I haven't used it, but this guy suggests his library in this answer

Community
  • 1
  • 1
David
  • 7,005
  • 2
  • 22
  • 29
  • the mp4parser library seems promising . i could use a 2 buffer files solution , and when i'm ready for stopping the recording , merge both files and then crop the merged file . are you sure there isn't another workaround for this ? maybe set the recording's outputStream to a buffer that i will be responsible to cut where needed? – android developer Dec 02 '12 at 20:23
0

The correct keyword for searching it is "circular buffer". You will see a couple of methods, which aren't trivial. Some use NDK solutions.

My idea it is: You know X seconds do you want to record. Than record to fileX_1, after that it ends the recording. Automatically start and record fileX_2 until ends. When it ends then record to fileX_3 AND delete fileX_2 to save space.

So the maximum storage and video length can be X * 2. The minimum can be X.

To use the circular recording I think it has to decode it to frames, store it, encode it , a lot of processing power is used, which result is batter drain and heating the device!

matheszabi
  • 594
  • 5
  • 16