我无法旋转mp4parser视频。我有一个包含要合并的视频路径的数组,数组中的所有视频都是垂直的,但合并后它会水平显示。我试过很多改变方向,但mvhd.setMatrix(Matrix.ROTATE_180);根本不工作。当我使用容器时它会在“movieCreator”中出错并且当我使用isofile时,它工作正常但方向保持水平。 请帮帮我。
public void onRunVideoClick() {
String newPath =Environment.getExternalStorageDirectory().getAbsolutePath();
Movie videoMovie;
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();
try {
for (int i = 0; i < NewVideoCaptureActivity.videoPath.size(); i++) {
File filevideo;
String videoFilePath;
videoFilePath = NewVideoCaptureActivity.videoPath.get(i);
filevideo = new File(videoFilePath);
if (filevideo.exists() == true) {
videoMovie = MovieCreator.build((DataSource) new FileInputStream(videoFilePath).getChannel());
Track TrackVideoStart = null;
for (Track t4 : videoMovie.getTracks()) {
if (t4.getHandler().equals("vide")) {
TrackVideoStart = t4;
break;
}
}
videoTracks.add(TrackVideoStart);
Track TrackVideoSound = null;
for (Track t4 : videoMovie.getTracks()) {
if (t4.getHandler().equals("soun")) {
TrackVideoSound = t4;
break;
}
}
audioTracks.add(TrackVideoSound);
AudioTime = getTrackTime(TrackVideoSound);
}
}
Movie result1 = new Movie();
result1.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
result1.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
Container out = new DefaultMp4Builder().build(result1);
MovieHeaderBox mvhd = (MovieHeaderBox) Path.getPath(out, "moov/mvhd");
mvhd.setMatrix(Matrix.ROTATE_180);
out.writeContainer(new FileOutputStream(newPath+ File.separator + "SampleVideos"+ File.separator + "output12.mp4").getChannel());
// IsoFile out = (IsoFile) new DefaultMp4Builder().build (result1);
//
//
// FileChannel fc = new RandomAccessFile(String.format(newPath+ File.separator + "SampleVideos"+ File.separator + "output12.mp4"), "rw").getChannel();
// fc.position(0);
// out.getBox(fc);
// fc.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}