问题
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.
回答1:
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.
回答2:
This response may be of use. It suggests using the isoparser library. It works pretty well if you have elementary streams saved to disk, but it doesn't work if you want to live stream from the MediaCodec output.
回答3:
Another way is to use FFmpeg (http://sourceforge.net/projects/ffmpeg4android/) for muxing h264-file to mp4 container.
来源:https://stackoverflow.com/questions/14493627/mp4-filewriter-in-android-4-1