2 qq 31280613 qq_31280613 于 2016.03.17 22:34 提问

Android 用Mp4Parser 合并视频后如何播放?

在Mp4Parser 的demo 中,有一个AppendExample.java 示范,写出了如何合并视频。
但在如下面源码所示,如何在合并后获取到新生成的合并视频文件呢?

public class AppendExample {
public static void main(String[] args) throws IOException {

    String[] videoUris = new String[]{

            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20150930_161515.mp4",
            "c:\\content\\20150930_161525.mp4",
            "c:\\content\\20150930_161529.mp4",
            "c:\\content\\20150930_161534.mp4",
            "c:\\content\\20150930_161543.mp4",
            "c:\\content\\20151001_135436.mp4",
            "c:\\content\\20151001_135446.mp4",
            "c:\\content\\20151001_135540.mp4"

    };

    List<Movie> inMovies = new ArrayList<Movie>();
    for (String videoUri : videoUris) {
        inMovies.add(MovieCreator.build(videoUri));
    }

    List<Track> videoTracks = new LinkedList<Track>();
    List<Track> audioTracks = new LinkedList<Track>();

    for (Movie m : inMovies) {
        for (Track t : m.getTracks()) {
            if (t.getHandler().equals("soun")) {
                audioTracks.add(t);
            }
            if (t.getHandler().equals("vide")) {
                videoTracks.add(t);
            }
        }
    }

    Movie result = new Movie();

    if (!audioTracks.isEmpty()) {
        result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
    }
    if (!videoTracks.isEmpty()) {
        result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
    }

    Container out = new DefaultMp4Builder().build(result);

    FileChannel fc = new RandomAccessFile(String.format("output.mp4"), "rw").getChannel();
    out.writeContainer(fc);
    fc.close();


}

}


git原址:https://github.com/sannies/mp4parser

非常感谢

1个回答

devmiao
devmiao   Ds   Rxr 2016.03.17 23:51
qq_31280613
qq_31280613 但是这里给出的也是Mp4Paresr 中自带的AppendExample.java 源码
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!