Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
684 views
in Technique[技术] by (71.8m points)

java - How to Merge Multiple MP4 Videos files in single file

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...