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.
Asked
Active
Viewed 6,859 times
1
-
Which software or library are you planning to use? This is not the right place to ask for recommendations. – Peter Lawrey May 02 '16 at 10:18
-
Hi Peter, I have no idea that which library should be use to merge the videos.But this task should be done using java. – Mohd Abad May 02 '16 at 10:50
1 Answers
3
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

Viktor Mellgren
- 4,318
- 3
- 42
- 75
-
Thanks Vixen for help.yes i am talking about mp4, can you send the example code to merging the several MP4 videos . i didnt find the example code in the given link. Any help would be appreciated. – Mohd Abad May 02 '16 at 10:44
-
-
-
@ViktorMellgren ok i have no idea of mp4parser can you give me example – Bipin Bharti Jun 05 '17 at 13:22
-
-
This code doesn't stitch movies, but adds them as tracks on top of each other. The total movie length wil be the same... – user10053673 Apr 15 '22 at 12:48