Android encoder muxer: raw h264 to mp4 container

∥☆過路亽.° 提交于 2019-11-28 20:57:38
xy uber.com

I gave up on Jcodec. It exposes too many codec internal stuff, and there is no documentation on usage at all. Mp4Parser did the job for me, and it's simple. Here is the code I mux raw h264 video into mp4 container:

    String h264Path = "path to my h264 file, generated by Android MediaCodec";

    DataSource videoFile = new FileDataSourceImpl(h264Path);

    H264TrackImpl h264Track = new H264TrackImpl(videoFile, "eng", 5, 1); // 5fps. you can play with timescale and timetick to get non integer fps, 23.967 is 24000/1001

    Movie movie = new Movie();

    movie.addTrack(h264Track);

    Container out = new DefaultMp4Builder().build(movie);
    FileOutputStream fos = new FileOutputStream(new File("path to my generated file.mp4"));
    out.writeContainer(fos.getChannel());

    fos.close();

Code examples were found here. Loop is closed! Now my video encoder implementation works from Android 4.1 and up, without the need of FFMpeg

BTW: Android stock "Gallery" app uses Mp4Parser, listed in its open source licenses.

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