androidmediamuxerandroid-mediacodec

Android mediacodec: Is it possible to encode audio and video at the same time using mediacodec and muxer?


There is some good documentation on this site called big flake about how to use media muxer and mediacodec to encode then decode video as mp4, or extract video then encode it again and more stuff.

But it doesnt seem that there is a way to encode audio with video at the same time, no documentation or code about this. It doesn't seem impossible.

Question

Do you know any stable way of doing it that will work on all devices greater than android 18?

Why no one implemented it, is it hard to implement?


Solution

  • You have to create 2 Mediacodec instances, one for video and one for audio and then use MediaMuxer to mux the video with audio after encoding, you can take a look at ExtractDecodeEditEncodeMuxTest.java and at this project to capture camera/mic and save to mp4 file using Mediamuxer and Mediacodec