0

我需要在我的 Android 项目中将视频旋转 90 度。经过一番谷歌搜索后,我停在了可以与 Android 集成的 mp4parser。视频存储在设备上,也将保存在那里(不确定是否使用不同的名称,但这并不重要)。这是我正在使用的代码(使用 isoviewer-1.0-RC-35 制作),但如果需要,我可以将库更改为 2.0 版:

try 
{
    String inputVideoName = "path_to_a_video";

    IsoFile out =  new IsoFile(inputVideoName);
    out.getMovieBox().getMovieHeaderBox().setMatrix(Matrix.ROTATE_90);

    File outputVideoName = new File("path_to_a_saved_processed_video");
    if (!outputVideoName.exists())
        outputVideoName.createNewFile();

    FileOutputStream fos = new FileOutputStream(outputVideoName);
    out.writeContainer(fos.getChannel());
    fos.close();
    out.close();
} 
catch (IOException e) {
    Log.e("test", "some exception", e);
}

代码编译、运行、保存视频,但使用原始旋转,因此没有对其进行任何更改。怎么了?

4

1 回答 1

0

这有帮助吗?你也不认为你应该使用 Isoparser 而不是 Isoviewer 吗?

package com.googlecode.mp4parser;

import com.googlecode.mp4parser.authoring.Movie;
import com.googlecode.mp4parser.authoring.builder.DefaultMp4Builder;
import com.googlecode.mp4parser.authoring.container.mp4.MovieCreator;
import com.googlecode.mp4parser.util.Matrix;

import java.io.FileOutputStream; 
import java.io.IOException;


public class Rotate {
public static void main(String[] args) throws IOException {

    String f1 = AppendExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/1365070268951.mp4";

    Movie inMovie = MovieCreator.build(f1);
    inMovie.setMatrix(Matrix.ROTATE_90);

    new DefaultMp4Builder().build(inMovie).writeContainer(new FileOutputStream("output.mp4").getChannel());
}
}
于 2015-04-16T06:54:10.303 回答