我尝试通过mp4parser lib连接两个mp4视频。但是我收到了错误。这是我的代码
public void appendTwoVideo(String mp4_1,String mp4_2) throws IOException {
Movie[] inMovies = new Movie[]{MovieCreator.build(mp4_1),
MovieCreator.build(mp4_2)};
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : inMovies) {
for (Track t : m.getTracks()) {
if (t.getHandler().equals("soun")) {
audioTracks.add(t);
}
if (t.getHandler().equals("vide")) {
videoTracks.add(t);
}
}
}
Movie result = new Movie();
if (audioTracks.size() > 0) {
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
}
if (videoTracks.size() > 0) {
result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
}
IsoFile out = new DefaultMp4Builder().build(result);
FileChannel fc = new RandomAccessFile(String.format("output.mp4"), "rw").getChannel();
fc.position(0);
out.getBox(fc);
fc.close();
}
排队
IsoFile out = new DefaultMp4Builder().build(result);
我收到错误
错误:(296,53)错误:不兼容的类型:容器无法转换为IsoFile。
任何人都可以帮我解决错误或者如何以其他方式连接两个视频?
答案 0 :(得分:0)
我找到了解决方案
只是不要使用IsoFile。使用Container作为类型,使用
将容器写入磁盘 WritableByteChannel wbc = new FileOutputStream(
new File(outputDirectory, filename)).getChannel();
try {
container.writeContainer(wbc);
} finally {
wbc.close();
}
https://groups.google.com/forum/#!msg/mp4parser-discussion/t3jRVeRsGFs/RTT3bdDN-qQJ