我正在开发一个应用程序,使用mp4parser合并n个视频。要合并的视频是在前置摄像头和后置摄像头中拍摄的。如果我将这些视频合并为单个视频,它会合并所有视频,但通过前置摄像头拍摄的替代视频将合并为倒置视频。 我能做什么。 请任何人帮助我。
这是我合并视频的代码:
try {
String f1,f2,f3;
f1 = Environment.getExternalStorageDirectory() + "/DCIM/testvideo1.mp4";// video took via back camera
f2 = Environment.getExternalStorageDirectory() + "/DCIM/testvideo2.mp4";// video took via front camera
f3 = Environment.getExternalStorageDirectory() + "/DCIM/testvideo3.mp4";// video took via front camera
Movie[] inMovies = new Movie[] {
MovieCreator.build(f1),
MovieCreator.build(f2),
MovieCreator.build(f3)
};
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()])));
}
BasicContainer out = (BasicContainer) new DefaultMp4Builder().build(result);
WritableByteChannel fc = new RandomAccessFile(
String.format(Environment.getExternalStorageDirectory()+ "/DCIM/CombinedVideo.mp4"), "rw").getChannel();
out.writeContainer(fc);
fc.close();
} catch (Exception e) {
Log.d("Rvg", "exeption" + e);
Toast.makeText(getApplicationContext(), "" + e, Toast.LENGTH_LONG)
.show();
}