Search code examples
androidmp4android-4.2-jelly-beanandroid-mediarecordermuxer

MP4 filewriter in android 4.1+


Starting from Android 4.1 (API level 16) MediaCodec APIs have been introduced. These APIs support Elementary stream Decoding & Encoding. Also MediaExtractor API will give elementary track details by analyzing Media streams.

My Question is, I setup a video encoder using MediaCodec API, which gives me encoded file in .h264 format. I want to write .h264 file into a .mp4 file for playing/storing/sharing purposes. I don't find any .MP4 file-writer API for android. Is there any way to achieve it?

Thanks, Satish.


Solution

  • As of Android 4.3 (API 18) you can use the MediaMuxer class to convert the raw H.264 stream to a .mp4 file (and even merge an audio stream in).

    See the EncodeAndMuxTest and CameraToMpegTest sources on this page for sample code.