我需要旋转一个视频来调整我的一些需求。我将解释下面列表中的细节。
我正在创建一个类似藤蔓的应用程序。我必须记录视频片段,然后将所有部分合并到一个文件中。我在使用mp4解析器库的Android应用程序上这样做,最后版本为1.0-RC-26,使用了他们网站上提供的示例:这里
如果所有的视频都有相同的方向,那么附加的视频示例工作得很好,但是我发现了一些从前面的摄像机记录视频的问题,所以快速的解决方案是将视频定向设置为270。这个解决方案的缺点是,在合并的视频中,带有此方向的段出现了错误的方向。
对此,我可能的解决方案是旋转视频,在不同的情况下应用我需要的内容,但我的代码没有一个工作示例。在互联网上搜索,我找到了像这里这样的解决方案。这段代码的问题在于它与上一个版本不兼容(它提供了一个编译错误)。我也试着去理解图书馆的逻辑,但是我没有结果。例如,我在Movie上使用了setMatrix指令,但是它根本不起作用。
public static void mergeVideo(int SegmentNumber) throws Exception {
Log.d("PM", "Merge process started");
Movie[] inMovies = new Movie[SegmentNumber] ;
//long[] Matrix = new long[SegmentNumber];
for (int i = 1 ; i <= SegmentNumber; i++){
File file = new File(getCompleteFilePath(i));
if (file.exists()){
FileInputStream fis = new FileInputStream(getCompleteFilePath(i));
//Set rotation I tried to experiment with this instruction but is not working
inMovies [i-1].setMatrix(Matrix.ROTATE_90);
inMovies [i-1] = MovieCreator.build(fis.getChannel());
Log.d("PM", "Video " + i + " merged" );
}
//fis.close();
}
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()])));
}
Container out = new DefaultMp4Builder().build(result);
//out.getMovieBox().getMovieHeaderBox().setMatrix(Matrix.ROTATE_180); //set orientation, default merged video have wrong orientation
// Create a media file name
//
String filename = getCompleteMergedVideoFilePath() ;
FileChannel fc = new RandomAccessFile(String.format(filename), "rw").getChannel();
out.writeContainer(fc);
fc.close();
//don't leave until the file is on his place
File file = new File (filename);
do {
if (! file.exists()){
Log.d("PM", "Result file not ready");
}
} while (! file.exists() );
//
Log.d("PM", "Merge process finished");
}有人用Mp4解析器的最后一个版本旋转视频了吗?英语不是我的母语,所以我对任何语法错误表示歉意。
发布于 2013-10-15 23:19:03
for (int i = 1; i <= SegmentNumber; i++) {
IsoFile isoFile = new IsoFile(getCompleteFilePath(i));
Movie m = new Movie();
List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(
TrackBox.class);
for (TrackBox trackBox : trackBoxes) {
trackBox.getTrackHeaderBox().setMatrix(Matrix.ROTATE_90);
m.addTrack(new Mp4TrackImpl(trackBox));
}
inMovies[i - 1] = m;
}这就是我旋转视频时所做的。
https://stackoverflow.com/questions/19190050
复制相似问题