How to Merge Multiple MP4 Videos files in single file

醉酒当歌 提交于 2019-12-08 05:57:23

问题


I need to merge the multiple MP4 videos file to a single file using java. Can any one tell me how to merge videos. Your help would be appreciated.


回答1:


Since you do not mention format it is hard to give advice, but for mp4 this seems to be a good alternative. Even includes example of merging files.

Code taken from link:

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



来源:https://stackoverflow.com/questions/36979996/how-to-merge-multiple-mp4-videos-files-in-single-file

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