问题描述
我正在尝试将三个 mp4 视频合并(合并)到一个文件中。为此,我将 mp4parser 库用于 java。这是我的功能:
public static void appendMp4List(List<String> mp4PathList,String outPutPath) throws IOException {
List<Movie> mp4MovieList = new ArrayList<>();// Movie object collection [input]
for (String mp4Path : mp4PathList) {// Construct each file path into a Movie object
mp4MovieList.add(MovieCreator.build(mp4Path));
}
List<Track> audioTracks = new LinkedList<>();// Audio Channel Collection
List<Track> videoTracks = new LinkedList<>();// Video channel collection
for (Movie mp4Movie : mp4MovieList) {// Loop through the collection of Movie objects
for (Track inMovieTrack : mp4Movie.getTracks()) {
if ("soun".equals(inMovieTrack.getHandler())) {// Remove the audio channel from the Movie object
audioTracks.add(inMovieTrack);
}
if ("vide".equals(inMovieTrack.getHandler())) {// Remove the video channel from the Movie object
videoTracks.add(inMovieTrack);
}
}
}
Movie resultMovie = new Movie();// Result Movie object [output]
if (!audioTracks.isEmpty()) {// Append all audio channels together
resultMovie.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
}
if (!videoTracks.isEmpty()) {// Append all video channels together
resultMovie.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
}
Container outContainer = new DefaultMp4Builder().build(resultMovie);// Wrap the resulting Movie object into the container
FileChannel fileChannel = new RandomAccessFile(String.format(outPutPath),"rw").getChannel();
outContainer.writeContainer(fileChannel);// Write the contents of the container to disk
fileChannel.close();
System.out.println(getVideoDuration(outPutPath));
}
问题出在这行代码上:
mp4MovieList.add(MovieCreator.build(mp4Path));
所以 build 方法不会构建 mp4 视频的卡车和箱子。所以当在卡车上循环时:
for (Track inMovieTrack : mp4Movie.getTracks()) { ... }
getTracks()
返回空值。我将这些文件检查到快速播放器中,它们似乎没问题。
在这里,我还将这些文件上传到我的驱动器中以进行测试:
当文件超过 100MB 时,mp4parser 库似乎无法解析它。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)