如何在单个文件中合并多个MP4视频文件

时间:2016-05-02 10:13:32

标签: java mp4 video-editing

我需要使用java将多个MP4视频文件合并到一个文件中。任何人都可以告诉我如何合并视频。感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

由于你没有提到格式,很难给出建议,但对于mp4,这似乎是一个很好的选择。甚至包括合并文件的例子。

从链接获取的代码:

MovieCreator mc = new MovieCreator();
Movie video = mc.build(Channels.newChannel(AppendExample.class.getResourceAsStream("/count-video.mp4")));
Movie audio = mc.build(Channels.newChannel(AppendExample.class.getResourceAsStream("/count-english-audio.mp4")));

List videoTracks = video.getTracks();
video.setTracks(new LinkedList());

List audioTracks = audio.getTracks();

for(Track videoTrack:videoTracks){
    video.addTrack(new AppendTrack(videoTrack, videoTrack));
}

for(Track audioTrack:audioTracks){
    video.addTrack(new AppendTrack(audioTrack, audioTrack));
}

IsoFile out = new DefaultMp4Builder().build(video);
FileOutputStream fos = new FileOutputStream(new File(String.format("output.mp4")));
out.getBox(fos.getChannel());
fos.close();

https://code.google.com/archive/p/mp4parser/wikis/AppendTracks.wiki