MP4 filewriter in android 4.1+

2019-08-02 18:43发布

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.

3条回答
Fickle 薄情
2楼-- · 2019-08-02 19:37

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楼-- · 2019-08-02 19:38

Another way is to use FFmpeg (http://sourceforge.net/projects/ffmpeg4android/) for muxing h264-file to mp4 container.

查看更多
The star\"
4楼-- · 2019-08-02 19:44

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.

查看更多
登录 后发表回答