我需要在我的Android项目中将视频旋转90度。我在谷歌上搜索了一下,找到了可以与安卓系统集成的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);
}代码编译、运行、保存视频,但使用原始旋转,因此不会对其进行任何更改。怎么了?
发布于 2015-04-16 14:54:10
这有帮助吗?另外,你不认为你应该使用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());
}
}https://stackoverflow.com/questions/22302907
复制相似问题