Pro*_*ugo 7 video android video-recording mp4parser
我需要旋转视频来调整我的一些需求.我将在下面的列表中解释详细信息.
我正在创建一个像应用程序一样的Vine.我必须录制视频片段,然后将所有部分合并为一个文件.我正在使用mp4解析器库和最新版本1.0-RC-26使用其网站上提供的示例在Android应用程序上执行此操作:此处
如果所有视频具有相同的方向,附加视频示例工作正常但我发现从前置摄像头录制视频的一些问题,因此快速解决方案是将视频方向记录设置为270.此解决方案的不好部分是该段此方向在合并视频上显示错误的方向.
我可能的解决方案是旋转视频以应用我在不同情况下所需的内容,但我没有使用我的代码的工作示例.在互联网上搜索我在这里找到了这样的解决方案.此代码的问题是与上一版本不兼容(它给出了编译错误).我也试图理解库的逻辑,但我没有结果.例如,我尝试使用setMatrixMovie对象上的指令,但它根本不起作用.
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解析器旋转了视频吗?英语不是我的母语所以我道歉任何语法错误.
小智 4
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;
}
这就是我旋转视频所做的。
| 归档时间: | 
 | 
| 查看次数: | 3534 次 | 
| 最近记录: |