5
votes

I'm trying to record a 10 second video for surveillance. That is quite straight forward using MediaRecorder in Android. All i have to do is call

mediaRecorder.setMaxDuration(10000);

However, i want to continuously overwrite the same 10 second video. Again this is a trivial task.

@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
    switch (what) {
    case MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED:
        stopRecording();
        startRecording();
        break;
    }
}

Stopping and Starting (reseting) the MediaRecorder takes approximately two seconds. If something important happened during those two seconds, i will not have it recorded.

So i followed several others having the same problem by using a LocalSocket, and passing it's descriptor to MediaRecorder

mediaRecorder.setOutputFile(sender.getFileDescriptor());

Then an AyncTask containing a LocalServerSocket and a receiver LocalSocket

public class VirtualServer extends AsyncTask<Void, Void, Void> {
    ...
    server = new LocalServerSocket(SOCKET_ADDRESS);
    while (true) {
        receiver = server.accept();
        ...
        int len = 0;
        byte[] data = new byte[1024];
        while ((len = input.read(data)) >= 0) {
        ...

See where this is going? Once that is solved, a new problem arises, also addressed several times on StackOverflow. The problem is that the file descriptor passed to MediaRecorder is not seek-able.

For me this is where my understanding stops. Unfortunately there is no clear description of the problem. If someone can describe the problem to me i can start looking for a solution. Some places mention that "moot" has to be repositioned, but then the discussion drifts to general mp4 encoding, and i get lost in all the details.

i hope my problem is clearly stated. i do not wish to stream video of any sort. Digging into code that packetizes into RTP and trying to extract the parts i really need has made me even more confused.

Links i already looked at:

Cheers.

I understand what your trying to accomplish here but can you go into more detail on your actual problem. The problem is that the file descriptor passed to MediaRecorder is not seek-able. Do you have a stack trace? - Jake Graham Arnold