首先 导入关联 .jar文件
compile 'com.googlecode.mp4parser:isoparser:1.1.21'
也可以使用下载jar包
关联完成之后使用下面代码就可实现合并
public class MergerMp4 { public void mergeMP4(){ ListfileList = new ArrayList (); List moviesList = new LinkedList<>();
//添加需要合并的文件 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
//输出合并后的文件 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(); } }