如何在一个文件中合并多个MP4视频文件 [英] How to Merge Multiple MP4 Videos files in single file

查看:1009
本文介绍了如何在一个文件中合并多个MP4视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Java将多个MP4视频文件合并为单个文件.谁能告诉我如何合并视频.您的帮助将不胜感激.

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.

推荐答案

由于您没有提到格式,因此很难给出建议,但是对于mp4来说,这似乎是一个不错的选择.甚至包括合并文件的示例.

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.

代码来自链接:

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

这篇关于如何在一个文件中合并多个MP4视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆