使用mp4parser将h264多路复用到mp4文件需要很长时间



我正在使用mp4parser将h264文件和aac文件复用到mp4文件中。代码如下。

    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();

但当我调试它时,这一步大约需要4分钟:

    DataSource videoFile = new FileDataSourceImpl(h264Path);

我的示例h264视频文件的持续时间约为20秒,大小约为3MB(比特率约为178KB)。它是由MediaCodec生成的。这在生产环境中是不可接受的。我的代码有错误吗?还是mp4parser的真正效率?非常感谢。

尝试谷歌的ExoPlayer库,尽管我认为MP4提取仅在dev分支上可用,请参阅此处的演示代码。

H264文件正确的路径,它就会调试。

最新更新