Q:

Split android video to multiple files while recording

I have a requirement where I have to record video and save video in to chunk of files. How can I split video to multiple file while recording with out loosing video frame

A:

It is possible if you use the Camera2 API, video and audio codecs, and the MediaMuxer. Basically, the codecs send buffers of data to a MediaMuxer which creates and writes to an .mp4 file. At any point you can start writing the buffers to a different MediaMuxer thus starting a new file.  The previous MediaMuxer can then close and save its file.  There is a lot of documentation to read and some difficulties. For example, a .mp4 file must start with a key frame. It is possible to request a key frame from the codec, but it won't happen right away, so you must wait for the key frame before starting a new file.  You of course must keep track of how must data you have written to files.  If your files have some kind of size limit, you must request a key frame before you reach that limit to allow room for frames that will arrive before the key frame appears.  And it goes on,  but depending on your app requirements, you can get it to work pretty good.

