Search code examples
androidvideosplitvideo-capturevideo-recording

Android: Split video during capture


I am looking for solution to split video during capture to 5 minutes parts. For example, during one hour trip (video capture) I would like to divide this video (during trip) to smaller videos 12 * 5 min = 1h. Not after stop capture, but in the meantime.

I would like to do something like video recorder. Could you tell me what I need to use to do this issue?


Solution

  • I found the solution, you need to use:

    MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED
    

    Here is full description in Android documentation: MediaRecorder | Android

    Below is part of my code which I am using & it is working :)

    if(what==MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED)
        recorder.stop();
        recorder.reset();
    
        // Flag to recording (in my code I am using to stop/start capturing)
        recording = false;
        recording = true;
    
        initRecorder();
        prepareRecorder();
    
        recorder.start();
    
        Toast.makeText(MainActivity.this, "Again",Toast.LENGTH_LONG).show();
        // 5 000 ms - 5 s
        // 300 000 ms - 5 min
    }
    

    To set Max Duration you need to declare:

    recorder.setMaxDuration(300000);
    

    in initRecorder() function.
    I recommend you also read this: SetMaxDuration

    I hope that what I wrote will help you.