First, import the associated. jar file
Compile ' com.googlecode.mp4parser:isoparser:1.1.21 '
You can also use the download jar package
After the association is complete, use the following code to implement the merge
public class MergerMp4 {
public void MergeMP4 () {
list<string> fileList = new arraylist<string> ();
list<com.googlecode.mp4parser.authoring.movie> movieslist = new linkedlist<> ();
Add files that need to be merged Filelist.add ("/sdcard/video/20161122135659.mp4");
Filelist.add ("/sdcard/video/20161122135810.mp4");
Filelist.add ("/sdcard/video/20161122144321.mp4");
Filelist.add ("/sdcard/video/20161122144357.mp4");
Filelist.add ("/sdcard/video/20161122144447.mp4");
try{for (String file:filelist) {movieslist.add (moviecreator.build (file));
}} catch (IOException e) {e.printstacktrace ();
} list<track> videotracks = new linkedlist<track> ();
list<track> audiotracks = new linkedlist<track> ();
for (Com.googlecode.mp4parser.authoring.Movie m:movieslist) {to (track t:m.gettracks ())
{if (T.gethandler (). Equals ("Soun")) {Audiotracks.add (t);
} if (T.gethandler (). Equals ("vide")) {Videotracks.add (t);
}}} Movie result = new movie (); try {if (audiotracks.size () > 0) {result.addtrack (new Appendtrack (AUD
Iotracks.toarray (New Track[audiotracks.size ()))); } if (Videotracks.size () > 0) {result.addtrack (new Appendtrack (Videotracks.toa
Rray (New Track[videotracks.size ()))); }} catch (IOException e) {//TODO auto-generated catch block E.printstac
Ktrace ();
} Container out = new Defaultmp4builder (). Build (result); try {
Output the merged file
filechannel fc = new Randomaccessfile ("/sdcard/video/small/output2.mp4", "RW"). Getchannel ();
Out.writecontainer (FC);
Fc.close ();
}
catch (Exception e)
{
//TODO auto-generated catch block
e.printstacktrace ();
}
Movieslist.clear ();
Filelist.clear ();
}
}