MP4 filewriter in android 4.1+

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 16:13:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!