Search code examples
androidaudiovideorecordingmediamuxer

Android MediaMuxer for InputSurface and Audio


I am really hoping that somebody can point me to a code somewhere that demonstrates how to use MediaMuxer to record surface view and audio and output an mp4 file video.

Basically what I want to do is to record what's happening on my surface view but also combine it with whatever audio is being heard. (From the mic)

I have a hard time believing that no one has a complete sample code that demonstrate doing this. This one comes close: https://github.com/google/grafika

But it only does video. No audio part. Much appreciated.


Solution

  • Never mind. I found it. Full code here: https://github.com/saki4510t/AudioVideoRecordingSample

    This samples records surface and audio. You would of course need add appropriate permissions to record audio, and use Camera etc...

    The sample uses CameraView to write to MediaVideoRecorder inputsurface.So, it writes twice. First to the preview screen (what the user sees), then to the recording input surface. If you have your own rendering of course, you can disable the camera part and write your own GL commands on the MediaVideoRecorder surface, and then call frameAvailableSoon on the MediaVideoRecorder.